public void Initialize() { g_hash = RAND_32(); for (int n = 0; n < undoStack.Length; n++) { undoStack[n] = new CUndo(); } for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { arrField[y * 8 + x] = (y + 4) * 16 + x + 4; } } for (int n = 0; n < 256; n++) { boardCheck[n] = 0; boardCastle[n] = 15; g_board[n] = 0; for (int p = 0; p < 16; p++) { g_hashBoard[n, p] = RAND_32(); } } int[] arrCastleI = { 68, 72, 75, 180, 184, 187 }; int[] arrCasteleV = { 7, 3, 11, 13, 12, 14 }; int[] arrCheckI = { 71, 72, 73, 183, 184, 185 }; int[] arrCheckV = { colorBlack | moveflagCastleQueen, colorBlack | maskCastle, colorBlack | moveflagCastleKing, colorWhite | moveflagCastleQueen, colorWhite | maskCastle, colorWhite | moveflagCastleKing }; for (int n = 0; n < 6; n++) { boardCastle[arrCastleI[n]] = arrCasteleV[n]; boardCheck[arrCheckI[n]] = arrCheckV[n]; } }
public void UnmakeMove(int move) { int fr = move & 0xFF; int to = (move >> 8) & 0xFF; int flags = move & 0xFF0000; int capi = to; CUndo undo = undoStack[--undoIndex]; g_passing = undo.passing; g_castleRights = undo.castle; g_move50 = undo.move50; g_lastCastle = undo.lastCastle; g_hash = undo.hash; int captured = undo.captured; if ((flags & moveflagCastleKing) > 0) { g_board[to + 1] = g_board[to - 1]; g_board[to - 1] = colorEmpty; } else if ((flags & moveflagCastleQueen) > 0) { g_board[to - 2] = g_board[to + 1]; g_board[to + 1] = colorEmpty; } if ((flags & moveflagPromotion) > 0) { int piece = (g_board[to] & (~0x7)) | piecePawn; g_board[fr] = piece; } else { g_board[fr] = g_board[to]; } if ((flags & moveflagPassing) > 0) { capi = whiteTurn ? to - 16 : to + 16; g_board[to] = colorEmpty; } g_board[capi] = captured; whiteTurn ^= true; g_moveNumber--; }
public void MakeMove(int emo) { CUndo undo = undoStack[undoIndex++]; undo.hash = g_hash; undo.passing = g_passing; undo.castle = g_castleRights; undo.move50 = g_move50; undo.lastCastle = g_lastCastle; int fr = emo & 0xff; int to = (emo >> 8) & 0xff; int flags = emo & 0xFF0000; int piecefr = g_board[fr]; int piece = piecefr & 0xf; int captured = g_board[to]; g_lastCastle = (emo & maskCastle) | (piecefr & maskColor); if ((flags & moveflagCastleKing) > 0) { g_board[to - 1] = g_board[to + 1]; g_board[to + 1] = colorEmpty; } else if ((flags & moveflagCastleQueen) > 0) { g_board[to + 1] = g_board[to - 2]; g_board[to - 2] = colorEmpty; } else if ((flags & moveflagPassing) > 0) { int capi = whiteTurn ? to + 16 : to - 16; captured = g_board[capi]; g_board[capi] = colorEmpty; } undo.captured = captured; g_hash ^= g_hashBoard[fr, piece]; g_passing = 0; if ((captured & 0xF) > 0) { g_move50 = 0; } else if ((piece & 7) == piecePawn) { if (to == (fr + 32)) { g_passing = (fr + 16); } if (to == (fr - 32)) { g_passing = (fr - 16); } g_move50 = 0; } else { g_move50++; } if ((flags & moveflagPromotion) > 0) { int newPiece = piecefr & (~0x7); if ((flags & moveflagPromoteKnight) > 0) { newPiece |= pieceKnight; } else if ((flags & moveflagPromoteQueen) > 0) { newPiece |= pieceQueen; } else if ((flags & moveflagPromoteBishop) > 0) { newPiece |= pieceBishop; } else { newPiece |= pieceRook; } g_board[to] = newPiece; g_hash ^= g_hashBoard[to, newPiece & 0xf]; } else { g_board[to] = g_board[fr]; g_hash ^= g_hashBoard[to, piece]; } g_board[fr] = colorEmpty; g_castleRights &= boardCastle[fr] & boardCastle[to]; whiteTurn ^= true; g_moveNumber++; }