Board Class Reference

Board representation. More...

#include <board.h>

List of all members.

Public Member Functions

void initNewGame ()
 Public wrapper around init(newGame=true).
bool initFromRecord (const char *fn, bool init_repetitions=false)
 Inits board from a game record in file.
bool initFromPosition (const char *fn)
 Inits board from a position in file.
bool initFromPositionCompactString (const string &s)
 Inits board from compact string.
Step findMCstep ()
 Step generation for Monte Carlo playouts.
void findMCmoveAndMake ()
 Move generation in Monte Carlo playouts.
bool operator== (const Board &board) const
 Equality operator.
void updateThirdRep ()
 Updates third repetition table with actual position.
void makeMove (const string &move)
 Performs whole move.
void makeMove (const Move &move)
 Making whole move.
bool makeStepTryCommit (const Step &)
 Wraper for makeStep with commiting.
void commit ()
 Commits the move.
int filterRepetitions (StepArray &, int) const
 Repetition check.
bool isSetupPhase () const
 Setup pieces phase test.
bool checkKillForward (coord_t from, coord_t to, KillInfo *killInfo=NULL) const
 Forward check.
u64 calcAfterStepSignature (const Step &step) const
 Calculater signature for one step forward.
int genStepsNoPass (player_t, StepArray &steps) const
 Step generation.
int genSteps (player_t, StepArray &steps) const
 Step generation with pass included.
void getHeuristics (const StepArray &steps, uint stepsNum, HeurArray &heurs) const
 Knowledge for steps.
bool canContinue (const Move &move) const
 Continue check.
bool canPass () const
 Can pass test.
Step lastStep () const
 Last step getter.
bool isMoveBeginning () const
 Checks is in the move beginning.
void updateWinner ()
bool goalCheck (player_t player, int stepLimit, Move *move=NULL) const
 Full goal check.
bool goalCheck (Move *move=NULL) const
 Goal check.
bool trapCheck (player_t player, coord_t trap, int limit, MoveList *moves, SoldierList *soldiers) const
 Trap check.
bool trapCheck (player_t player, MoveList *moves=NULL, SoldierList *soldiers=NULL) const
bool trapCheck (coord_t pos, piece_t piece, player_t player, coord_t trap, int limit, int used, Move *move) const
string toString () const
 String representation.
string moveToStringWithKills (const Move &m) const
 Print of move with kills.
u64 getSignature () const
 Signature getter.
player_t getWinner () const
 Winner getter.
player_t gameOver () const
 There is a winner.
player_t getPlayerToMove () const
 Actual player getter.
const Bitboard & getBitboard () const
 Bitboard getter.
player_t getPlayerToMoveAfterStep (const Step &step) const
 Next step's player getter.
uint getStepCount () const
 Step count getter.
uint getStepCountLeft () const
 Steps left.
void * operator new (size_t size)
void operator delete (void *p)

Static Public Member Functions

static string bitboardToString (const Bitboard &bitb)
 Bitboard string representation.

Private Member Functions

int reachability (int from, int to, player_t player, int limit, int used, Move *move) const
 Reachability check.
void genStepsOne (coord_t coord, player_t player, StepArray &steps, int &stepsNum) const
 Step generation for one.
void genStepsOneTuned (coord_t coord, player_t player, piece_t piece, StepArray &steps, int &stepsNum, u64 victims) const
 Push Pull Step generation for one piece.
u64 calcMovable (player_t player) const
 Calculates not frozen mask.
void calcWeaker (player_t player, u64(&weaker)[7]) const
 Calculates weaker pieces.
void setSquare (coord_t, player_t, piece_t)
void delSquare (coord_t, player_t)
void delSquare (coord_t, player_t, piece_t)
piece_t getPiece (coord_t, player_t) const
 Piece getter for coord.
player_t getPlayer (coord_t) const
 Player getter for coord.
int strongerDistance (player_t player, piece_t piece, coord_t coord) const
 Distance of stronger piece.
u64 strongerWithinDistance (player_t player, piece_t piece, coord_t coord, int distance) const
 Check whether there is stronger piece within distance.
int equalDistance (player_t player, piece_t piece, coord_t coord) const
 Distance of equaly strong piece.
player_t strongestPieceOwner (u64 area) const
 Strongest(>) piece owner in area.
player_t strongestPiece (player_t player, u64 area) const
 Strongest player's piece in area.
u64 weaker (player_t player, piece_t piece) const
 Weaker mask getter.
u64 stronger (player_t player, piece_t piece) const
 Stronger mask getter.
void init (bool newGame=false)
 General init - nullifies variables.
void afterPositionLoad ()
 After load from position actions.
