Chess API

View on GitHub

Useful tools

Creating tests - http://www.apronus.com/chess/wbeditor.php Allows you to setup a position and get the FEN from it.

Base.h

Color

Color opposite(Color c)

Return the opposite color.

Piece

char letter(Piece p)

Return space (empty) or one of PNBRQK.

Square

Square toSquare(File f, Rank r)

Return Square of file f and rank r.

File getFile(Square s)
Rank getRank(Square s)
int fileDist(Square s1, s2)
int rankDist(Square s1, s2)
int dist(Square s1, s2)

Return the file, rank, and max of (file,rank) distance between squares s1 and s2..

Score

enum minScore = -131072
draw = 0
pawnValue = 1000
mate = 130000
illegal = 130100
maxScore = +131072

Bitboard.h

Bitboard b &,|,^,~,<<,>>, ==
b &= someBB
b = b & someBB

Square firstBit(Bitboard b)

Returns the first 'on' bit in the Bitboard. Used repeatedly to find all the 'on' bits i.e. to locate pieces of type X on bitboard for pieces of type X.

int popCount(Bitboard b)

Returns the number of 'on' bits in the Bitboard i.e. number of pieces of type X

void clear(Bitboard& b, Square s)
void set(Bitboard& b, Square s)

Clear/set square S on bitboard b.

evaluate.h

Score evaluate(const Position& pos);

Return a score for the position including material and piece positions.

Move.h

Move class methods

Square from()
Square to()
Piece piece()
Piece capture()
Piece promote()

Return data associated with the Move.

Moves.h

void generateMoves(const Position& pos, Moves& moves);

Save generated moves into moves. Includes illegal moves.

void generateNonQuietMoves(const Position& pos, Moves& moves);

Save generated moves into moves. Includes only captures. (Could be illegal still)

Square rotate45Left(Square s);
Square rotate45Right(Square s);
Square rotate90Left(Square s);

Rotate a square to match a rotated bitboard.

bool isAttacking(Color color, Square s, const Position& pos);

Return true if Color color is attacking square S in position pos.

Score SEE(const Position &pos, Move move);

Return a score based on the result of move in terms of captures & exchanges

Position.h

Position class methods

void makeMove(Move m);
void unMakeMove(Move m);
void makeNullMove();
void unMakeNullMove();

Make/unmake a move (or null move for optimizations)

void setupFEN(std::string FEN);
std::string getFEN() const;

Set and return string representations of the board.

ColoredPiece position[square s]

Returns the piece and square s

BitBoard bitboard(Color c, Piece p) const
BitBoard occupied(Color c) const
BitBoard occupied() const
BitBoard nonOccupied() const
BitBoard occupiedRotate45Left() const
BitBoard occupiedRotate45Right() const
BitBoard occupiedRotate90Left() const

Return various bitboards of certain colors/pieces or rotated/occupied versions.

Color turn()
Square epSquare()
CastlingRight castlingRight(Color c)
Score material(Color c)
bool inCheck(Color color, const Position& pos)

Return game details such as color, en passant square, castling rights.