]> git.draconx.ca Git - rrace.git/blobdiff - src/game.c
Add timer display.
[rrace.git] / src / game.c
index bdd8f2b3ac103c6e2974fe138c1b23f342a81673..2ad3a7ed083b885cfddbc3c372b5865bbc72f67b 100644 (file)
@@ -170,14 +170,14 @@ void game_reset(struct board *board)
        }
 }
 
-int game_do_move(struct board *board, int x, int y)
+uint_fast32_t game_do_move(struct board *board, int x, int y)
 {
        int bx = board->x, by = board->y;
-       uint_least32_t mask, val[4];
+       uint_least32_t ret = 0, mask, val[4];
        int i, shl, shr;
 
        if ((bx != x) == (by != y))
-               return -1;
+               return 0;
 
        if (bx == x) {
                mask = board_mask_v(x, by, y);
@@ -192,11 +192,13 @@ int game_do_move(struct board *board, int x, int y)
        for (i = 0; i < 4; i++) {
                board->game[i] ^= (val[i] = board->game[i] & mask);
                board->game[i] |= val[i] << shl >> shr;
+               ret |= board->game[i] ^ val[i];
        }
 
        board->x = x;
        board->y = y;
-       return 0;
+
+       return mask & ret;
 }
 
 uint_fast32_t game_check_goal(struct board *board)
@@ -216,14 +218,14 @@ void game_begin(struct board *board)
        board->time_start = gethrxtime();
 }
 
-static int_fast32_t elapsed(struct board *board)
+int_fast32_t game_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_fast32_t t = game_elapsed(board);
        int i;
 
        for (i = 0; i < 4; i++) {