66 unsigned long long moves;
79 if (n_player > n_opponent) stats.
n_wins = 1;
80 else if (n_player == n_opponent) stats.
n_draws = 1;
110 unsigned long long t, n;
114 puts(
"\n ply moves passes wins draws losses mobility time speed");
115 puts(
"------------------------------------------------------------------------------------------------------------------");
117 for (i = 1; i <= depth; ++i) {
122 printf(
" %2d, %15llu, %12llu, %12llu, %12llu, %12llu, ", i, stats.
n_moves + stats.
n_passes, stats.
n_passes, stats.
n_wins, stats.
n_draws, stats.
n_losses);
129 printf(
"Total %12llu\n", n);
130 puts(
"------------------------------------------------------------------------------------------------------------------");
144 unsigned long long moves;
163 for (k = depth; n[k]; ++k) n[k] *= i;
180 unsigned long long t;
181 double x[128], m[128], s[128], em[128], es[128], en[128];
187 M = S = EM = ES = 0.0;
188 for (i = 0; i < 128; ++i) m[i] = s[i] = 0.0;
189 for (i = 0; i < 128; ++i) em[i] = es[i] = en[i] = 0.0;
192 for (j = 1; j <= n; ++j) {
193 for (i = 0; i < 128; ++i) x[i] = 0.0;
195 for (i = 1; x[i]; ++i) {
196 m[i] += x[i]; s[i] += x[i] * x[i];
197 M += x[i]; S += x[i] * x[i];
200 em[i] += x[i - 1]; es[i] += x[i - 1] * x[i - 1];
201 EM += x[i - 1]; ES += x[i - 1] * x[i - 1];
207 for (i = 1; m[i] || en[i]; ++i) {
209 s[i] = sqrt((s[i] / n - m[i] * m[i])/n);
210 printf(
"%2d: %e +/- %e; ", i, m[i], s[i]);
214 es[i] = sqrt((es[i] / n - em[i] * em[i])/n);
215 printf(
"%e +/- %e;", em[i], es[i]);
220 S = sqrt((S / n - M * M)/n);
222 ES = sqrt((ES / n - EM * EM)/n);
223 printf(
"Total %e +/- %e: %e +/- %e en", M, S, EM, ES);
239static void test_mobility(
const Board *board,
const int ply,
Random *r,
int *move,
int *max_mobility,
int *max_empties,
const unsigned long long n)
241 unsigned long long moves;
247 if (e > *max_mobility) {
251 if (i > *max_mobility || (i == *max_mobility && e > *max_empties)) {
254 printf(
"\n after %llu trials:\n\n", n);
256 for (k = 1; k < ply; ++k) {
262 moves &= 0x007e7e7e7e7e7e00ULL;
269 test_mobility(next, ply + 1, r, move, max_mobility, max_empties, n);
278 test_mobility(next, ply + 1, r, move, max_mobility, max_empties, n);
294 const long long t_max = t * 1000 +
cpu_clock();
296 unsigned long long n = 0;
297 const int bucket = 10000;
306 test_mobility(board, 1, &r, x, &max_mobility, &max_empties, ++n);
342 hash->
size = (1 << bitsize) + 3;
343 hash->
mask = (1 << bitsize) - 1;
345 if (hash->
array == NULL)
fatal_error(
"Cannot allocate qperft hashtable.\n");
406 for (i = j; i < j + 4; ++i) {
431 unsigned long long moves;
444 if (n_player > n_opponent) stats.
n_wins = 1;
445 else if (n_player == n_opponent) stats.
n_draws = 1;
478 unsigned long long moves;
491 if (n_player > n_opponent) stats.
n_wins = 1;
492 else if (n_player == n_opponent) stats.
n_draws = 1;
527 unsigned long long n;
530 puts(
"\n ply moves passes wins draws losses mobility time speed");
531 puts(
"------------------------------------------------------------------------------------------------------------------");
533 for (i = 1; i <= depth; ++i) {
540 printf(
" %2d, %15llu, %12llu, %12llu, %12llu, %12llu, ", i, stats.
n_moves + stats.
n_passes, stats.
n_passes, stats.
n_wins, stats.
n_draws, stats.
n_losses);
545 printf(
" (h_tries = %lld, h_hits = %lld)\n", hash.
n_tries, hash.
n_hits);
549 printf(
"Total %12llu\n", n);
550 puts(
"------------------------------------------------------------------------------------------------------------------");
567 for (x =
A1; x <=
H8; ++x) {
568 if (x % 5 == 0) n = 0;
570 if (x % 5 == 4) c->
x[i++] = n;
592 array->
n = array->
size = 0;
613 for (i = 0; i < array->
n; ++i) {
614 if (memcmp(array->
item + i, b, 13) == 0)
return false;
617 if (array->
size < array->
n + 1) {
619 if (array->
item == NULL)
fatal_error(
"Cannot re-allocate board array.\n");
621 array->
item[array->
n++] = *b;
643 hash->
size = (1 << bitsize) + 3;
644 hash->
mask = (1 << bitsize) - 1;
667 unsigned long long h;
672 i = (h & hash->
mask);
685 unsigned long long h;
690 i = (h & hash->
mask);
713 hash->
size = (1 << bitsize);
742 unsigned long long h;
759 unsigned long long nodes = 0;
760 unsigned long long moves;
792 unsigned long long nodes = 0;
793 unsigned long long moves;
825 unsigned long long n, c;
832 puts(
"\n discs nodes total time speed");
833 puts(
"----------------------------------------------------------");
835 for (i = 0; i <= depth; ++i) {
842 printf(
" %2d, %12llu, %12llu, ", i + 4, n, c);
848 puts(
"----------------------------------------------------------");
860 unsigned long long sym, unique;
864 for (i = 1; i < 8; ++i) {
869 if (unique > sym) unique = sym;
883 unsigned long long h;
884 const unsigned char *p = (
const unsigned char*)&shape;
915 array->
n = array->
size = 0;
936 for (i = 0; i < array->
n; ++i) {
937 if (array->
item[i] == shape)
return false;
940 if (array->
size == array->
n) {
941 array->
item = (
unsigned long long*) realloc(array->
item, (array->
size += 1) * sizeof (
unsigned long long));
942 if (array->
item == NULL)
fatal_error(
"Cannot re-allocate board array.\n");
944 array->
item[array->
n++] = shape;
968 hash->
size = (1 << bitsize);
994 unsigned long long u;
1009 unsigned long long nodes = 0;
1010 unsigned long long moves;
1021 nodes +=
count_shape(hash, cache, next, depth - 1);
1044 unsigned long long nodes = 0;
1045 unsigned long long moves;
1080 unsigned long long n, c;
1087 puts(
"\n discs nodes total time speed");
1088 puts(
"----------------------------------------------------------");
1090 for (i = 0; i <= depth; ++i) {
1095 else c += (n =
count_shape(&hash, &cache, board, i));
1097 printf(
" %2d, %12llu, %12llu, ", i + 4, n, c);
1103 puts(
"----------------------------------------------------------");
1116 const unsigned long long mask = target->
opponent | target->
player;
1117 unsigned long long moves;
DLL_API int bit_count(unsigned long long b)
Count the number of bits set to one in an unsigned long long.
Definition bit.c:72
unsigned long long transpose(unsigned long long b)
Transpose the unsigned long long (symetry % A1-H8 diagonal).
Definition bit.c:345
unsigned long long horizontal_mirror(unsigned long long b)
Mirror the unsigned long long (exchange the line 1 - 8, 2 - 7, 3 - 6 & 4 - 5).
Definition bit.c:377
unsigned long long vertical_mirror(unsigned long long b)
Mirror the unsigned long long (exchange the lines A - H, B - G, C - F & D - E.).
Definition bit.c:364
#define foreach_bit(i, b)
Definition bit.h:39
unsigned long long board_get_hash_code(const Board *board)
Compute a hash code.
Definition board.c:1134
void board_print(const Board *board, const int player, FILE *f)
Print out the board.
Definition board.c:1230
int board_count_empties(const Board *board)
Check if the game is over.
Definition board.c:1216
unsigned long long get_moves_6x6(const unsigned long long P, const unsigned long long O)
Get legal moves on a 6x6 board.
Definition board.c:779
int board_compare(const Board *b1, const Board *b2)
Compare two board.
Definition board.c:319
int board_unique(const Board *board, Board *unique)
unique board
Definition board.c:379
int board_get_square_color(const Board *board, const int x)
Get square color.
Definition board.c:1168
int get_mobility(const unsigned long long P, const unsigned long long O)
Count legal moves.
Definition board.c:833
bool can_move_6x6(const unsigned long long P, const unsigned long long O)
Check if a player can move.
Definition board.c:814
bool board_equal(const Board *b1, const Board *b2)
Compare two board for equality.
Definition board.c:335
DLL_API unsigned long long get_moves(const unsigned long long P, const unsigned long long O)
Get legal moves.
Definition board.c:621
DLL_API bool can_move(const unsigned long long P, const unsigned long long O)
Check if a player can move.
Definition board.c:797
unsigned long long board_next(const Board *board, const int x, Board *next)
Compute a board resulting of a move played on a previous board.
Definition board.c:517
@ PASS
Definition const.h:37
@ A1
Definition const.h:29
@ H8
Definition const.h:36
@ BLACK
Definition const.h:42
unsigned long long hash_rank[16][256]
Definition hash-lock-free.c:41
void line_push(Line *line, const int x)
Add a move to the sequence.
Definition move.c:561
void move_print(const int x, const int player, FILE *f)
Print out a move.
Definition move.c:110
void line_pop(Line *line)
Remove the last move from a sequence.
Definition move.c:578
Options options
Definition options.c:22
static void boardcache_delete(BoardCache *hash)
Free the hash table.
Definition perft.c:654
static void gamehash_store(GameHashTable *hash, const Board *b, const int depth, const GameStatistics *stats)
Store a game position.
Definition perft.c:368
static unsigned long long count_position(PositionHash *hash, BoardCache *cache, const Board *board, const int depth)
Recursively count positions.
Definition perft.c:757
void quick_count_games(const Board *board, const int depth, const int size)
Count games.
Definition perft.c:521
void game_statistics_cumulate(GameStatistics *global, const GameStatistics *local)
Accumulate statistics: add local data to global ones.
Definition perft.c:44
unsigned long long shape_unique(unsigned long long shape)
unique shape.
Definition perft.c:858
void estimate_games(const Board *board, const long long n)
Move estimate games.
Definition perft.c:177
static void estimate_game(const Board *board, const int depth, Random *r, double *n)
Estimate move counts from a single game.
Definition perft.c:142
const GameStatistics GAME_STATISTICS_INIT
Definition perft.c:37
void positionhash_delete(PositionHash *hash)
Free the hash table.
Definition perft.c:724
static void compact_board(const Board *b, CBoard *c)
Definition perft.c:563
bool seek_position(const Board *target, const Board *board, Line *line)
seek a game that reach to a position
Definition perft.c:1115
static bool boardcache_undone(BoardCache *hash, const Board *b)
Append a shape to the hash table.
Definition perft.c:664
static unsigned long long count_shape_6x6(ShapeHash *hash, BoardCache *cache, const Board *board, const int depth)
Recursively count shapes.
Definition perft.c:1042
static void shapehash_delete(ShapeHash *hash)
Free the hash table.
Definition perft.c:979
static void quick_count_game_6x6(GameHashTable *hash, const Board *board, const int depth, GameStatistics *global_stats)
Count games recursively.
Definition perft.c:428
static void quick_count_game(GameHashTable *hash, const Board *board, const int depth, GameStatistics *global_stats)
Count games recursively.
Definition perft.c:475
static void boardcache_init(BoardCache *hash, int bitsize)
Initialisation of the hash table.
Definition perft.c:639
void seek_highest_mobility(const Board *board, const unsigned long long t)
Move estimate games.
Definition perft.c:290
static unsigned long long count_position_6x6(PositionHash *hash, BoardCache *cache, const Board *board, const int depth)
Recursively count positions.
Definition perft.c:790
static bool shapehash_append(ShapeHash *hash, const Board *b)
Append a shape to the hash table.
Definition perft.c:992
static void gamehash_init(GameHashTable *hash, int bitsize)
Hash table initialisation.
Definition perft.c:338
static void boardcache_append(BoardCache *hash, const Board *b)
Definition perft.c:682
static void positionarray_init(PosArray *array)
array initialisation.
Definition perft.c:589
static unsigned long long count_shape(ShapeHash *hash, BoardCache *cache, const Board *board, const int depth)
Recursively count shapes.
Definition perft.c:1007
bool positionhash_append(PositionHash *hash, const Board *b)
Append a position to the hash table.
Definition perft.c:738
static void shapehash_init(ShapeHash *hash, int bitsize)
Initialisation of the hash table.
Definition perft.c:964
static bool shapearray_append(ShapeArray *array, const unsigned long long shape)
Append a shape into the array.
Definition perft.c:932
static bool positionarray_append(PosArray *array, const CBoard *b)
Append a position.
Definition perft.c:610
static bool gamehash_fail(GameHashTable *hash, const Board *b, const int depth, GameStatistics *stats)
Seek for a position in the hash table.
Definition perft.c:395
void count_shapes(const Board *board, const int depth, const int size)
Count shapes.
Definition perft.c:1077
static void shapearray_init(ShapeArray *array)
array initialisation.
Definition perft.c:912
static void test_mobility(const Board *board, const int ply, Random *r, int *move, int *max_mobility, int *max_empties, const unsigned long long n)
Estimate move counts from a single game.
Definition perft.c:239
static void shapearray_delete(ShapeArray *array)
array supression.
Definition perft.c:922
void count_positions(const Board *board, const int depth, const int size)
Count positions.
Definition perft.c:822
unsigned long long shape_get_hash_code(const unsigned long long shape)
Compute a hash code.
Definition perft.c:881
void count_games(const Board *board, const int depth)
Move generator performance test.
Definition perft.c:107
const GameHash GAME_HASH_INIT
Definition perft.c:321
static void count_game(const Board *board, const int depth, GameStatistics *global_stats)
Move generator performance test function.
Definition perft.c:63
static void gamehash_delete(GameHashTable *hash)
Hash table resource freeing.
Definition perft.c:355
void positionhash_init(PositionHash *hash, int bitsize)
Initialisation of the hash table.
Definition perft.c:709
static void positionarray_delete(PosArray *array)
array supression.
Definition perft.c:599
Move generator test header file.
int size
Definition perft.c:630
int mask
Definition perft.c:631
Board * array
Definition perft.c:629
unsigned long long player
Definition board.h:27
unsigned long long opponent
Definition board.h:27
unsigned char x[13]
Definition perft.c:559
unsigned long long n_tries
Definition perft.c:328
GameHash * array
Definition perft.c:325
unsigned long long n_hits
Definition perft.c:329
int mask
Definition perft.c:327
int size
Definition perft.c:326
GameStatistics stats
Definition perft.c:316
Board board
Definition perft.c:315
int depth
Definition perft.c:317
unsigned long long n_passes
Definition perft.c:31
unsigned long long n_losses
Definition perft.c:29
unsigned int min_mobility
Definition perft.c:32
unsigned long long n_moves
Definition perft.c:27
unsigned long long n_wins
Definition perft.c:30
unsigned long long n_draws
Definition perft.c:28
unsigned int max_mobility
Definition perft.c:33
int hash_table_size
Definition options.h:25
CBoard * item
Definition perft.c:580
int size
Definition perft.c:582
int n
Definition perft.c:581
int mask
Definition perft.h:30
struct PosArray * array
Definition perft.h:28
int size
Definition perft.h:29
int n
Definition perft.c:904
int size
Definition perft.c:905
unsigned long long * item
Definition perft.c:903
int size
Definition perft.c:954
ShapeArray * array
Definition perft.c:953
int mask
Definition perft.c:955
void time_print(long long t, bool justified, FILE *f)
Print time as "D:HH:MM:SS.CC".
Definition util.c:131
void print_scientific(double v, const char *unit, FILE *f)
Print a value with a unit.
Definition util.c:250
unsigned long long random_get(Random *random)
Pseudo-random number generator.
Definition util.c:1043
void random_seed(Random *random, const unsigned long long seed)
Pseudo-random number seed.
Definition util.c:1062
Miscellaneous utilities header.
long long real_clock(void)
long long cpu_clock(void)
#define fatal_error(...)
Display an error message as "FATAL_ERROR : file name : function name : line number : ....
Definition util.h:349