Chess Game
1.1.0
A full chess game for Unity
|
The chess board, here moves are generated, checked for legality, performed and reverted. More...
Public Types | |
enum | OUTCOME { Undecided = 0, Draw = 1, BlackWin = 2, WhiteWin = 3 } |
Public Member Functions | |
cgBoard (List< sbyte > positions=null, byte boardWidth=8, byte boardHeight=8, Dictionary< string, cgMoveSet > allHypotheticalMoves=null) | |
Create a new instance of the board. More... | |
void | findAllMoves () |
void | move (cgSimpleMove move) |
Perform the provided move, capturing if necessary. More... | |
bool | longCastlingRights (bool white) |
Does the provided color still have its long castling rights? More... | |
bool | shortCastlingRights (bool white) |
Does the provided color still have its short castling rights? More... | |
void | revert () |
Revert the last performed move. More... | |
cgBoard | revertToStart () |
Revert the board all the way to the start. More... | |
int | Evaluate () |
Evaluate the current board, adding together material values of both sides, positional values, castling values etc. More... | |
bool | verifyLegality (cgSimpleMove testMove) |
Final verification, checks if the kings is attempting to perform a capture that leads to the king being taken next, which is the only illegal move findLegalMoves does not check(because it would be very intensive for the AI to search for this kind of move and also slightly redundant, as such a move leads immediately to loss of king which is the most highly valued piece on the board and thusly would be weighed as a terrible move). More... | |
List< cgSimpleMove > | findLegalMoves (bool asWhite) |
Returns all legal moves for the provided color for the current board. Note: it may return a move in which the king captures an enemy piece to which the enemy can then next capture the king, use findStrictLegalMoves to avoid - however for the engine the computation to verify such a move are too costly. And since such a move immediatly leads to king capture, the AI will once it check the next moves find it to be a very very bad move. More... | |
List< cgSimpleMove > | findStrictLegalMoves (bool asWhite) |
Returns all legal moves for the provided color for the current board. More... | |
string | moveToString (cgSimpleMove move) |
Converts a move to a human readable string. Useful for debugging purposes. More... | |
void | LoadGame (cgNotation notation) |
Generates a board matching the provided notation. More... | |
byte | IndexFromCellName (string p) |
Translates a coordinate string(e3, d1 etc.) to an index(0-64). More... | |
bool | isChecked (bool asWhite) |
Is the color checked? More... | |
string | boardToNeatString () |
Creates a neat human readable string of the current board. Useful for debugging purposes. More... | |
string | boardToString () |
Returns the board as not so neat string, useful for generating a unique string of current board state. More... | |
cgBoard | duplicate () |
Create a new board that is a duplication of this instance. More... | |
void | setDuplicateValues (byte enpassantSquare, byte enPassantCapture, bool whiteToMove, byte whiteARook, byte whiteHRook, byte blackARook, byte blackHRook, byte whiteKing, byte blackKing, byte[] _blackRooksStart, byte[] _whiteRooksStart, byte _blackKingStart, byte _whiteKingStart, byte[] _whiteLeftCastleCrossSquares, byte[] _whiteRightCastleCrossSquares, byte[] _blackLeftCastleCrossSquares, byte[] _blackRightCastleCrossSquares, byte _whiteKingLeftCastleTo, byte _whiteKingRightCastleTo, byte _blackKingLeftCastleTo, byte _blackKingRightCastleTo, byte _whiteRookLeftCastleTo, byte _whiteRookRightCastleTo, byte _blackRookLeftCastleTo, byte _blackRookRightCastleTo) |
Setting all private vars for a new duplicate instance, to match its target. More... | |
Public Attributes | |
List< sbyte > | squares = new List<sbyte>(64) |
The 0-64 index presentation of the board. This is where the magic happends. Below is a detailed list of what values can be expected, and what each index position corresponds to on the board. More... | |
List< cgSimpleMove > | moves = new List<cgSimpleMove>() |
A list of all unreverted moves in chronological order since the start of the game. More... | |
int | moveCount = 0 |
Total number of moves that have been performed(regardless of reverting). More... | |
int | revertCount = 0 |
Total number of reverts that have been performed. More... | |
bool | whiteHasCastled = false |
Has white castled? used to add value on board avaluation. More... | |
bool | blackHasCastled = false |
Has black castled? used to subtract value on board avaluation. More... | |
byte | illegalCellIndex = 65 |
the index at which squares are out of bounds, in other words the index that exceeds the board. More... | |
byte | boardWidth = 8 |
Width of the board. More... | |
byte | boardHeight = 8 |
Height of board More... | |
string [] | SquareNames |
Cell names according to index position. More... | |
Static Public Attributes | |
static List< sbyte > | defaultStartPosition |
The default starting position. More... | |
Properties | |
bool | whiteTurnToMove [get] |
Is it whites turn to move? More... | |
The chess board, here moves are generated, checked for legality, performed and reverted.
cgBoard.cgBoard | ( | List< sbyte > | positions = null , |
byte | boardWidth = 8 , |
||
byte | boardHeight = 8 , |
||
Dictionary< string, cgMoveSet > | allHypotheticalMoves = null |
||
) |
Create a new instance of the board.
positions |
string cgBoard.boardToNeatString | ( | ) |
Creates a neat human readable string of the current board. Useful for debugging purposes.
string cgBoard.boardToString | ( | ) |
Returns the board as not so neat string, useful for generating a unique string of current board state.
cgBoard cgBoard.duplicate | ( | ) |
Create a new board that is a duplication of this instance.
int cgBoard.Evaluate | ( | ) |
Evaluate the current board, adding together material values of both sides, positional values, castling values etc.
List<cgSimpleMove> cgBoard.findLegalMoves | ( | bool | asWhite | ) |
Returns all legal moves for the provided color for the current board. Note: it may return a move in which the king captures an enemy piece to which the enemy can then next capture the king, use findStrictLegalMoves to avoid - however for the engine the computation to verify such a move are too costly. And since such a move immediatly leads to king capture, the AI will once it check the next moves find it to be a very very bad move.
asWhite | Move as white? |
List<cgSimpleMove> cgBoard.findStrictLegalMoves | ( | bool | asWhite | ) |
Returns all legal moves for the provided color for the current board.
asWhite | Move as white? |
byte cgBoard.IndexFromCellName | ( | string | p | ) |
Translates a coordinate string(e3, d1 etc.) to an index(0-64).
p |
bool cgBoard.isChecked | ( | bool | asWhite | ) |
Is the color checked?
asWhite | Should we check if white is checked(true) or if black is checked(false) |
void cgBoard.LoadGame | ( | cgNotation | notation | ) |
Generates a board matching the provided notation.
notation | The notation of the game to be recreated |
bool cgBoard.longCastlingRights | ( | bool | white | ) |
Does the provided color still have its long castling rights?
white | The color whoms castling right should be checked,false=black |
void cgBoard.move | ( | cgSimpleMove | move | ) |
Perform the provided move, capturing if necessary.
move | The move to perform. |
string cgBoard.moveToString | ( | cgSimpleMove | move | ) |
Converts a move to a human readable string. Useful for debugging purposes.
move |
void cgBoard.revert | ( | ) |
Revert the last performed move.
cgBoard cgBoard.revertToStart | ( | ) |
Revert the board all the way to the start.
void cgBoard.setDuplicateValues | ( | byte | enpassantSquare, |
byte | enPassantCapture, | ||
bool | whiteToMove, | ||
byte | whiteARook, | ||
byte | whiteHRook, | ||
byte | blackARook, | ||
byte | blackHRook, | ||
byte | whiteKing, | ||
byte | blackKing, | ||
byte [] | _blackRooksStart, | ||
byte [] | _whiteRooksStart, | ||
byte | _blackKingStart, | ||
byte | _whiteKingStart, | ||
byte [] | _whiteLeftCastleCrossSquares, | ||
byte [] | _whiteRightCastleCrossSquares, | ||
byte [] | _blackLeftCastleCrossSquares, | ||
byte [] | _blackRightCastleCrossSquares, | ||
byte | _whiteKingLeftCastleTo, | ||
byte | _whiteKingRightCastleTo, | ||
byte | _blackKingLeftCastleTo, | ||
byte | _blackKingRightCastleTo, | ||
byte | _whiteRookLeftCastleTo, | ||
byte | _whiteRookRightCastleTo, | ||
byte | _blackRookLeftCastleTo, | ||
byte | _blackRookRightCastleTo | ||
) |
Setting all private vars for a new duplicate instance, to match its target.
bool cgBoard.shortCastlingRights | ( | bool | white | ) |
Does the provided color still have its short castling rights?
white | The color whoms castling right should be checked,false=black |
bool cgBoard.verifyLegality | ( | cgSimpleMove | testMove | ) |
Final verification, checks if the kings is attempting to perform a capture that leads to the king being taken next, which is the only illegal move findLegalMoves does not check(because it would be very intensive for the AI to search for this kind of move and also slightly redundant, as such a move leads immediately to loss of king which is the most highly valued piece on the board and thusly would be weighed as a terrible move).
testMove | The move to be verified |
bool cgBoard.blackHasCastled = false |
Has black castled? used to subtract value on board avaluation.
byte cgBoard.boardHeight = 8 |
Height of board
byte cgBoard.boardWidth = 8 |
Width of the board.
|
static |
The default starting position.
byte cgBoard.illegalCellIndex = 65 |
the index at which squares are out of bounds, in other words the index that exceeds the board.
int cgBoard.moveCount = 0 |
Total number of moves that have been performed(regardless of reverting).
List<cgSimpleMove> cgBoard.moves = new List<cgSimpleMove>() |
A list of all unreverted moves in chronological order since the start of the game.
0 = unoccupied square
1 = white pawn 2 = white rook 3 = white knight 4 = white bishop 5 = white queen 6 = white king
-1 = black pawn -2 = black rook -3 = black knight -4 = black bishop -5 = black queen -6 = black king
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
int cgBoard.revertCount = 0 |
Total number of reverts that have been performed.
string [] cgBoard.SquareNames |
Cell names according to index position.
List<sbyte> cgBoard.squares = new List<sbyte>(64) |
The 0-64 index presentation of the board. This is where the magic happends. Below is a detailed list of what values can be expected, and what each index position corresponds to on the board.
bool cgBoard.whiteHasCastled = false |
Has white castled? used to add value on board avaluation.
|
get |
Is it whites turn to move?