My Project
|
#include "board.h"
#include "bit.h"
#include "hash.h"
#include "move.h"
#include "settings.h"
#include "util.h"
#include <ctype.h>
#include <stdlib.h>
#include <assert.h>
#include "flip_carry_32.c"
#include "count_last_flip_carry_32.c"
Macros | |
#define | packA1A8(X) (((((unsigned int)(X) & 0x01010101u) + (((unsigned int)((X) >> 32) & 0x01010101u) << 4)) * 0x01020408u) >> 24) |
#define | packH1H8(X) (((((unsigned int)((X) >> 32) & 0x80808080u) + (((unsigned int)(X) & 0x80808080u) >> 4)) * 0x00204081u) >> 24) |
Functions | |
void | board_swap_players (Board *board) |
Swap players. More... | |
int | board_set (Board *board, const char *string) |
Set a board from a string description. More... | |
int | board_from_FEN (Board *board, const char *string) |
Set a board from a string description. More... | |
int | board_from_obj (Board *board, const Board *obj, const int turn) |
Set a board from a Board object. More... | |
void | board_init (Board *board) |
Set a board to the starting position. More... | |
void | board_check (const Board *board) |
Check board consistency. More... | |
int | board_compare (const Board *b1, const Board *b2) |
Compare two board. More... | |
bool | board_equal (const Board *b1, const Board *b2) |
Compare two board for equality. More... | |
void | board_symetry (const Board *board, const int s, Board *sym) |
symetric board More... | |
int | board_unique (const Board *board, Board *unique) |
unique board More... | |
void | board_rand (Board *board, int n_ply, Random *r) |
Get a random board by playing random moves. More... | |
unsigned long long | board_get_move (const Board *board, const int x, Move *move) |
Compute a move. More... | |
bool | board_check_move (const Board *board, Move *move) |
Check if a move is legal. More... | |
void | board_update (Board *board, const Move *move) |
Update a board. More... | |
void | board_restore (Board *board, const Move *move) |
Restore a board. More... | |
void | board_pass (Board *board) |
Passing move. More... | |
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. More... | |
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. More... | |
static unsigned long long | get_some_moves (const unsigned long long P, const unsigned long long mask, const int dir) |
Get a part of the moves. More... | |
DLL_API unsigned long long | get_moves (const unsigned long long P, const unsigned long long O) |
Get legal moves. More... | |
unsigned long long | get_moves_6x6 (const unsigned long long P, const unsigned long long O) |
Get legal moves on a 6x6 board. More... | |
DLL_API bool | can_move (const unsigned long long P, const unsigned long long O) |
Check if a player can move. More... | |
bool | can_move_6x6 (const unsigned long long P, const unsigned long long O) |
Check if a player can move. More... | |
int | get_mobility (const unsigned long long P, const unsigned long long O) |
Count legal moves. More... | |
int | get_weighted_mobility (const unsigned long long P, const unsigned long long O) |
static unsigned long long | get_some_potential_moves (const unsigned long long P, const int dir) |
Get some potential moves. More... | |
static unsigned long long | get_potential_moves (const unsigned long long P, const unsigned long long O) |
Get potential moves. More... | |
int | get_potential_mobility (const unsigned long long P, const unsigned long long O) |
Get potential mobility. More... | |
static int | find_edge_stable (const int old_P, const int old_O, int stable) |
search stable edge patterns. More... | |
void | edge_stability_init (void) |
Initialize the edge stability tables. More... | |
static unsigned long long | get_full_lines (const unsigned long long line, const int dir) |
Get full lines. More... | |
static unsigned long long | get_stable_edge (const unsigned long long P, const unsigned long long O) |
Get stable edge. More... | |
int | get_stability (const unsigned long long P, const unsigned long long O) |
Estimate the stability. More... | |
int | get_edge_stability (const unsigned long long P, const unsigned long long O) |
Estimate the stability of edges. More... | |
int | get_corner_stability (const unsigned long long P) |
Estimate corner stability. More... | |
unsigned long long | board_get_hash_code (const Board *board) |
Compute a hash code. More... | |
int | board_get_square_color (const Board *board, const int x) |
Get square color. More... | |
bool | board_is_occupied (const Board *board, const int x) |
Check if a square is occupied. More... | |
bool | board_is_pass (const Board *board) |
Check if current player should pass. More... | |
bool | board_is_game_over (const Board *board) |
Check if the game is over. More... | |
int | board_count_empties (const Board *board) |
Check if the game is over. More... | |
void | board_print (const Board *board, const int player, FILE *f) |
Print out the board. More... | |
char * | board_to_string (const Board *board, const int player, char *s) |
convert the to a compact string. More... | |
void | board_print_FEN (const Board *board, const int player, FILE *f) |
print using FEN description. More... | |
char * | board_to_FEN (const Board *board, const int player, char *string) |
print to FEN description. More... | |
Variables | |
static unsigned char | edge_stability [256][256] |
static const unsigned long long | A1_A8 [256] |
static const unsigned long long | H1_H8 [256] |
This module deals with the Board management.
The Board is represented with a structure containing the following data:
High level functions are provided to set/modify the board data or to compute some board properties. Most of the functions are optimized to be as fast as possible, while remaining readable.
#define packA1A8 | ( | X | ) | (((((unsigned int)(X) & 0x01010101u) + (((unsigned int)((X) >> 32) & 0x01010101u) << 4)) * 0x01020408u) >> 24) |
#define packH1H8 | ( | X | ) | (((((unsigned int)((X) >> 32) & 0x80808080u) + (((unsigned int)(X) & 0x80808080u) >> 4)) * 0x00204081u) >> 24) |
void board_check | ( | const Board * | board | ) |
Check board consistency.
board | the board to initialize |
Check if a move is legal.
board | board |
move | a Move. |
Compare two board.
b1 | first board |
b2 | second board |
int board_count_empties | ( | const Board * | board | ) |
Check if the game is over.
board | board. |
Compare two board for equality.
b1 | first board |
b2 | second board |
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.
board | the board to set |
string | string describing the board |
Set a board from a Board object.
board | the board to set |
obj | object describing the board. assumes player attribute as black, opponent attribute as white |
turn | turn's color |
unsigned long long board_get_hash_code | ( | const Board * | board | ) |
Compute a hash code.
board | the board. |
Compute a move.
Compute how the board will be modified by a move without playing it.
board | board |
x | square on which to move. |
move | a Move structure remembering the modification. |
int board_get_square_color | ( | const Board * | board, |
const int | x | ||
) |
Get square color.
returned value: 0 = player, 1 = opponent, 2 = empty;
board | board. |
x | square coordinate. |
void board_init | ( | Board * | board | ) |
Set a board to the starting position.
board | the board to initialize |
bool board_is_game_over | ( | const Board * | board | ) |
Check if the game is over.
board | board. |
bool board_is_occupied | ( | const Board * | board, |
const int | x | ||
) |
Check if a square is occupied.
board | board. |
x | square coordinate. |
bool board_is_pass | ( | const Board * | board | ) |
Check if current player should pass.
board | board. |
Compute a board resulting of a move played on a previous board.
board | board to play the move on. |
x | move to play. |
next | resulting board. |
void board_pass | ( | Board * | board | ) |
Passing move.
Modify a board by passing player's turn.
board | board to update. |
Compute a board resulting of an opponent move played on a previous board.
Compute the board after passing and playing a move.
board | board to play the move on. |
x | opponent move to play. |
next | resulting board. |
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.
board | board to print. |
player | player's color. |
f | output stream. |
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.
board | the board to write |
player | turn's color. |
f | output stream. |
Get a random board by playing random moves.
board | The output board. |
n_ply | The number of random move to generate. |
r | The random generator. |
Restore a board.
Restore a board by un-flipping its discs and restoring every other data, according to the 'move' description, in order to cancel a board_update_move.
board | board to restore. |
move | a Move structure describing the modification. |
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.
board | the board to set |
string | string describing the board |
void board_swap_players | ( | Board * | board | ) |
Swap players.
Swap players, i.e. change player's turn.
board | board |
symetric board
board | input board |
s | symetry |
sym | symetric output board |
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.
board | the board to write |
player | turn's color. |
string | output string. |
char * board_to_string | ( | const Board * | board, |
const int | player, | ||
char * | s | ||
) |
convert the to a compact string.
board | board to convert. |
player | player's color. |
s | output string. |
unique board
Compute a board unique from all its possible symertries.
board | input board |
unique | output board |
Update a board.
Update a board by flipping its discs and updating every other data, according to the 'move' description.
board | the board to modify |
move | A Move structure describing the modification. |
DLL_API bool can_move | ( | const unsigned long long | P, |
const unsigned long long | O | ||
) |
Check if a player can move.
P | bitboard with player's discs. |
O | bitboard with opponent's discs. |
bool can_move_6x6 | ( | const unsigned long long | P, |
const unsigned long long | O | ||
) |
Check if a player can move.
P | bitboard with player's discs. |
O | bitboard with opponent's discs. |
void edge_stability_init | ( | void | ) |
Initialize the edge stability tables.
|
static |
search stable edge patterns.
Compute a 8-bit bitboard where each stable square is set to one
old_P | previous player edge discs. |
old_O | previous opponent edge discs. |
stable | 8-bit bitboard with stable edge squares. |
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.
P | bitboard with player's discs. |
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.
P | bitboard with player's discs. |
O | bitboard with opponent's discs. |
|
inlinestatic |
Get full lines.
line | all discs on a line. |
dir | tested direction |
int get_mobility | ( | const unsigned long long | P, |
const unsigned long long | O | ||
) |
Count legal moves.
Compute mobility, ie the number of legal moves.
P | bitboard with player's discs. |
O | bitboard with opponent's discs. |
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.
P | bitboard with player's discs. |
O | bitboard with opponent's discs. |
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.
P | bitboard with player's discs. |
O | bitboard with opponent's discs. |
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.
P | bitboard with player's discs. |
O | bitboard with opponent's discs. |
|
static |
Get potential moves.
Get the list of empty squares in contact of a player square.
P | bitboard with player's discs. |
O | bitboard with opponent's discs. |
|
inlinestatic |
Get a part of the moves.
Partially compute a bitboard where each coordinate with a legal move is set to one.
Two variants of the algorithm are provided, one based on Kogge-Stone parallel prefix.
P | bitboard with player's discs. |
mask | bitboard with flippable opponent's discs. |
dir | flipping direction. |
|
inlinestatic |
Get some potential moves.
P | bitboard with player's discs. |
dir | flipping direction. |
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.
P | bitboard with player's discs. |
O | bitboard with opponent's discs. |
|
inlinestatic |
Get stable edge.
P | bitboard with player's discs. |
O | bitboard with opponent's discs. |
int get_weighted_mobility | ( | const unsigned long long | P, |
const unsigned long long | O | ||
) |
|
static |
conversion from an 8-bit line to the A1-A8 line
|
static |
edge stability global data
|
static |
conversion from an 8-bit line to the H1-H8 line