My Project
Classes | Typedefs | Functions | Variables
move.c File Reference

Move & list of moves management. More...

#include "move.h"
#include "bit.h"
#include "board.h"
#include "hash.h"
#include "search.h"
#include "settings.h"
#include "stats.h"
#include <limits.h>
#include <assert.h>
#include <ctype.h>
#include <string.h>

Classes

struct  MBoard
 
struct  MoveArray
 

Typedefs

typedef struct MoveArray MoveArray
 

Functions

int symetry (int x, const int sym)
 Get a symetric square coordinate. More...
 
char * move_to_string (const int x, const int player, char *s)
 Print out a move. More...
 
void move_print (const int x, const int player, FILE *f)
 Print out a move. More...
 
bool move_wipeout (const Move *move, const Board *board)
 Check if a move wins 64-0. More...
 
static void move_evaluate (Move *move, Search *search, const HashData *hash_data, const int sort_alpha, const int sort_depth)
 Evaluate a list of move. More...
 
int movelist_get_moves (MoveList *movelist, const Board *board)
 Get moves from a position. More...
 
void movelist_print (const MoveList *movelist, const int player, FILE *f)
 Print out a movelist. More...
 
Movemove_next_best (Move *previous_best)
 Return the next best move from the list. More...
 
Movemove_next_most_expensive (Move *previous_best)
 Return the next best move from the list. More...
 
Movemove_next (Move *move)
 Return the next move from the list. More...
 
Movemovelist_best (MoveList *movelist)
 Return the best move of the list. More...
 
Movemovelist_first (MoveList *movelist)
 Return the first move of the list. More...
 
void movelist_evaluate (MoveList *movelist, Search *search, const HashData *hash_data, const int alpha, const int depth)
 Evaluate a list of move in order to sort it. More...
 
Movemovelist_sort_bestmove (MoveList *movelist, const int move)
 Sort a move as best. More...
 
void movelist_sort_cost (MoveList *movelist, const HashData *hash_data)
 Sort all moves except the first, based on move cost & hash_table storage. More...
 
void movelist_sort (MoveList *movelist)
 Sort all moves. More...
 
Movemovelist_exclude (MoveList *movelist, const int move)
 Exclude a move. More...
 
bool movelist_is_empty (const MoveList *movelist)
 Check if the list is empty. More...
 
void line_init (Line *line, const int player)
 Initialize a sequence of moves. More...
 
void line_push (Line *line, const int x)
 Add a move to the sequence. More...
 
void line_pop (Line *line)
 Remove the last move from a sequence. More...
 
void line_copy (Line *dest, const Line *src, const int from)
 Copy part of a sequence to another sequence. More...
 
void line_print (const Line *line, int width, const char *separator, FILE *f)
 Print a move sequence. More...
 
char * line_to_string (const Line *line, int n, const char *separator, char *string)
 Line to string. More...
 
static void movearray_init (MoveArray *array)
 array initialisation. More...
 
static void movearray_delete (MoveArray *array)
 array supression. More...
 
static bool movearray_append (MoveArray *array, const Board *b, const int x)
 Append a position. More...
 
void movehash_init (MoveHash *hash, int bitsize)
 Initialisation of the hash table. More...
 
void movehash_delete (MoveHash *hash)
 Free the hash table. More...
 
bool movehash_append (MoveHash *hash, const Board *b, const int x)
 Append a position to the hash table. More...
 

Variables

const Move MOVE_INIT = {0, NOMOVE, -SCORE_INF, 0, NULL}
 
const Move MOVE_PASS = {0, PASS, -SCORE_INF, 0, NULL}
 
const int SQUARE_VALUE []
 

Detailed Description

Move & list of moves management.

Move & list of moves management - header file.

Date
1998 - 2017
Author
Richard Delorme
Version
4.4

Typedef Documentation

◆ MoveArray

typedef struct MoveArray MoveArray

Array of MBoard.

Function Documentation

◆ line_copy()

void line_copy ( Line dest,
const Line src,
const int  from 
)

Copy part of a sequence to another sequence.

Parameters
destthe destination move sequence.
srcthe source move sequence.
fromthe point to copy from.

◆ line_init()

void line_init ( Line line,
const int  player 
)

Initialize a sequence of moves.

Parameters
linethe move sequence.
playercolor of the first player of the sequence.

◆ line_pop()

void line_pop ( Line line)

Remove the last move from a sequence.

Parameters
linethe move sequence.

◆ line_print()

void line_print ( const Line line,
int  width,
const char *  separator,
FILE *  f 
)

Print a move sequence.

Parameters
linethe move sequence.
widthwidth of the line to print (in characters).
separatora string to print between moves.
foutput stream.

◆ line_push()

void line_push ( Line line,
const int  x 
)

Add a move to the sequence.

Parameters
linethe move sequence.
xmove coordinate.

◆ line_to_string()

char * line_to_string ( const Line line,
int  n,
const char *  separator,
char *  string 
)

Line to string.

Parameters
linethe move sequence.
nnumber of moves to add.
separatora string to print between moves.
stringoutput string receiving the line.

◆ move_evaluate()

static void move_evaluate ( Move move,
Search search,
const HashData hash_data,
const int  sort_alpha,
const int  sort_depth 
)
static

Evaluate a list of move.

Evaluate the moves to sort them. Evaluation is based on, in order of importance:

  • wipeout move : 1 << 30
  • first hash move : 1 << 29
  • second hash move: 1 << 28
  • shallow search : 1 << 22 to 1 << 14
  • opponent mobility: 1 << 15 32768...1048576
  • player stability near the corner: 1 << 11 2048...24576
  • opponent potential mobility: 1 << 5 32...1024
  • square value 1 << 1: 2 ...18
  • parity: 1 << 0: 0 ... 1
