X-Git-Url: http://git.draconx.ca/gitweb/rrace.git/blobdiff_plain/a13b072946d80c2da325e90cb73d96a25485a80a..23aee3322744aa3c65de28c3ebe1509e291b8702:/src/game.c diff --git a/src/game.c b/src/game.c index bdb18a1..bdd8f2b 100644 --- a/src/game.c +++ b/src/game.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "game.h" #define B64(x) ((x) & 0xffffffffffffffff) @@ -123,8 +124,15 @@ void game_reset(struct board *board) unsigned char tiles[25]; unsigned i; - if (!rng_is_seeded()) - game_reseed(time(NULL)); + if (!rng_is_seeded()) { + unsigned long long seed; + + seed = time(NULL); + seed += gethrxtime(); + seed += seed << 32; + + game_reseed(seed); + } for (i = 0; i < 24; i++) { tiles[i] = (i%6) + 1; @@ -191,19 +199,31 @@ int game_do_move(struct board *board, int x, int y) return 0; } -#define GOAL_MASK 0x739c0 - -int game_check_goal(struct board *board) +uint_fast32_t game_check_goal(struct board *board) { - int i, ret = 1; + uint_least32_t *game = board->game; + uint_least16_t *goal = board->goal; + uint_least32_t mask = 0; + int i; for (i = 0; i < 3; i++) - ret &= ((board->game[i] & GOAL_MASK) >> 6) == board->goal[i]; - return ret; + mask |= goal[i] ^ (game[i] >> GOAL_SHIFT); + return (mask << GOAL_SHIFT) & GOAL_MASK; } -void game_finish(struct board *board) +void game_begin(struct board *board) { + board->time_start = gethrxtime(); +} + +static int_fast32_t elapsed(struct board *board) +{ + return (gethrxtime() - board->time_start) / 1000000; +} + +int_fast32_t game_finish(struct board *board) +{ + int_fast32_t t = elapsed(board); int i; for (i = 0; i < 4; i++) { @@ -215,4 +235,6 @@ void game_finish(struct board *board) * disable the game since there will be no valid moves. */ board->x = board->y = -1; + + return t; }