X-Git-Url: http://git.draconx.ca/gitweb/rrace.git/blobdiff_plain/b4b5688edd332e17591ca7bc1cdd64c296abe1c5..5ba271c9a2d679094dc69dd4e9eff33122022ea0:/src/game.c?ds=sidebyside diff --git a/src/game.c b/src/game.c index eefafe5..ab70478 100644 --- a/src/game.c +++ b/src/game.c @@ -1,6 +1,6 @@ /* * Slide puzzle core game logic - * Copyright © 2022 Nick Bowler + * Copyright © 2022-2023 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,8 +23,8 @@ #include #include #include +#include #include -#include #include "game.h" #define B64(x) ((x) & 0xffffffffffffffff) @@ -133,8 +133,19 @@ void game_reset(struct board *board) if (!rng_is_seeded()) { unsigned long long seed; - seed = time(NULL); - seed += gethrxtime(); + /* + * Try to get a reasonable initial seed. + * + * Reasonable in this context means: + * + * - roughly even distribution of 1/0 bits, and + * - unlikely to generate the same seed twice in succession. + */ + game_begin(board); + + seed = time(NULL); + seed += board->time_start; + seed += (unsigned long long)getpid() << 16; seed += seed << 32; game_reseed(seed); @@ -241,16 +252,6 @@ uint_fast32_t game_check_goal(struct board *board) return mask & GOAL_MASK; } -void game_begin(struct board *board) -{ - board->time_start = gethrxtime(); -} - -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 = game_elapsed(board);