Home - SamChenYu/JavaChessEngine GitHub Wiki
Welcome to the JavaChessEngine wiki!
This project was my attempt at building a chess engine from scratch. At its current state, in the opening, it can compute 270,000 positions per second. In a complex midgame position, it will analyse about 11,000 positions per second. This is due to the fact that having more possible moves will create an exponential increase of positions needed to analyse.
The Game is represented with a long[12] board array that contains bitboards of each type (in progress). It also stores other information such as En Passant, Castling Rights and Move Clocks. The Piece 2D array representation was replaced by the bitboard representation for greater efficiency. It allowed for simple development but added overhead for accessing data.
The following breakdown how the array matches up with a typical chess board, where the rank numbers was aligned to the array indices.
long[] bitboard representation
Each of the long indices represent the following:
[0] w_pawn
[1] w_knight
[2] w_bishop
[3] w_rook
[4] w_queen
[5] w_king
[6] b_pawn
[7] b_knight
[8] b_bishop
[9] b_rook
[10] b_queen
[11] b_king
Typical Chess Board
* Black
[A8][B8][C8][D8][E8][F8][G8][H8]
[A7][B7][C7][D7][E7][F7][G7][H7]
[A6][B6][C6][D6][E6][F6][G6][H6]
[A5][B5][C5][D5][E5][F5][G5][H5]
[A4][B4][C4][D4][E4][F4][G4][H4]
[A3][B3][C3][D3][E3][F3][G3][H3]
[A2][B2][C2][D2][E2][F2][G2][H2]
[A1][B1][C1][D1][E1][F1][G1][H1]
* White
*
Little-Endian File-Rank Mapping
long representation
A1 = 0b1L
A2 = 0b01L
A3 = 0b001L
A4 = 0b00001L
A5 = 0b000001L
A6 = 0b0000001L
A7 = 0b00000001L
A8 = 0b000000001L
B1 = 0b0000000001L
...
H8 = 0b0000000000000000000000000000000000000000000000000000000000000001L
* Black
[ 7][15][23][31][39][47][55][63]
[ 6][14][22][30][38][46][54][62]
[ 5][13][21][29][37][45][53][61]
[ 4][12][20][28][36][44][52][60]
[ 3][11][19][27][35][43][51][59]
[ 2][10][18][26][34][42][50][58]
[ 1][ 9][17][25][33][41][49][57]
[ 0][ 8][16][24][32][40][48][56]
* White
*
Move Generation (White's Perspective)
[-7][+1][+9]
[-8][ x][+8]
[-9][-1][+7]
Piece[][] 2D array representation (deprecated)
ARRAY REFERENCE TABLE
* WHITE
[A1][B1][C1][D1][E1][F1][G1][H1]
[A2][B2][C2][D2][E2][F2][G2][H2]
[A3][B3][C3][D3][E3][F3][G3][H3]
[A4][B4][C4][D4][E4][F4][G4][H4]
[A5][B5][C5][D5][E5][F5][G5][H5]
[A6][B6][C6][D6][E6][F6][G6][H6]
[A7][B7][C7][D7][E7][F7][G7][H7]
[A8][B8][C8][D8][E8][F8][G8][H8]
* BLACK
*
Piece[][] Representation
WHITE
[0,0][1,0][2,0][3,0][4,0][5,0][6,0][7,0]
[0,1][1,1][2,1][3,1][4,1][5,1][6,1][7,1]
[0,2][1,2][2,2][3,2][4,2][5,2][6,2][7,2]
[0,3][1,3][2,3][3,3][4,3][5,3][6,3][7,3]
[0,4][1,4][2,4][3,4][4,4][5,4][6,4][7,4]
[0,5][1,5][2,5][3,5][4,5][5,5][6,5][7,5]
[0,6][1,6][2,6][3,6][4,6][5,6][6,6][7,6]
[0,7][1,7][2,7][3,7][4,7][5,7][6,7][7,7]
BLACK
A File = [0,y] B File = [1,y]
C File = [2,y] D File = [3,y]
E File = [4,y] F File = [5,y]
G File = [6,y] H File = [7,y]
1st Rank = [x,0] 2nd Rank = [x,1]
3rd Rank = [x,2] 4th Rank = [x,3]
5th Rank = [x,4] 6th Rank = [x,5]
7th Rank = [x,6] 8th Rank = [x,7]