My Project
Classes | Macros | Typedefs | Functions | Variables
board.h File Reference
#include "const.h"
#include <stdio.h>
#include <stdbool.h>

Go to the source code of this file.

Classes

struct  Board
 

Macros

#define DLL_API
 

Typedefs

typedef struct Board Board
 

Functions

void board_init (Board *)
 Set a board to the starting position. More...
 
int board_set (Board *, const char *)
 Set a board from a string description. More...
 
int board_from_FEN (Board *, const char *)
 Set a board from a string description. More...
 
int board_from_obj (Board *, const Board *, const int)
 Set a board from a Board object. More...
 
int board_compare (const Board *, const Board *)
 Compare two board. More...
 
bool board_equal (const Board *, const Board *)
 Compare two board for equality. More...
 
void board_symetry (const Board *, const int, Board *)
 symetric board More...
 
int board_unique (const Board *, Board *)
 unique board More...
 
void board_check (const Board *)
 Check board consistency. More...
 
void board_rand (Board *, int, struct Random *)
 Get a random board by playing random moves. More...
 
int board_count_last_flips (const Board *, const int)
 
unsigned long long board_get_move (const Board *, const int, struct Move *)
 Compute a move. More...
 
bool board_check_move (const Board *, struct Move *)
 Check if a move is legal. More...
 
void board_swap_players (Board *)
 Swap players. More...
 
void board_update (Board *, const struct Move *)
 
void board_restore (Board *, const struct Move *)
 
void board_pass (Board *)
 Passing move. More...
 
unsigned long long board_next (const Board *, const int, Board *)
 Compute a board resulting of a move played on a previous board. More...
 
unsigned long long board_pass_next (const Board *, const int, Board *)
 Compute a board resulting of an opponent move played on a previous board. More...
 
unsigned long long board_get_hash_code (const Board *)
 Compute a hash code. More...
 
int board_get_square_color (const Board *, const int)
 Get square color. More...
 
bool board_is_occupied (const Board *, const int)
 Check if a square is occupied. More...
 
void board_print (const Board *, const int, FILE *)
 Print out the board. More...
 
char * board_to_string (const Board *, const int, char *)
 convert the to a compact string. More...
 
void board_print_FEN (const Board *, const int, FILE *)
 print using FEN description. More...
 
char * board_to_FEN (const Board *, const int, char *)
 print to FEN description. More...
 
bool board_is_pass (const Board *)
 Check if current player should pass. More...
 
bool board_is_game_over (const Board *)
 Check if the game is over. More...
 
int board_count_empties (const Board *board)
 Check if the game is over. More...
 
int count_last_flip (const int, const unsigned long long)
 
DLL_API unsigned long long get_moves (const unsigned long long, const unsigned long long)
 Get legal moves. More...
 
DLL_API bool can_move (const unsigned long long, const unsigned long long)
 Check if a player can move. More...
 
unsigned long long get_moves_6x6 (const unsigned long long, const unsigned long long)
 Get legal moves on a 6x6 board. More...
 
bool can_move_6x6 (const unsigned long long, const unsigned long long)
 Check if a player can move. More...
 
int get_mobility (const unsigned long long, const unsigned long long)
 Count legal moves. More...
 
int get_weighted_mobility (const unsigned long long, const unsigned long long)
 
int get_potential_mobility (const unsigned long long, const unsigned long long)
 Get potential mobility. More...
 
void edge_stability_init (void)
 Initialize the edge stability tables. More...
 
int get_stability (const unsigned long long, const unsigned long long)
 Estimate the stability. More...
 
int get_edge_stability (const unsigned long long, const unsigned long long)
 Estimate the stability of edges. More...
 
int get_corner_stability (const unsigned long long)
 Estimate corner stability. More...
 

Variables

unsigned long long(* flip [BOARD_SIZE+2])(const unsigned long long, const unsigned long long)
 

Detailed Description

Board management header file.

Date
1998 - 2017
Author
Richard Delorme
Version
4.4

Macro Definition Documentation

◆ DLL_API

#define DLL_API

Typedef Documentation

◆ Board

typedef struct Board Board

Board : board representation

Function Documentation

◆ board_check()

void board_check ( const Board board)

Check board consistency.

Parameters
boardthe board to initialize

◆ board_check_move()

bool board_check_move ( const Board board,
Move move 
)

