Classes | Typedefs | Functions | Variables
perft.c File Reference

Move generator test. More...

#include "bit.h"
#include "board.h"
#include "move.h"
#include "hash.h"
#include "options.h"
#include "settings.h"
#include "util.h"
#include "perft.h"
#include <stdlib.h>
#include <math.h>

Classes

struct  GameStatistics
 
struct  GameHash
 
struct  GameHashTable
 
struct  CBoard
 
struct  PosArray
 
struct  BoardCache
 
struct  ShapeArray
 
struct  ShapeHash
 

Typedefs

typedef struct CBoard CBoard
 
typedef struct PosArray PosArray
 

Functions

void game_statistics_cumulate (GameStatistics *global, const GameStatistics *local)
 Accumulate statistics: add local data to global ones. More...
 
static void count_game (const Board *board, const int depth, GameStatistics *global_stats)
 Move generator performance test function. More...
 
void count_games (const Board *board, const int depth)
 Move generator performance test. More...
 
static void estimate_game (const Board *board, const int depth, Random *r, double *n)
 Estimate move counts from a single game. More...
 
void estimate_games (const Board *board, const long long n)
 Move estimate games. More...
 
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. More...
 
void seek_highest_mobility (const Board *board, const unsigned long long t)
 Move estimate games. More...
 
static void gamehash_init (GameHashTable *hash, int bitsize)
 Hash table initialisation. More...
 
static void gamehash_delete (GameHashTable *hash)
 Hash table resource freeing. More...
 
static void gamehash_store (GameHashTable *hash, const Board *b, const int depth, const GameStatistics *stats)
 Store a game position. More...
 
static bool gamehash_fail (GameHashTable *hash, const Board *b, const int depth, GameStatistics *stats)
 Seek for a position in the hash table. More...
 
static void quick_count_game_6x6 (GameHashTable *hash, const Board *board, const int depth, GameStatistics *global_stats)
 Count games recursively. More...
 
static void quick_count_game (GameHashTable *hash, const Board *board, const int depth, GameStatistics *global_stats)
 Count games recursively. More...
 
void quick_count_games (const Board *board, const int depth, const int size)
 Count games. More...
 
static void compact_board (const Board *b, CBoard *c)
 
static void positionarray_init (PosArray *array)
 array initialisation. More...
 
static void positionarray_delete (PosArray *array)
 array supression. More...
 
static bool positionarray_append (PosArray *array, const CBoard *b)
 Append a position. More...
 
static void boardcache_init (BoardCache *hash, int bitsize)
 Initialisation of the hash table. More...
 
static void boardcache_delete (BoardCache *hash)
 Free the hash table. More...
 
static bool boardcache_undone (BoardCache *hash, const Board *b)
 Append a shape to the hash table. More...
 
static void boardcache_append (BoardCache *hash, const Board *b)
 
void positionhash_init (PositionHash *hash, int bitsize)
 Initialisation of the hash table. More...
 
void positionhash_delete (PositionHash *hash)
 Free the hash table. More...
 
bool positionhash_append (PositionHash *hash, const Board *b)
 Append a position to the hash table. More...
 
static unsigned long long count_position (PositionHash *hash, BoardCache *cache, const Board *board, const int depth)
 Recursively count positions. More...
 
static unsigned long long count_position_6x6 (PositionHash *hash, BoardCache *cache, const Board *board, const int depth)
 Recursively count positions. More...
 
void count_positions (const Board *board, const int depth, const int size)
 Count positions. More...
 
unsigned long long shape_unique (unsigned long long shape)
 unique shape. More...
 
unsigned long long shape_get_hash_code (const unsigned long long shape)
 Compute a hash code. More...
 
static void shapearray_init (ShapeArray *array)
 array initialisation. More...
 
static void shapearray_delete (ShapeArray *array)
 array supression. More...
 
static bool shapearray_append (ShapeArray *array, const unsigned long long shape)
 Append a shape into the array. More...
 
static void shapehash_init (ShapeHash *hash, int bitsize)
 Initialisation of the hash table. More...
 
static void shapehash_delete (ShapeHash *hash)
 Free the hash table. More...
 
static bool shapehash_append (ShapeHash *hash, const Board *b)
 Append a shape to the hash table. More...
 
static unsigned long long count_shape (ShapeHash *hash, BoardCache *cache, const Board *board, const int depth)
 Recursively count shapes. More...
 
static unsigned long long count_shape_6x6 (ShapeHash *hash, BoardCache *cache, const Board *board, const int depth)
 Recursively count shapes. More...
 
