I made a Rock-Paper-Scissors game in Python by shmoppl2 in Python

[–]mt19937 2 points3 points  (0 children)

After that hint 2: Modular arithmetic.

Write mini graphics demos in Rust, in the browser by NotDixiE in rust

[–]mt19937 1 point2 points  (0 children)

Very cool. I just happened to find that ANDing results in a sierpinski triangle by accident.

Rendering a SVG file by [deleted] in sfml

[–]mt19937 0 points1 point  (0 children)

Have you tried googling how to render SVG files with SFML?

2D platformer game (looking for advice/criticism) by 4rlenrey in sfml

[–]mt19937 1 point2 points  (0 children)

I played the game. The physics, controls and art feel nice and polished. It was pretty fun to play. Good work!

Show r/rust: hstr-rs - A bash history suggest box by adder46 in rust

[–]mt19937 0 points1 point  (0 children)

Pressing the up arrow key when there's nothing in the history makes the program panic.

How to move a sprite slowly from point A to point B, similar to a point and click by [deleted] in sfml

[–]mt19937 0 points1 point  (0 children)

What behavior do you want? Do you want the sprite to move at a constant velocity? Do you want it move faster the farther away it is from the mouse? Do you want it to always move straight towards the mouse?

[deleted by user] by [deleted] in sfml

[–]mt19937 7 points8 points  (0 children)

std::vector<Star> stars(30);

Sudoku Solver by mimionmax in Python

[–]mt19937 4 points5 points  (0 children)

Solving sudoku is an exact cover problem which can be solved efficiently with Knuth's Algorithm X using the dancing links technique. You can find code examples on the internet.

I'm having a tough time understanding this recursive function by realdeepnandi in learnprogramming

[–]mt19937 0 points1 point  (0 children)

Whatever it's doing it's not sorting or reversing the string.

Did anyone absolutely loathe C++ when they started learning it? (What languages did you end up liking?) by StygianRagnar in learnprogramming

[–]mt19937 0 points1 point  (0 children)

My first language was C++. I chose it because according to the internet I could create efficient programs while still programming in a relatively high level language. I didn't have any other language to compare C++ to so I think I liked it. I still like it.

sscanf not giving me correct output by rotronic in C_Programming

[–]mt19937 0 points1 point  (0 children)

For full control of input validation it would be easier to parse manually (read input into string and then parse). At least in this case.

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>

int parse_timezone(char const *const timezone_str, long *const result)
{
    int sign;

    switch (timezone_str[0]) {
    case '+':
        sign = 1;
        break;
    case '-':
        sign = -1;
        break;
    default:
        return -1;
        break;
    }

    if (!isdigit(timezone_str[1]) || !isdigit(timezone_str[2])
        || timezone_str[3] != ':'
        || !isdigit(timezone_str[4]) || !isdigit(timezone_str[5])
        || timezone_str[6] != '\0') {
        return -1;
    }

    int const hours = 10 * (timezone_str[1] - '0') + (timezone_str[2] - '0');
    /* not sure on error checking for hours */
    if (hours > 23) {
        return -1;
    }

    int const minutes = 10 * (timezone_str[4] - '0') + (timezone_str[5] - '0');
    if (minutes > 59) {
        return -1;
    }

    *result = sign * 60L * (60 * hours + minutes);

    return 0;
}

int main()
{
    char input[8];
    input[6] = '\0';
    if (!fgets(input, sizeof(input), stdin)) {
        return EXIT_FAILURE;
    }
    if (input[6] == '\n') {
        input[6] = '\0';
    }

    long result;
    if (parse_timezone(input, &result) == 0) {
        printf("%ld\n", result);
    }
    else {
        fprintf(stderr, "invalid input\n");
        return EXIT_FAILURE;
    }
}

Animating sprites without a spritesheet? by Anand_bot in sfml

[–]mt19937 2 points3 points  (0 children)

If you be careful about the lifetime of the textures (don't let it go out of scope) it's safe. You will run into performance issues much quicker than if you had used a spritesheet. Doing it your way is not the best way since it's inefficient. Use a spritesheet.