public void BlackBishopMoved2SW_Undo_Test() { ChessBoard testBoard = new ChessBoard(); testBoard.InitializeGame(); PawnBitBoard movePawn = new PawnBitBoard(ChessPieceColors.Black); PawnBitBoard moveWhitePawn = new PawnBitBoard(ChessPieceColors.White); movePawn.Bits = (testBoard.BlackPawn.Bits ^ BoardSquare.B7) | BoardSquare.B6; ulong expectedHash = testBoard.BoardHash.Key; testBoard.Update(movePawn); testBoard.Undo(); ulong actualHash = testBoard.BoardHash.Key; Assert.Equal(expectedHash, actualHash); testBoard.Update(movePawn); moveWhitePawn.Bits = (testBoard.WhitePawn.Bits ^ BoardSquare.H2) | BoardSquare.H3; expectedHash = testBoard.BoardHash.Key; testBoard.Update(moveWhitePawn); testBoard.Undo(); actualHash = testBoard.BoardHash.Key; Assert.Equal(expectedHash, actualHash); testBoard.Update(moveWhitePawn); BishopBitBoard moveBishop = new BishopBitBoard(ChessPieceColors.Black); moveBishop.Bits = (testBoard.BlackBishop.Bits ^ BoardSquare.C8) | BoardSquare.A6; expectedHash = testBoard.BoardHash.Key; testBoard.Update(moveBishop); testBoard.Undo(); actualHash = testBoard.BoardHash.Key; Assert.Equal(expectedHash, actualHash); }
public void BestMoveTest_WhiteDepth2() { ChessBoard input = new ChessBoard(); input.InitializeScenario(new ScenarioList { { BoardSquare.C2, ChessPieceType.Pawn, ChessPieceColors.White }, { BoardSquare.B3, ChessPieceType.Pawn, ChessPieceColors.Black }, { BoardSquare.H1, ChessPieceType.King, ChessPieceColors.White }, { BoardSquare.B4, ChessPieceType.King, ChessPieceColors.Black }, { BoardSquare.D3, ChessPieceType.Pawn, ChessPieceColors.Black } }); //Used for depth 2 bool depth2MoveEqual = false; ColoredBitBoard depth2Test = NegaMax.GetBestMove(input, 2, ChessPieceColors.White, GenerateStaticMoves_Depth12, GetStaticMaterialValueDepth2_White); PawnBitBoard optimalMove = new PawnBitBoard(ChessPieceColors.White); optimalMove.Bits = BoardSquare.D3; if (depth2Test is PawnBitBoard) { depth2Test = (PawnBitBoard)depth2Test; if (depth2Test.Bits == optimalMove.Bits) { depth2MoveEqual = true; } } Assert.True(depth2MoveEqual); }
public void TestUpRightAttacks() { string boardString = "00000000" + "00000000" + "00000000" + "00000000" + "00000000" + "10000010" + "00101000" + "00000000"; var board = new PawnBitBoard(BitBoardHelper.FromString(boardString)); string moves = "00000000" + "00000000" + "00000000" + "00000000" + "01000001" + "00010100" + "00000000" + "00000000"; ulong movesBoard = BitBoardHelper.FromString(moves); ulong emptySquares = 0; emptySquares = ~emptySquares; var attacks = board.NorthEastAttacks(); Assert.AreEqual(movesBoard, attacks); }
public void Undo_BlackPawnRank2Forward2_Equal() { ChessBoard testBoard = new ChessBoard(); testBoard.InitializeGame(); PawnBitBoard move0 = new PawnBitBoard(ChessPieceColors.White); PawnBitBoard move1 = new PawnBitBoard(ChessPieceColors.Black); PawnBitBoard move2 = new PawnBitBoard(ChessPieceColors.White); PawnBitBoard move3 = new PawnBitBoard(ChessPieceColors.Black); PawnBitBoard move4 = new PawnBitBoard(ChessPieceColors.White); PawnBitBoard move5 = new PawnBitBoard(ChessPieceColors.Black); move0.Bits = testBoard.WhitePawn.Bits ^ BoardSquare.E2 ^ BoardSquare.E4; move1.Bits = testBoard.BlackPawn.Bits ^ BoardSquare.C7 ^ BoardSquare.C5; move2.Bits = move0.Bits ^ BoardSquare.F2 ^ BoardSquare.F3; move3.Bits = move1.Bits ^ BoardSquare.E7 ^ BoardSquare.E5; move4.Bits = move2.Bits ^ BoardSquare.A2 ^ BoardSquare.A4; move5.Bits = move3.Bits ^ BoardSquare.H7 ^ BoardSquare.H5; testBoard.Update(move0); testBoard.Update(move1); testBoard.Update(move2); testBoard.Update(move3); testBoard.Update(move4); ulong hashbefore = testBoard.BoardHash.Key; testBoard.Update(move5); testBoard.Undo(); ulong actualKey = testBoard.BoardHash.Key; Assert.Equal(hashbefore, actualKey); }
public void Undo_WhitePawnCapture_Equal() { ChessBoard testBoard = new ChessBoard(); testBoard.InitializeGame(); PawnBitBoard move1 = new PawnBitBoard(ChessPieceColors.White); move1.Bits = (testBoard.WhitePawn.Bits ^ BoardSquare.H2) | BoardSquare.H4; PawnBitBoard move2 = new PawnBitBoard(ChessPieceColors.Black); move2.Bits = (testBoard.BlackPawn.Bits ^ BoardSquare.G7) | BoardSquare.G5; PawnBitBoard move3 = new PawnBitBoard(ChessPieceColors.White); move3.Bits = (move1.Bits ^ BoardSquare.H4) | BoardSquare.G5; testBoard.Update(move1); testBoard.Update(move2); ulong expectedHash = testBoard.BoardHash.Key; testBoard.Update(move3); testBoard.Undo(); ulong testHash = testBoard.BoardHash.Key; Assert.Equal(expectedHash, testHash); }
public void TestDoubleUpPush() { string boardString = "00000000" + "00000000" + "00000000" + "00000000" + "00000000" + "10000010" + "00101000" + "00000000"; var board = new PawnBitBoard(BitBoardHelper.FromString(boardString)); string moves = "00000000" + "00000000" + "00000000" + "00000000" + "00101000" + "00000000" + "00000000" + "00000000"; ulong movesBoard = BitBoardHelper.FromString(moves); ulong emptySquares = 0; emptySquares = ~emptySquares; var attacks = board.DoubleUpPushTargets(emptySquares); Assert.AreEqual(movesBoard, attacks); }
public static List <ColoredBitBoard> GenerateStaticMoves_Black_Depth1(ChessBoard board, ChessPieceColors color) { List <ColoredBitBoard> legalMoves = new List <ColoredBitBoard>(); //Black king moves KingBitBoard move1 = new KingBitBoard(ChessPieceColors.Black); KingBitBoard move2 = new KingBitBoard(ChessPieceColors.Black); KingBitBoard move3 = new KingBitBoard(ChessPieceColors.Black); KingBitBoard move4 = new KingBitBoard(ChessPieceColors.Black); KingBitBoard move5 = new KingBitBoard(ChessPieceColors.Black); KingBitBoard move6 = new KingBitBoard(ChessPieceColors.Black); KingBitBoard move7 = new KingBitBoard(ChessPieceColors.Black); move1.Bits = BoardSquare.A3; move2.Bits = BoardSquare.C3; move3.Bits = BoardSquare.A4; move4.Bits = BoardSquare.C4; move5.Bits = BoardSquare.A5; move6.Bits = BoardSquare.B5; move7.Bits = BoardSquare.C5; //Black Pawn moves, pawn at B3 PawnBitBoard pawnEnd11 = new PawnBitBoard(ChessPieceColors.Black); PawnBitBoard pawnEnd12 = new PawnBitBoard(ChessPieceColors.Black); PawnBitBoard move8 = new PawnBitBoard(ChessPieceColors.Black); PawnBitBoard move9 = new PawnBitBoard(ChessPieceColors.Black); pawnEnd11.Bits = BoardSquare.B2; pawnEnd12.Bits = BoardSquare.C2; move8.Bits = (board.BlackPawn.Bits ^ BoardSquare.B3) | pawnEnd11.Bits; move9.Bits = (board.BlackPawn.Bits ^ BoardSquare.B3) | pawnEnd12.Bits; //Pawn at D3 PawnBitBoard pawnEnd21 = new PawnBitBoard(ChessPieceColors.Black); PawnBitBoard pawnEnd22 = new PawnBitBoard(ChessPieceColors.Black); PawnBitBoard move10 = new PawnBitBoard(ChessPieceColors.Black); PawnBitBoard move11 = new PawnBitBoard(ChessPieceColors.Black); pawnEnd21.Bits = BoardSquare.C2; pawnEnd22.Bits = BoardSquare.D2; move10.Bits = (board.BlackPawn.Bits ^ BoardSquare.D3) | pawnEnd21.Bits; move11.Bits = (board.BlackPawn.Bits ^ BoardSquare.D3) | pawnEnd22.Bits; legalMoves.Add(move1); legalMoves.Add(move2); legalMoves.Add(move3); legalMoves.Add(move4); legalMoves.Add(move5); legalMoves.Add(move6); legalMoves.Add(move7); legalMoves.Add(move8); legalMoves.Add(move9); legalMoves.Add(move10); legalMoves.Add(move11); return(legalMoves); }
public void Initialize_IsBlackCorrectPlaced_Equal() { ulong correctPlacement = 0x00FF000000000000; PawnBitBoard board = new PawnBitBoard(ChessPieceColors.Black); board.Initialize(null); Assert.Equal(correctPlacement, (ulong)board.Bits); }
public void SplitBitboard_IfCountZero_Equal() { PawnBitBoard bb = new PawnBitBoard(ChessPieceColors.Black); bb.Bits = 0x0; PawnBitBoard[] bbArr = new PawnBitBoard[0]; Assert.Equal(bbArr, ColoredBitBoard.SplitBitBoard(bb)); }
public void Undo_WhiteKingRankBackward_Equal() { ChessBoard testBoard = new ChessBoard(); testBoard.InitializeGame(); PawnBitBoard move1 = new PawnBitBoard(ChessPieceColors.White); move1.Bits = (testBoard.WhitePawn.Bits ^ BoardSquare.E2) | BoardSquare.E3; PawnBitBoard move2 = new PawnBitBoard(ChessPieceColors.Black); move2.Bits = (testBoard.BlackPawn.Bits ^ BoardSquare.A7) | BoardSquare.A6; KingBitBoard move3 = new KingBitBoard(ChessPieceColors.White); move3.Bits = (testBoard.WhiteKing.Bits ^ BoardSquare.E1) | BoardSquare.E2; PawnBitBoard move4 = new PawnBitBoard(ChessPieceColors.Black); move4.Bits = (move2.Bits ^ BoardSquare.A6) | BoardSquare.A5; KingBitBoard move5 = new KingBitBoard(ChessPieceColors.White); move5.Bits = (move3.Bits ^ BoardSquare.E2) | BoardSquare.E1; ulong expectedHash = testBoard.BoardHash.Key; testBoard.Update(move1); testBoard.Undo(); Assert.Equal(expectedHash, testBoard.BoardHash.Key); testBoard.Update(move1); expectedHash = testBoard.BoardHash.Key; testBoard.Update(move2); testBoard.Undo(); Assert.Equal(expectedHash, testBoard.BoardHash.Key); testBoard.Update(move2); expectedHash = testBoard.BoardHash.Key; testBoard.Update(move3); testBoard.Undo(); Assert.Equal(expectedHash, testBoard.BoardHash.Key); testBoard.Update(move3); expectedHash = testBoard.BoardHash.Key; testBoard.Update(move4); testBoard.Undo(); Assert.Equal(expectedHash, testBoard.BoardHash.Key); testBoard.Update(move4); expectedHash = testBoard.BoardHash.Key; testBoard.Update(move5); testBoard.Undo(); ulong testHash = testBoard.BoardHash.Key; Assert.Equal(expectedHash, testHash); }
public void Equals_ColoredBitBoardNotEqual_True() { PawnBitBoard pawn1 = new PawnBitBoard(ChessPieceColors.White); pawn1.Bits = BoardSquare.E5; PawnBitBoard pawn = new PawnBitBoard(ChessPieceColors.Black); pawn.Bits = BoardSquare.E5; Assert.False(pawn1.Equals(pawn)); }
public void Equals_BitBoardEqual_True() { PawnBitBoard pawn1 = new PawnBitBoard(ChessPieceColors.White); pawn1.Bits = BoardSquare.E5; PawnBitBoard pawn = new PawnBitBoard(ChessPieceColors.White); pawn.Bits = BoardSquare.E5; Assert.True(pawn1.Equals(pawn)); }
public void Equals_BitBoardNotEqual_True() { KingBitBoard king = new KingBitBoard(ChessPieceColors.White); king.Bits = BoardSquare.E5; PawnBitBoard pawn = new PawnBitBoard(ChessPieceColors.White); pawn.Bits = BoardSquare.E5; Assert.False(king.Equals(pawn)); }
public void WhiteBishopMoved2SE_Undo_Test() { ChessBoard testBoard = new ChessBoard(); testBoard.InitializeGame(); PawnBitBoard movePawn = new PawnBitBoard(ChessPieceColors.White); movePawn.Bits = (testBoard.WhitePawn.Bits ^ BoardSquare.B2) | BoardSquare.B3; PawnBitBoard moveBlackPawn1 = new PawnBitBoard(ChessPieceColors.Black); ulong expectedHash = testBoard.BoardHash.Key; testBoard.Update(movePawn); testBoard.Undo(); ulong actualHash = testBoard.BoardHash.Key; Assert.Equal(expectedHash, actualHash); testBoard.Update(movePawn); moveBlackPawn1.Bits = (testBoard.BlackPawn.Bits ^ BoardSquare.H7) | BoardSquare.H6; expectedHash = testBoard.BoardHash.Key; testBoard.Update(moveBlackPawn1); testBoard.Undo(); actualHash = testBoard.BoardHash.Key; Assert.Equal(expectedHash, actualHash); testBoard.Update(moveBlackPawn1); BishopBitBoard moveBishop1 = new BishopBitBoard(ChessPieceColors.White); moveBishop1.Bits = (testBoard.WhiteBishop.Bits ^ BoardSquare.C1) | BoardSquare.A3; expectedHash = testBoard.BoardHash.Key; testBoard.Update(moveBishop1); testBoard.Undo(); actualHash = testBoard.BoardHash.Key; Assert.Equal(expectedHash, actualHash); testBoard.Update(moveBishop1); moveBlackPawn1.Bits = (testBoard.BlackPawn.Bits ^ BoardSquare.H6) | BoardSquare.H5; expectedHash = testBoard.BoardHash.Key; testBoard.Update(moveBlackPawn1); testBoard.Undo(); actualHash = testBoard.BoardHash.Key; Assert.Equal(expectedHash, actualHash); testBoard.Update(moveBlackPawn1); BishopBitBoard moveBishop2 = new BishopBitBoard(ChessPieceColors.White); moveBishop2.Bits = (moveBishop1.Bits ^ BoardSquare.A3) | BoardSquare.C1; expectedHash = testBoard.BoardHash.Key; testBoard.Update(moveBishop2); testBoard.Undo(); actualHash = testBoard.BoardHash.Key; Assert.Equal(expectedHash, actualHash); }
public void Handler_IsMoveHandledCorrectly_Equal() { Winboard winboard = new Winboard(); winboard.Handler("new"); winboard.Handler("e2e4"); PawnBitBoard correctWhitePawnPlacement = new PawnBitBoard(ChessPieceColors.White); correctWhitePawnPlacement.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E4 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H2; Assert.Equal(correctWhitePawnPlacement.Bits, winboard.chessBoard.WhitePawn.Bits); }
public void Bits_BlackMovedTwoSquaresOneMove_Equal() { BoardSquare correct = BoardSquare.H5; PawnBitBoard board = new PawnBitBoard(ChessPieceColors.Black); board.Initialize(null); /* "Perform" move, triggers the Bits property on pawnbitboard that sets the MovedTwoSquares */ board.Bits = BoardSquare.A7 | BoardSquare.B7 | BoardSquare.C7 | BoardSquare.D7 | BoardSquare.E7 | BoardSquare.F7 | BoardSquare.G7 | BoardSquare.H5; Assert.Equal(correct, board.MovedTwoSquares); }
public void Bits_WhiteMovedTwoSquaresOneMove_Equal() { BoardSquare correct = BoardSquare.H4; PawnBitBoard board = new PawnBitBoard(ChessPieceColors.White); board.Initialize(null); /* "Perform" move, triggers the Bits property on pawnbitboard that sets the MovedTwoSquares */ board.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E2 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H4; Assert.Equal(correct, board.MovedTwoSquares); }
public void Undo_WhiteKnightCapture_Equal() { ChessBoard testBoard = new ChessBoard(); testBoard.InitializeGame(); KnightBitBoard move1 = new KnightBitBoard(ChessPieceColors.White); move1.Bits = (testBoard.WhiteKnight.Bits ^ BoardSquare.G1) | BoardSquare.F3; PawnBitBoard move2 = new PawnBitBoard(ChessPieceColors.Black); move2.Bits = (testBoard.BlackPawn.Bits ^ BoardSquare.B7) | BoardSquare.B6; KnightBitBoard move3 = new KnightBitBoard(ChessPieceColors.White); move3.Bits = (move1.Bits ^ BoardSquare.F3) | BoardSquare.G5; PawnBitBoard move4 = new PawnBitBoard(ChessPieceColors.Black); move4.Bits = (move2.Bits ^ BoardSquare.B6) | BoardSquare.B5; KnightBitBoard move5 = new KnightBitBoard(ChessPieceColors.White); move5.Bits = (move3.Bits ^ BoardSquare.G5) | BoardSquare.F7; ulong expectedHash = testBoard.BoardHash.Key; testBoard.Update(move1); testBoard.Undo(); Assert.Equal(expectedHash, testBoard.BoardHash.Key); testBoard.Update(move1); expectedHash = testBoard.BoardHash.Key; testBoard.Update(move2); testBoard.Undo(); Assert.Equal(expectedHash, testBoard.BoardHash.Key); testBoard.Update(move2); expectedHash = testBoard.BoardHash.Key; testBoard.Update(move3); testBoard.Undo(); Assert.Equal(expectedHash, testBoard.BoardHash.Key); testBoard.Update(move3); expectedHash = testBoard.BoardHash.Key; testBoard.Update(move4); testBoard.Undo(); Assert.Equal(expectedHash, testBoard.BoardHash.Key); testBoard.Update(move4); expectedHash = testBoard.BoardHash.Key; testBoard.Update(move5); testBoard.Undo(); ulong testHash = testBoard.BoardHash.Key; Assert.Equal(expectedHash, testHash); }
public static List <ColoredBitBoard> GenerateStaticMoves_Depth12(ChessBoard board, ChessPieceColors color) { List <ColoredBitBoard> legalMoves = new List <ColoredBitBoard>(); if (color == ChessPieceColors.Black) { if (board.WhitePawn.Bits == BoardSquare.B3) { PawnBitBoard move1 = new PawnBitBoard(ChessPieceColors.Black); move1.Bits = (board.BlackPawn.Bits ^ BoardSquare.D3) | BoardSquare.D2; KingBitBoard move2 = new KingBitBoard(ChessPieceColors.Black); move2.Bits = BoardSquare.B3; legalMoves.Add(move1); legalMoves.Add(move2); } else if (board.WhitePawn.Bits == BoardSquare.D3) { PawnBitBoard move3 = new PawnBitBoard(ChessPieceColors.Black); move3.Bits = (board.BlackPawn.Bits ^ BoardSquare.B3) | BoardSquare.B2; KingBitBoard move4 = new KingBitBoard(ChessPieceColors.Black); move4.Bits = BoardSquare.A3; legalMoves.Add(move3); legalMoves.Add(move4); } else if (board.WhitePawn.Bits == BoardSquare.C3) { KingBitBoard move8 = new KingBitBoard(ChessPieceColors.Black); move8.Bits = BoardSquare.C3; KingBitBoard move9 = new KingBitBoard(ChessPieceColors.Black); move9.Bits = BoardSquare.C4; legalMoves.Add(move8); legalMoves.Add(move9); } } else if (color == ChessPieceColors.White) { PawnBitBoard move5 = new PawnBitBoard(ChessPieceColors.White); move5.Bits = (board.WhitePawn.Bits ^ BoardSquare.C2) | BoardSquare.B3; PawnBitBoard move6 = new PawnBitBoard(ChessPieceColors.White); move6.Bits = (board.WhitePawn.Bits ^ BoardSquare.C2) | BoardSquare.D3; PawnBitBoard move7 = new PawnBitBoard(ChessPieceColors.White); move7.Bits = (board.WhitePawn.Bits ^ BoardSquare.C2) | BoardSquare.C3; legalMoves.Add(move5); legalMoves.Add(move6); legalMoves.Add(move7); } return(legalMoves); }
private static PawnBitBoard ComputeWhitePawn(PawnBitBoard inputPawnBB, ChessBoard inputChessBoard, BitBoard blackPieces, BitBoard whitePieces, BitBoard allPieces) { PawnBitBoard result = new PawnBitBoard(ChessPieceColors.White); //moves PawnBitBoard pawnOneStep = new PawnBitBoard(ChessPieceColors.White); pawnOneStep.Bits = (BoardSquare)((ulong)inputPawnBB.Bits << 8) & ~allPieces.Bits; PawnBitBoard pawnTwoSteps = new PawnBitBoard(ChessPieceColors.White); if (((ulong)inputPawnBB.Bits & MoveGenUtils.RANK_2) != 0) { pawnTwoSteps.Bits = (BoardSquare)((ulong)pawnOneStep.Bits << 8) & ~allPieces.Bits; } //attacks PawnBitBoard enPassantBB = new PawnBitBoard(ChessPieceColors.White); PawnBitBoard pawnLeftAttack = new PawnBitBoard(ChessPieceColors.White); PawnBitBoard pawnRightAttack = new PawnBitBoard(ChessPieceColors.White); EmptyBitBoard pawnClipFILE_A = new EmptyBitBoard(); EmptyBitBoard pawnClipFILE_H = new EmptyBitBoard(); pawnClipFILE_A.Bits = (BoardSquare)((ulong)inputPawnBB.Bits & ~MoveGenUtils.FILE_A); pawnClipFILE_H.Bits = (BoardSquare)((ulong)inputPawnBB.Bits & ~MoveGenUtils.FILE_H); pawnLeftAttack.Bits = (BoardSquare)(((ulong)pawnClipFILE_A.Bits << 9) & (ulong)blackPieces.Bits); pawnRightAttack.Bits = (BoardSquare)(((ulong)pawnClipFILE_H.Bits << 7) & (ulong)blackPieces.Bits); //enPassantBB = PawnBitBoard.EnPassant(); if (inputChessBoard.BlackPawn.MovedTwoSquares != BoardSquare.Empty) { BoardSquare enemyPawn = new BoardSquare(); enemyPawn = inputChessBoard.BlackPawn.MovedTwoSquares; if ((((ulong)inputPawnBB.Bits << 1) == (ulong)enemyPawn) && (((ulong)enemyPawn & MoveGenUtils.FILE_H) == 0)) { enPassantBB.Bits = (BoardSquare)((ulong)inputPawnBB.Bits << 9); } if ((((ulong)inputPawnBB.Bits >> 1) == (ulong)enemyPawn) && (((ulong)enemyPawn & MoveGenUtils.FILE_A) == 0)) { enPassantBB.Bits = (BoardSquare)((ulong)inputPawnBB.Bits << 7); } } result.Bits = pawnOneStep.Bits | pawnTwoSteps.Bits | pawnLeftAttack.Bits | pawnRightAttack.Bits | enPassantBB.Bits; return(result); }
public void BestMoveTest_BlackDepth1() { ChessBoard input = new ChessBoard(); input.InitializeScenario(new ScenarioList { { BoardSquare.C2, ChessPieceType.Pawn, ChessPieceColors.White }, { BoardSquare.B3, ChessPieceType.Pawn, ChessPieceColors.Black }, { BoardSquare.H1, ChessPieceType.King, ChessPieceColors.White }, { BoardSquare.B4, ChessPieceType.King, ChessPieceColors.Black }, { BoardSquare.D3, ChessPieceType.Pawn, ChessPieceColors.Black } }); PawnBitBoard bestMoveBlack1 = new PawnBitBoard(ChessPieceColors.Black); bestMoveBlack1.Bits = (input.BlackPawn.Bits ^ BoardSquare.D3) | BoardSquare.C2 | BoardSquare.B3; PawnBitBoard bestMoveBlack2 = new PawnBitBoard(ChessPieceColors.Black); bestMoveBlack2.Bits = (input.BlackPawn.Bits ^ BoardSquare.B3) | BoardSquare.C2 | BoardSquare.D3; Tuple <BitBoard, int> outputTuple_Black1 = new Tuple <BitBoard, int>(bestMoveBlack1, -1); Tuple <BitBoard, int> outputTuple_Black2 = new Tuple <BitBoard, int>(bestMoveBlack2, -1); BitBoard blackBoard1 = outputTuple_Black1.Item1; BitBoard blackBoard2 = outputTuple_Black2.Item1; int blackVal = outputTuple_Black1.Item2; //ÆNDRE TEST HER! BitBoard testTuple_Black = NegaMax.GetBestMove(input, 1, ChessPieceColors.Black, GenerateStaticMoves_Black_Depth1, Eval.EvaluateState); int blackVal_Test = outputTuple_Black1.Item2; bool blackBoardEqual = false; bool blackBoardValEqual = false; //Black test comparison if (blackVal == blackVal_Test) { blackBoardValEqual = true; } if (testTuple_Black is PawnBitBoard) { if (testTuple_Black.Bits == blackBoard1.Bits | testTuple_Black.Bits == blackBoard2.Bits) { blackBoardEqual = true; } } Assert.True(blackBoardValEqual && blackBoardEqual); }
public void ConvertBitBoardMoveToString_IsCorrectPromotionKnightStringReturned_Equals() { ChessBoard chessBoard = new ChessBoard(); chessBoard.WhitePawn.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E7 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H2; PawnBitBoard toCoordinate = new PawnBitBoard(ChessPieceColors.White); toCoordinate.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E8 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H2; toCoordinate.Promote(PawnBitBoard.PromotionPiece.Knight); string correctMoveString = "e7e8n"; StringBitboardConverter converter = new StringBitboardConverter(chessBoard, ChessPieceColors.White); Assert.Equal(correctMoveString, converter.ConvertBitBoardMoveToString(toCoordinate)); }
public void BestMoveTest_WhiteDepth1() { ChessBoard input = new ChessBoard(); input.InitializeScenario(new ScenarioList { { BoardSquare.C2, ChessPieceType.Pawn, ChessPieceColors.White }, { BoardSquare.B3, ChessPieceType.Pawn, ChessPieceColors.Black }, { BoardSquare.H1, ChessPieceType.King, ChessPieceColors.White }, { BoardSquare.B4, ChessPieceType.King, ChessPieceColors.Black }, { BoardSquare.D3, ChessPieceType.Pawn, ChessPieceColors.Black } }); //Used for Depth 1 PawnBitBoard bestMoveWhite1 = new PawnBitBoard(ChessPieceColors.White); bestMoveWhite1.Bits = BoardSquare.B3; PawnBitBoard bestMoveWhite2 = new PawnBitBoard(ChessPieceColors.White); bestMoveWhite2.Bits = BoardSquare.D3; Tuple <BitBoard, int> outputTuple_White1 = new Tuple <BitBoard, int>(bestMoveWhite1, 1); Tuple <BitBoard, int> outputTuple_White2 = new Tuple <BitBoard, int>(bestMoveWhite2, 1); BitBoard whiteBoard1 = outputTuple_White1.Item1; BitBoard whiteBoard2 = outputTuple_White2.Item1; int whiteVal = outputTuple_White1.Item2; //ÆNDRE TEST HER! BitBoard testTuple_White = NegaMax.GetBestMove(input, 1, ChessPieceColors.White, GenerateStaticMoves_White_Depth1, Eval.EvaluateState); int whiteVal_Test = outputTuple_White1.Item2; bool whiteBoardEqual = false; bool whiteBoardValEqual = false; //White test comparison if (whiteVal == whiteVal_Test) { whiteBoardValEqual = true; } if (testTuple_White is PawnBitBoard) { if (testTuple_White.Bits == whiteBoard1.Bits || testTuple_White.Bits == whiteBoard2.Bits) { whiteBoardEqual = true; } } Assert.True(whiteBoardValEqual && whiteBoardEqual); }
public void Handler_IsForceHandledCorrectly_Equal() { Winboard winboard = new Winboard(); PawnBitBoard correctWhitePawnPlacement = new PawnBitBoard(ChessPieceColors.White); PawnBitBoard correctBlackPawnPlacement = new PawnBitBoard(ChessPieceColors.Black); correctWhitePawnPlacement.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E4 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H2; correctBlackPawnPlacement.Bits = BoardSquare.A7 | BoardSquare.B7 | BoardSquare.C7 | BoardSquare.D7 | BoardSquare.E6 | BoardSquare.F7 | BoardSquare.G7 | BoardSquare.H7; winboard.Handler("new"); winboard.Handler("force"); winboard.Handler("e2e4"); winboard.Handler("e7e6"); Assert.Equal(correctWhitePawnPlacement.Bits, winboard.chessBoard.WhitePawn.Bits); Assert.Equal(correctBlackPawnPlacement.Bits, winboard.chessBoard.BlackPawn.Bits); }
private static void EvalFail() { ChessBoard lolBoard = new ChessBoard(); lolBoard.InitializeGame(); //White PawnBitBoard pawnWhite = new PawnBitBoard(ChessPieceColors.White); pawnWhite.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E2 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H3; PawnBitBoard pawnBlack = new PawnBitBoard(ChessPieceColors.Black); pawnBlack.Bits = BoardSquare.A7 | BoardSquare.B7 | BoardSquare.C7 | BoardSquare.D7 | BoardSquare.E7 | BoardSquare.F5 | BoardSquare.G7 | BoardSquare.H7; lolBoard.Update(pawnWhite); lolBoard.Update(pawnBlack); ColoredBitBoard bestMove = NegaMax.GetBestMove(lolBoard, 3, ChessPieceColors.White, MoveGen.GenerateLegalMoves, Eval.EvaluateState); }
public void Undo_WhitePawnRank1Forward_Equal() { ChessBoard testBoard = new ChessBoard(); testBoard.InitializeGame(); ulong expectedKey = testBoard.BoardHash.Key; PawnBitBoard move = new PawnBitBoard(ChessPieceColors.White); move.Bits = (testBoard.WhitePawn.Bits ^ BoardSquare.A2) | BoardSquare.A3; testBoard.Update(move); testBoard.Undo(); ulong actualKey = testBoard.BoardHash.Key; Assert.Equal(expectedKey, actualKey); }
public void Undo_BlackKingRankBackward_Equal() { ChessBoard testBoard = new ChessBoard(); testBoard.InitializeGame(); PawnBitBoard move1 = new PawnBitBoard(ChessPieceColors.White); move1.Bits = (testBoard.WhitePawn.Bits ^ BoardSquare.H2) | BoardSquare.H3; PawnBitBoard move2 = new PawnBitBoard(ChessPieceColors.Black); move2.Bits = (testBoard.BlackPawn.Bits ^ BoardSquare.E7) | BoardSquare.E6; PawnBitBoard move3 = new PawnBitBoard(ChessPieceColors.White); move3.Bits = (move1.Bits ^ BoardSquare.H3) | BoardSquare.H4; KingBitBoard move4 = new KingBitBoard(ChessPieceColors.Black); move4.Bits = (testBoard.BlackKing.Bits ^ BoardSquare.E8) | BoardSquare.E7; ulong expectedHash = testBoard.BoardHash.Key; testBoard.Update(move1); testBoard.Undo(); Assert.Equal(expectedHash, testBoard.BoardHash.Key); testBoard.Update(move1); expectedHash = testBoard.BoardHash.Key; testBoard.Update(move2); testBoard.Undo(); Assert.Equal(expectedHash, testBoard.BoardHash.Key); testBoard.Update(move2); expectedHash = testBoard.BoardHash.Key; testBoard.Update(move3); testBoard.Undo(); Assert.Equal(expectedHash, testBoard.BoardHash.Key); testBoard.Update(move3); expectedHash = testBoard.BoardHash.Key; testBoard.Update(move4); testBoard.Undo(); Assert.Equal(expectedHash, testBoard.BoardHash.Key); }
public void ConvertStringMoveToBitBoard_IsCorrectPromotionKnigtBitBoardReturned_Equal() { ChessBoard chessBoard = new ChessBoard(); chessBoard.WhitePawn.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E7 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H2; string stringMove = "e7e8n"; StringBitboardConverter converter = new StringBitboardConverter(chessBoard, ChessPieceColors.White); PawnBitBoard currentMoveBitBoard = (PawnBitBoard)converter.ConvertStringMoveToBitBoard(stringMove); PawnBitBoard correctMoveBitBoard = new PawnBitBoard(ChessPieceColors.White); correctMoveBitBoard.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E8 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H2; correctMoveBitBoard.Promote(PawnBitBoard.PromotionPiece.Knight); Assert.Equal(correctMoveBitBoard.GetType(), currentMoveBitBoard.GetType()); Assert.Equal(correctMoveBitBoard.Bits, currentMoveBitBoard.Bits); Assert.Equal(correctMoveBitBoard.Promotion, currentMoveBitBoard.Promotion); }
public string ConvertBitBoardMoveToString(ColoredBitBoard bitBoard) { ColoredBitBoard toBitBoard = bitBoard.DeepCopy(); ColoredBitBoard fromBitBoard = _chessBoard.GetOldBitBoardFromBitBoard(toBitBoard); System.Diagnostics.Debug.Assert(bitBoard.Bits != fromBitBoard.Bits); EmptyBitBoard containerBitBoard = new EmptyBitBoard(); containerBitBoard.Bits = fromBitBoard.Bits; fromBitBoard.Bits = (fromBitBoard.Bits | toBitBoard.Bits) ^ toBitBoard.Bits; toBitBoard.Bits = (fromBitBoard.Bits | toBitBoard.Bits) ^ containerBitBoard.Bits; string stringMove = fromBitBoard.Bits.ToString().ToLower() + toBitBoard.Bits.ToString().ToLower(); if (fromBitBoard is PawnBitBoard) { PawnBitBoard toPawnBitBoardPromotion = (PawnBitBoard)toBitBoard; if (toPawnBitBoardPromotion.IsPromoted) { switch (toPawnBitBoardPromotion.Promotion) { case PawnBitBoard.PromotionPiece.Queen: return(stringMove + "q"); case PawnBitBoard.PromotionPiece.Rook: return(stringMove + "r"); case PawnBitBoard.PromotionPiece.Bishop: return(stringMove + "b"); case PawnBitBoard.PromotionPiece.Knight: return(stringMove + "n"); default: throw new ArgumentOutOfRangeException("A promoted pawn bit board must contain a promotion type."); } } } return(stringMove); }
public static List <ColoredBitBoard> GenerateStaticMoves_White_Depth1(ChessBoard board, ChessPieceColors color) { List <ColoredBitBoard> legalMoves = new List <ColoredBitBoard>(); //White king moves KingBitBoard move1 = new KingBitBoard(ChessPieceColors.White); KingBitBoard move2 = new KingBitBoard(ChessPieceColors.White); KingBitBoard move3 = new KingBitBoard(ChessPieceColors.White); move1.Bits = BoardSquare.H2; move2.Bits = BoardSquare.G1; move3.Bits = BoardSquare.G2; //White pawn moves PawnBitBoard pawnEnd1 = new PawnBitBoard(ChessPieceColors.White); PawnBitBoard pawnEnd2 = new PawnBitBoard(ChessPieceColors.White); PawnBitBoard pawnEnd3 = new PawnBitBoard(ChessPieceColors.White); pawnEnd1.Bits = BoardSquare.C3; pawnEnd2.Bits = BoardSquare.D3; pawnEnd3.Bits = BoardSquare.B3; PawnBitBoard move4 = new PawnBitBoard(ChessPieceColors.White); PawnBitBoard move5 = new PawnBitBoard(ChessPieceColors.White); PawnBitBoard move6 = new PawnBitBoard(ChessPieceColors.White); move4.Bits = (board.WhitePawn.Bits ^ BoardSquare.C2) | pawnEnd1.Bits; move5.Bits = (board.WhitePawn.Bits ^ BoardSquare.C2) | pawnEnd2.Bits; move6.Bits = (board.WhitePawn.Bits ^ BoardSquare.C2) | pawnEnd3.Bits; legalMoves.Add(move1); legalMoves.Add(move2); legalMoves.Add(move3); legalMoves.Add(move4); legalMoves.Add(move5); legalMoves.Add(move6); return(legalMoves); }