player_t sideCharToPlayer (char side) const
 Side character to player.
bool findActiveTrapping (MoveVector &moves)
 Tries to find a trapping move in current position.
void makeSignature ()
 Take (hopefully) unique signature of position - u64 number.
void makeStep (const Step &step)
 Making the step.
Step chooseStepWithKnowledge (StepArray &steps, uint stepsNum) const
 Knowledge integration into steps.
bool stepIsVirtualPass (Step &) const
 Virtual pass check.
bool stepIsThirdRepetition (const Step &) const
 Third repetition check.
u64 getPreMoveSignature () const
 Pre move signature getter.

Private Attributes

Bitboard bitboard_
u64 signature_
 position signature - for hash tables, corectness checks, etc.
u64 preMoveSignature_
 position signature from when the current move started
u64 preStepSignature_
 position signature from when the current step started
Step lastStep_
 Last made step.
uint moveCount_
uint stepCount_
player_t toMove_
player_t winner_

Static Private Attributes

static bool classInit = false
static ThirdRepthirdRep_
static Evaleval_

Friends

class Eval


Detailed Description

Board representation.

One of the pillars of the whole program. Defines mechanisms for:


Member Function Documentation

void Board::afterPositionLoad (  )  [private]

After load from position actions.

Signature gest created.

void Board::calcWeaker ( player_t  player,
u64(&)  weaker[7] 
) const [private]

Calculates weaker pieces.

Parameters:
player Calculation is done for this player.
weaker This array is filled.

bool Board::canContinue ( const Move move  )  const

Continue check.

Parameters:
move to be made from given position.
Returns:
True if after move player can still play ( <4 steps ), otherwise false.

bool Board::canPass (  )  const

Can pass test.

Checks possible 3rd repetitions as well.

bool Board::checkKillForward ( coord_t  from,
coord_t  to,
KillInfo killInfo = NULL 
) const

Forward check.

Checking whether step defined by from, to is causing a kill i.e. suicide, being pushed/pulled to trap, stops protecting piece on the trap. This function causes no board update and is used in class StepWithKills.

Step Board::chooseStepWithKnowledge ( StepArray &  steps,
uint  stepsNum 
) const [private]

Knowledge integration into steps.

Parameters:
steps Generated steps - some is selected from these according to "knowledge".
stepsNum Size of steps.

void Board::commit (  ) 

Commits the move.

Handles switching the sides, updating preMoveSignature.

int Board::equalDistance ( player_t  player,
piece_t  piece,
coord_t  coord 
) const [private]

Distance of equaly strong piece.

BIT_EMPTY if no such piece exists.

int Board::filterRepetitions ( StepArray &  steps,
int  stepsNum 
) const

Repetition check.

Takes step array and filters out illegal moves considering: 1) virtual pass repetition 2) 3 moves same position repetition

bool Board::findActiveTrapping ( MoveVector &  moves  )  [private]

Tries to find a trapping move in current position.

It's only a heuristic used in move generation. Must be very fast (aka desicion tree).

Parameters:
moveVector - Found moves are inserted here.
Returns:
True if found anything, false otherwise.

Step Board::findMCstep (  ) 

Step generation for Monte Carlo playouts.

Generates (random) step with some restrictions ( i.e. no pass in the first step ). Random step is generated either by calling findRandomStep method or ( if the former one is unsuccessfull ) by generating all steps and selecting one in random.

int Board::genStepsNoPass ( player_t  player,
StepArray &  steps 
) const

Step generation.

Generates all (syntatically) legal steps from the position EXCEPT from Pass. Doesn't check 3 - repetitions rule / virtual pass.

void Board::genStepsOne ( coord_t  coord,
player_t  player,
StepArray &  steps,
int &  stepsNum 
) const [private]

Step generation for one.

Wrapper around genStepsOneTuned[PushPull| Single]

void Board::genStepsOneTuned ( coord_t  coord,
player_t  player,
piece_t  piece,
StepArray &  steps,
int &  stepsNum,
u64  victims 
) const [inline, private]

Push Pull Step generation for one piece.

Parameters:
coord Steps are generated for piece at this coord.
player Player to generate steps for.
piece Piece ( for time save).
steps Steps are stored in this array.
stepsnum Size of step array.

void Board::getHeuristics ( const StepArray &  steps,
uint  stepsNum,
HeurArray &  heurs 
) const

Knowledge for steps.

Applies knowledge to given stepArray and fills heuristic array heurs will have the same size as steps.

Parameters:
steps - Given step array for heuristics generation.
stepsNum - Length of steps.

bool Board::goalCheck ( Move move = NULL  )  const

Goal check.