void count_shapes (const Board *board, const int depth, const int size)
 Count shapes. More...
 
bool seek_position (const Board *target, const Board *board, Line *line)
 seek a game that reach to a position More...
 

Variables

const GameStatistics GAME_STATISTICS_INIT = {0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 64, 0}
 
const GameHash GAME_HASH_INIT = {{0ULL, 0ULL}, {0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 64, 0}, 0}
 

Detailed Description

Move generator test.

Date
1998 - 2017
Author
Richard Delorme
Version
4.4

Typedef Documentation

◆ CBoard

typedef struct CBoard CBoard

Compact board 13 bytes

◆ PosArray

typedef struct PosArray PosArray

Array of position.

Function Documentation

◆ boardcache_append()

static void boardcache_append ( BoardCache hash,
const Board b 
)
static

◆ boardcache_delete()

static void boardcache_delete ( BoardCache hash)
static

Free the hash table.

Parameters
hashHash table.

◆ boardcache_init()

static void boardcache_init ( BoardCache hash,
int  bitsize 
)
static

Initialisation of the hash table.

Parameters
hashHash table.
bitsizeHash table size (as log2(size)).

◆ boardcache_undone()

static bool boardcache_undone ( BoardCache hash,
const Board b 
)
static

Append a shape to the hash table.

Parameters
hashHash table.
bPosition.

◆ compact_board()

static void compact_board ( const Board b,
CBoard c 
)
static

◆ count_game()

static void count_game ( const Board board,
const int  depth,
GameStatistics global_stats 
)
static

Move generator performance test function.

Parameters
board
depth
global_statsstatistics

◆ count_games()

void count_games ( const Board board,
const int  depth 
)

Move generator performance test.

Parameters
board
depth

◆ count_position()

static unsigned long long count_position ( PositionHash hash,
BoardCache cache,
const Board board,
const int  depth 
)
static

Recursively count positions.

Parameters
hashHash table with unique positions.
cacheHash table caching count search.
boardposition.
depthdepth.

◆ count_position_6x6()

static unsigned long long count_position_6x6 ( PositionHash hash,
BoardCache cache,
const Board board,
const int  depth 
)
static

Recursively count positions.

Parameters
hashHash table with unique positions.
cacheHash table caching count search.
boardposition.
depthdepth.

◆ count_positions()

void count_positions ( const Board board,
const int  depth,
const int  size 
)

Count positions.

Parameters
boardposition.
depthdepth.
sizeboard_size (8 or 6).

◆ count_shape()

static unsigned long long count_shape ( ShapeHash hash,
BoardCache cache,
const Board board,
const int  depth 
)
static

Recursively count shapes.

Parameters
hashHash table with unique shapes.
cacheHash table caching count search.
boardshape.
depthdepth.

◆ count_shape_6x6()

static unsigned long long count_shape_6x6 ( ShapeHash hash,
BoardCache cache,
const Board board,
const int  depth 
)
static

Recursively count shapes.

Parameters
hashHash table with unique shapes.
cacheHash table caching count search.
boardBoard.
depthdepth.

◆ count_shapes()

void count_shapes ( const Board board,
const int  depth,
const int  size 
)

Count shapes.

Parameters
boardBoard.
depthdepth.
sizesize (8 or 6).

◆ estimate_game()

static void estimate_game ( const Board board,
const int  depth,
Random r,
double *  n 
)
static

Estimate move counts from a single game.

Parameters
boardBoard
depthDepth.
rrandom generator
nnode counter array.

◆ estimate_games()

void estimate_games ( const Board board,
const long long  n 
)

Move estimate games.

Parameters
board
nNumber of trials

◆ game_statistics_cumulate()

void game_statistics_cumulate ( GameStatistics global,
const GameStatistics local 
)

Accumulate statistics: add local data to global ones.

Parameters
globalGlobal statistics.
localLocal statistics.

◆ gamehash_delete()

static void gamehash_delete ( GameHashTable hash)
static

Hash table resource freeing.

Parameters
hashHash table.

◆ gamehash_fail()

static bool gamehash_fail ( GameHashTable hash,
const Board b,
const int  depth,
GameStatistics stats 
)
static

Seek for a position in the hash table.

Parameters
hashHash table.
bposition.
depthDepth.
statsposition's statistics.
Returns
true if no position is found, false otherwise.

◆ gamehash_init()

static void gamehash_init ( GameHashTable hash,
int  bitsize 
)
static