Parameters
moveMove to evaluate.
searchPosition to evaluate.
hash_dataPosition (maybe) stored in the hashtable.
sort_alphaAlpha bound to evaluate moves.
sort_depthdepth for the shallow search

◆ move_next()

Move * move_next ( Move move)

Return the next move from the list.

Parameters
moveprevious move.
Returns
the next move in the list.

◆ move_next_best()

Move * move_next_best ( Move previous_best)

Return the next best move from the list.

Parameters
previous_bestLast best move.
Returns
the following best move in the list.

◆ move_next_most_expensive()

Move * move_next_most_expensive ( Move previous_best)

Return the next best move from the list.

Parameters
previous_bestLast best move.
Returns
the following best move in the list.

◆ move_print()

void move_print ( const int  x,
const int  player,
FILE *  f 
)

Print out a move.

Print the move, using letter case to distinguish player's color, to an output stream.

Parameters
xsquare coordinate to print.
playerplayer color.
foutput stream.

◆ move_to_string()

char * move_to_string ( const int  x,
const int  player,
char *  s 
)

Print out a move.

Print the move, using letter case to distinguish player's color, to an output stream.

Parameters
xSquare coordinate to print.
playerPlayer color.
sOutput string.
Returns
the output string.

◆ move_wipeout()

bool move_wipeout ( const Move move,
const Board board 
)

Check if a move wins 64-0.

Check if a move flipped all the opponent discs.

Parameters
moveMove.
boardBoard.
Returns
true if a move wins 64-0, false otherwise.

◆ movearray_append()

static bool movearray_append ( MoveArray array,
const Board b,
const int  x 
)
static

Append a position.

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

◆ movearray_delete()

static void movearray_delete ( MoveArray array)
static

array supression.

Parameters
arrayArray of positions.

◆ movearray_init()

static void movearray_init ( MoveArray array)
static

array initialisation.

Parameters
arrayArray of positions.

◆ movehash_append()

bool movehash_append ( MoveHash hash,
const Board b,
const int  x 
)

Append a position to the hash table.

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

◆ movehash_delete()

void movehash_delete ( MoveHash hash)

Free the hash table.

Parameters
hashHash table.

◆ movehash_init()

void movehash_init ( MoveHash hash,
int  bitsize 
)

Initialisation of the hash table.

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

◆ movelist_best()

Move * movelist_best ( MoveList movelist)

Return the best move of the list.

Parameters
movelistThe list of move.
Returns
the best move.

◆ movelist_evaluate()

void movelist_evaluate ( MoveList movelist,
Search search,
const HashData hash_data,
const int  alpha,
const int  depth 
)

Evaluate a list of move in order to sort it.

Parameters
movelistList of moves to sort.
searchPosition to evaluate.
hash_dataPosition (maybe) stored in the hashtable.
alphaAlpha bound to evaluate moves.
depthdepth for the shallow search

◆ movelist_exclude()

Move * movelist_exclude ( MoveList movelist,
const int  move 
)

Exclude a move.

Parameters
movelistList of moves to sort.
moveMove to exclude.

◆ movelist_first()

Move * movelist_first ( MoveList movelist)

Return the first move of the list.

Parameters
movelistThe list of move.
Returns
the first move.

◆ movelist_get_moves()

int movelist_get_moves ( MoveList movelist,
const Board board 
)

Get moves from a position.

Parameters
movelistmovelist.
boardboard.
Returns
move number.

◆ movelist_is_empty()

bool movelist_is_empty ( const MoveList movelist)

Check if the list is empty.

Parameters
movelistThe list of move.
Returns
true if the list is empty, false otherwise.

◆ movelist_print()

void movelist_print ( const MoveList movelist,
const int  player,
FILE *  f 
)

Print out a movelist.

Print the moves, using letter case to distinguish player's color, to an output stream.

Parameters
movelista list of moves.
playerplayer color.
foutput stream.

◆ movelist_sort()

void movelist_sort ( MoveList movelist)

Sort all moves.

Parameters
movelistList of moves to sort.

◆ movelist_sort_bestmove()

Move * movelist_sort_bestmove ( MoveList movelist,
const int  move 
)

Sort a move as best.

Put the best move at the head of the list.

Parameters
movelistList of moves to sort.
moveBest move to to set first.
Returns
A move, occasionally illegal, whose successor was the original successor of the new best move.

◆ movelist_sort_cost()

void movelist_sort_cost ( MoveList movelist,
const HashData hash_data 
)

Sort all moves except the first, based on move cost & hash_table storage.

Parameters
movelistList of moves to sort.
hash_dataData from the hash table.

◆ symetry()

int symetry ( int  x,
const int  sym 
)

Get a symetric square coordinate.

Parameters
xSquare coordinate.
symSymetry.
Returns
Symetric square coordinate.

Variable Documentation

◆ MOVE_INIT

const Move MOVE_INIT = {0, NOMOVE, -SCORE_INF, 0, NULL}

◆ MOVE_PASS

const Move MOVE_PASS = {0, PASS, -SCORE_INF, 0, NULL}

◆ SQUARE_VALUE

const int SQUARE_VALUE[]
Initial value:
= {
18, 4, 16, 12, 12, 16, 4, 18,
4, 2, 6, 8, 8, 6, 2, 4,
16, 6, 14, 10, 10, 14, 6, 16,
12, 8, 10, 0, 0, 10, 8, 12,
12, 8, 10, 0, 0, 10, 8, 12,
16, 6, 14, 10, 10, 14, 6, 16,
4, 2, 6, 8, 8, 6, 2, 4,
18, 4, 16, 12, 12, 16, 4, 18
}