Check if a move is legal.

Parameters
boardboard
movea Move.
Returns
true if the move is legal, false otherwise.

◆ board_compare()

int board_compare ( const Board b1,
const Board b2 
)

Compare two board.

Parameters
b1first board
b2second board
Returns
-1, 0, 1

◆ board_count_empties()

int board_count_empties ( const Board board)

Check if the game is over.

Parameters
boardboard.
Returns
true if game is over, false otherwise.

◆ board_count_last_flips()

int board_count_last_flips ( const Board ,
const int   
)

◆ board_equal()

bool board_equal ( const Board b1,
const Board b2 
)

Compare two board for equality.

Parameters
b1first board
b2second board
Returns
true if both board are equal

◆ board_from_FEN()

int board_from_FEN ( Board board,
const char *  string 
)

Set a board from a string description.

Read a Forsyth-Edwards Notation string and translate it into our internal Board structure.

Parameters
boardthe board to set
stringstring describing the board
Returns
turn's color.

◆ board_from_obj()

int board_from_obj ( Board board,
const Board obj,
const int  turn 
)

Set a board from a Board object.

Parameters
boardthe board to set
objobject describing the board. assumes player attribute as black, opponent attribute as white
turnturn's color
Returns
turn's color.
Date
2018
Author
lavox

◆ board_get_hash_code()

unsigned long long board_get_hash_code ( const Board board)

Compute a hash code.

Parameters
boardthe board.
Returns
the hash code of the bitboard

◆ board_get_move()

unsigned long long board_get_move ( const Board board,
const int  x,
Move move 
)

Compute a move.

Compute how the board will be modified by a move without playing it.

Parameters
boardboard
xsquare on which to move.
movea Move structure remembering the modification.
Returns
the flipped discs.

◆ board_get_square_color()

int board_get_square_color ( const Board board,
const int  x 
)

Get square color.

returned value: 0 = player, 1 = opponent, 2 = empty;

Parameters
boardboard.
xsquare coordinate.
Returns
square color.

◆ board_init()

void board_init ( Board board)

Set a board to the starting position.

Parameters
boardthe board to initialize

◆ board_is_game_over()

bool board_is_game_over ( const Board board)

Check if the game is over.

Parameters
boardboard.
Returns
true if game is over, false otherwise.

◆ board_is_occupied()

bool board_is_occupied ( const Board board,
const int  x 
)

Check if a square is occupied.

Parameters
boardboard.
xsquare coordinate.
Returns
true if a square is occupied.

◆ board_is_pass()

bool board_is_pass ( const Board board)

Check if current player should pass.

Parameters
boardboard.
Returns
true if player is passing, false otherwise.

◆ board_next()

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.

Parameters
boardboard to play the move on.
xmove to play.
nextresulting board.
Returns
flipped discs.

◆ board_pass()

void board_pass ( Board board)

Passing move.

Modify a board by passing player's turn.

Parameters
boardboard to update.

◆ board_pass_next()

unsigned long long board_pass_next ( const Board board,
const int  x,
Board next 
)

Compute a board resulting of an opponent move played on a previous board.

Compute the board after passing and playing a move.

Parameters
boardboard to play the move on.
xopponent move to play.
nextresulting board.
Returns
flipped discs.

◆ board_print()

void board_print ( const Board board,
const int  player,
FILE *  f 
)

Print out the board.

Print an ASCII representation of the board to an output stream.

Parameters
boardboard to print.
playerplayer's color.
foutput stream.

◆ board_print_FEN()

void board_print_FEN ( const Board board,
const int  player,
FILE *  f 
)

print using FEN description.

Write the board according to the Forsyth-Edwards Notation.

Parameters
boardthe board to write
playerturn's color.
foutput stream.

◆ board_rand()

void board_rand ( Board board,
int  n_ply,
Random r 
)

Get a random board by playing random moves.

Parameters
boardThe output board.
n_plyThe number of random move to generate.
rThe random generator.

◆ board_restore()

void board_restore ( Board ,
const struct Move  
)

◆ board_set()

int board_set ( Board board,
const char *  string 
)

Set a board from a string description.