Hash table initialisation.

Parameters
hashHash table.
bitsizeHash table size (as log2(size)).

◆ gamehash_store()

static void gamehash_store ( GameHashTable hash,
const Board b,
const int  depth,
const GameStatistics stats 
)
static

Store a game position.

Parameters
hashHash table.
bposition.
depthDepth.
statsposition's statistics.

◆ positionarray_append()

static bool positionarray_append ( PosArray array,
const CBoard b 
)
static

Append a position.

Parameters
arrayArray of positions.
bPosition.
Returns
true if a position is added to the array, false if it is already present.

◆ positionarray_delete()

static void positionarray_delete ( PosArray array)
static

array supression.

Parameters
arrayArray of positions.

◆ positionarray_init()

static void positionarray_init ( PosArray array)
static

array initialisation.

Parameters
arrayArray of positions.

◆ positionhash_append()

bool positionhash_append ( PositionHash hash,
const Board b 
)

Append a position to the hash table.

Parameters
hashHash table.
bPosition.
Returns
true if a position is added to the hash table, false otherwsise.

◆ positionhash_delete()

void positionhash_delete ( PositionHash hash)

Free the hash table.

Parameters
hashHash table.

◆ positionhash_init()

void positionhash_init ( PositionHash hash,
int  bitsize 
)

Initialisation of the hash table.

Parameters
hashHash table.
bitsizeHash table size (as log2(size)).

◆ quick_count_game()

static void quick_count_game ( GameHashTable hash,
const Board board,
const int  depth,
GameStatistics global_stats 
)
static

Count games recursively.

Parameters
hashHash table.
boardposition.
depthDepth.
global_statsGame's statistics.

◆ quick_count_game_6x6()

static void quick_count_game_6x6 ( GameHashTable hash,
const Board board,
const int  depth,
GameStatistics global_stats 
)
static

Count games recursively.

Parameters
hashHash table.
boardposition.
depthDepth.
global_statsGame's statistics.

◆ quick_count_games()

void quick_count_games ( const Board board,
const int  depth,
const int  size 
)

Count games.

Parameters
boardposition.
depthDepth.
sizeSize of the board (6 or 8).

◆ seek_highest_mobility()

void seek_highest_mobility ( const Board board,
const unsigned long long  t 
)

Move estimate games.

Parameters
board
ttime to test

◆ seek_position()

bool seek_position ( const Board target,
const Board board,
Line line 
)

seek a game that reach to a position

Parameters
targetposition seeked
boardstarting position.
lineline to reach the target position

◆ shape_get_hash_code()

unsigned long long shape_get_hash_code ( const unsigned long long  shape)

Compute a hash code.

Parameters
shapeBoard shape.
Returns
The hash code of the bitboard.

◆ shape_unique()

unsigned long long shape_unique ( unsigned long long  shape)

unique shape.

Parameters
shapeinput Shape.
Returns

◆ shapearray_append()

static bool shapearray_append ( ShapeArray array,
const unsigned long long  shape 
)
static

Append a shape into the array.

Parameters
arrayArray of shapes.
shapeShape.

◆ shapearray_delete()

static void shapearray_delete ( ShapeArray array)
static

array supression.

Parameters
arrayArray of shapes.

◆ shapearray_init()

static void shapearray_init ( ShapeArray array)
static

array initialisation.

Parameters
arrayArray of shapes.

◆ shapehash_append()

static bool shapehash_append ( ShapeHash hash,
const Board b 
)
static

Append a shape to the hash table.

Parameters
hashHash table.
bPosition.

◆ shapehash_delete()

static void shapehash_delete ( ShapeHash hash)
static

Free the hash table.

Parameters
hashHash table.

◆ shapehash_init()

static void shapehash_init ( ShapeHash hash,
int  bitsize 
)
static

Initialisation of the hash table.

Parameters
hashHash table.
bitsizeHash table size (as log2(size)).

◆ test_mobility()

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 
)
static

Estimate move counts from a single game.

Parameters
boardBoard
plyPly.
rrandom generator.
movemove array.
max_mobilityHighest mobility count.
max_emptiesStage of highest mobility.
ntest counter.

Variable Documentation

◆ GAME_HASH_INIT

const GameHash GAME_HASH_INIT = {{0ULL, 0ULL}, {0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 64, 0}, 0}

Hash entry initial value

◆ GAME_STATISTICS_INIT

const GameStatistics GAME_STATISTICS_INIT = {0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 64, 0}

initial statistics