Wrapper around previous with player, stepLimit set according to actual player to move.

bool Board::goalCheck ( player_t  player,
int  stepLimit,
Move move = NULL 
) const

Full goal check.

Done through limited full width search.

void Board::init ( bool  newGame = false  )  [private]

General init - nullifies variables.

Parameters:
newGame true -> inits static variables for new game e.g. -> zobrist table, thirdRepetition table, etc.

bool Board::initFromPosition ( const char *  fn  ) 

Inits board from a position in file.

Wrapper around initFromPositionStream.

bool Board::initFromPositionCompactString ( const string &  s  ) 

Inits board from compact string.

Compact string is in form PLAYER_CHAR [position in lines] e.g.:w [rrr r rrrdd e ED RhMH C mC RRRR c RR]

Returns:
true if initialization went right otherwise false

bool Board::initFromRecord ( const char *  fn,
bool  init_repetitions = false 
)

Inits board from a game record in file.

Returns:
true if initialization went right otherwise false

bool Board::isSetupPhase (  )  const

Setup pieces phase test.

Returns:
True, if it's first move and there are no pieces for player to move, otherwise false.

void Board::makeMove ( const Move move  ) 

Making whole move.

Wrapper around makeMoveNoCommit with commit() added.

void Board::makeMove ( const string &  move  ) 

Performs whole move.

There is no control whether move is legal.

Parameters:
move String representation of the move.

void Board::makeSignature (  )  [private]

Take (hopefully) unique signature of position - u64 number.

Done by XOR-ing signatures for all pieces on the board.

void Board::makeStep ( const Step step  )  [private]

Making the step.

One of the crucial methods in the boardstructure.

Parameters:
step Step to be made (kills are resolved as well).
update If true - board structure is updated (added steps, frozenBoard update).

bool Board::makeStepTryCommit ( const Step step  ) 

Wraper for makeStep with commiting.

Performs makestep on given step. If the move is over it updatesWinner and commits.

Parameters:
step given step
Returns:
true if commited false otherwise

bool Board::operator== ( const Board board  )  const

Equality operator.

Check signatures and moveCount.

int Board::reachability ( int  from,
int  to,
player_t  player,
int  limit,
int  used,
Move move 
) const [private]

Reachability check.

Used in goalCheck.

player_t Board::sideCharToPlayer ( char  side  )  const [private]

Side character to player.

Maps 'w','g' -> gold ; 'b', 's' -> silver.

bool Board::stepIsThirdRepetition ( const Step step  )  const [private]

Third repetition check.

Parameters:
step - expected to be last step in current move
Returns:
true if position after given step leads to a third repetition according to thirdRep object.

bool Board::stepIsVirtualPass ( Step step  )  const [private]

Virtual pass check.

Parameters:
step - expected to be last step in current move
Returns:
true if position after given step is same as in the beginning of the move, otherwise false.

u64 Board::stronger ( player_t  player,
piece_t  piece 
) const [private]

Stronger mask getter.

Analogical to weaker mask getter.

Parameters:
player Target player.
piece Reference piece.
Returns:
Mask of player pieces stronger than reference piece.

int Board::strongerDistance ( player_t  player,
piece_t  piece,
coord_t  coord 
) const [private]

Distance of stronger piece.

BIT_EMPTY if no such piece exists.

u64 Board::strongerWithinDistance ( player_t  player,
piece_t  piece,
coord_t  coord,
int  distance 
) const [private]

Check whether there is stronger piece within distance.

Returns:
returns mask with these pieces.

piece_t Board::strongestPiece ( player_t  player,
u64  area 
) const [private]

Strongest player's piece in area.

Returns:
Strongest piece for given player in area.

player_t Board::strongestPieceOwner ( u64  area  )  const [private]

Strongest(>) piece owner in area.

Returns:
player who's piece is dominant in area, NO_PLAYER if both players have pieces of same power there.

bool Board::trapCheck ( player_t  player,
coord_t  trap,
int  limit,
MoveList *  moves,
SoldierList *  soldiers 
) const

Trap check.

Pruned full width search.

Parameters:
moves - List of moves performing trap kill.
Returns:
True if any trap kill possible, false otherwise.

u64 Board::weaker ( player_t  player,
piece_t  piece 
) const [private]

Weaker mask getter.

Parameters:
player Target player.
piece Reference piece.
Returns:
Mask of player pieces weaker than reference piece.


Member Data Documentation

Last made step.

u64 Board::signature_ [private]

position signature - for hash tables, corectness checks, etc.


The documentation for this class was generated from the following files:

Generated on Thu Aug 6 23:29:08 2009 for akimot by  doxygen 1.5.7.1