Read a standardized string (See http://www.nada.kth.se/~gunnar/download2.html for details) and translate it into our internal Board structure.

Parameters
boardthe board to set
stringstring describing the board
Returns
turn's color.

◆ board_swap_players()

void board_swap_players ( Board board)

Swap players.

Swap players, i.e. change player's turn.

Parameters
boardboard

◆ board_symetry()

void board_symetry ( const Board board,
const int  s,
Board sym 
)

symetric board

Parameters
boardinput board
ssymetry
symsymetric output board

◆ board_to_FEN()

char * board_to_FEN ( const Board board,
const int  player,
char *  string 
)

print to FEN description.

Write the board into a Forsyth-Edwards Notation string.

Parameters
boardthe board to write
playerturn's color.
stringoutput string.

◆ board_to_string()

char * board_to_string ( const Board board,
const int  player,
char *  s 
)

convert the to a compact string.

Parameters
boardboard to convert.
playerplayer's color.
soutput string.

◆ board_unique()

int board_unique ( const Board board,
Board unique 
)

unique board

Compute a board unique from all its possible symertries.

Parameters
boardinput board
uniqueoutput board

◆ board_update()

void board_update ( Board ,
const struct Move  
)

◆ can_move()

DLL_API bool can_move ( const unsigned long long  P,
const unsigned long long  O 
)

Check if a player can move.

Parameters
Pbitboard with player's discs.
Obitboard with opponent's discs.
Returns
true or false.

◆ can_move_6x6()

bool can_move_6x6 ( const unsigned long long  P,
const unsigned long long  O 
)

Check if a player can move.

Parameters
Pbitboard with player's discs.
Obitboard with opponent's discs.
Returns
true or false.

◆ count_last_flip()

int count_last_flip ( const int  x,
const unsigned long long  P 
)

◆ edge_stability_init()

void edge_stability_init ( void  )

Initialize the edge stability tables.

◆ get_corner_stability()

int get_corner_stability ( const unsigned long long  P)

Estimate corner stability.

Count the number of stable discs around the corner. Limiting the count to the corner keep the function fast but still get this information, particularly important at Othello. Corner stability will be used for move sorting.

Parameters
Pbitboard with player's discs.
Returns
the number of stable discs around the corner.

◆ get_edge_stability()

int get_edge_stability ( const unsigned long long  P,
const unsigned long long  O 
)

Estimate the stability of edges.

Count the number (in fact a lower estimate) of stable discs on the edges.

Parameters
Pbitboard with player's discs.
Obitboard with opponent's discs.
Returns
the number of stable discs on the edges.

◆ get_mobility()

int get_mobility ( const unsigned long long  P,
const unsigned long long  O 
)

Count legal moves.

Compute mobility, ie the number of legal moves.

Parameters
Pbitboard with player's discs.
Obitboard with opponent's discs.
Returns
a count of all legal moves.

◆ get_moves()

DLL_API unsigned long long get_moves ( const unsigned long long  P,
const unsigned long long  O 
)

Get legal moves.

Compute a bitboard where each coordinate with a legal move is set to one.

Parameters
Pbitboard with player's discs.
Obitboard with opponent's discs.
Returns
all legal moves in a 64-bit unsigned integer.

◆ get_moves_6x6()

unsigned long long get_moves_6x6 ( const unsigned long long  P,
const unsigned long long  O 
)

Get legal moves on a 6x6 board.

Compute a bitboard where each coordinate with a legal move is set to one.

Parameters
Pbitboard with player's discs.
Obitboard with opponent's discs.
Returns
all legal moves in a 64-bit unsigned integer.

◆ get_potential_mobility()

int get_potential_mobility ( const unsigned long long  P,
const unsigned long long  O 
)

Get potential mobility.

Count the list of empty squares in contact of a player square.

Parameters
Pbitboard with player's discs.
Obitboard with opponent's discs.
Returns
a count of potential moves.

◆ get_stability()

int get_stability ( const unsigned long long  P,
const unsigned long long  O 
)

Estimate the stability.

Count the number (in fact a lower estimate) of stable discs.

Parameters
Pbitboard with player's discs.
Obitboard with opponent's discs.
Returns
the number of stable discs.

◆ get_weighted_mobility()

int get_weighted_mobility ( const unsigned long long  P,
const unsigned long long  O 
)

Variable Documentation

◆ flip

unsigned long long(* flip[BOARD_SIZE+2])(const unsigned long long, const unsigned long long) ( const unsigned long long  ,
const unsigned long long   
)
extern

Array of functions to compute flipped discs