/*
* 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
#include <config.h>
#include <limits.h>
#include <string.h>
+#include <unistd.h>
#include <time.h>
-#include <gethrxtime.h>
#include "game.h"
#define B64(x) ((x) & 0xffffffffffffffff)
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);
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);