public void testQueenMovementWithCapture() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); squarePos srcSquare = new squarePos(3, 3); ourBoard.addPiece(pieceType.queen, pieceColour.white, srcSquare.x, srcSquare.y); queenSquare queenie = (queenSquare)ourBoard[srcSquare]; // Place a black pawn on the board, and ensure that we can capture it, and // that we cannot move through it. ourBoard.addPiece(pieceType.pawn, pieceColour.black, 1, 1); sizableArray<move> possibleMoves = queenie.getPossibleMoves(ourBoard); List<move> expectedmoves = getExpectedMoveSquares(queenie); // We don't expect to be able to move to (0,0), since that square is behind an // enemy pawn.. bool found = false; for (int i = 0; i < expectedmoves.Count; i++) { if (expectedmoves[i].dstPos.x == 0 && expectedmoves[i].dstPos.y == 0) { expectedmoves.RemoveAt(i); found = true; break; } } if (!found) throw new ArgumentOutOfRangeException(); VectorMovementTests.testListsAreOfSameMoves(expectedmoves, possibleMoves); }
public void testCheckDetectionAsWhite() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); ourBoard.addPiece(pieceType.rook, pieceColour.black, 1, 1); ourBoard.addPiece(pieceType.king, pieceColour.white, 3, 1); Assert.IsTrue(ourBoard.isPlayerInCheck(pieceColour.white)); }
public void testQueensideCastlingNotation() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); square ourKing = ourBoard.addPiece(pieceType.king, pieceColour.white, 4, 0); ourBoard.addPiece(pieceType.rook, pieceColour.white, 0, 0); move theMove = new move(ourKing, new square(2, 0)); Assert.AreEqual("O-O-O", theMove.ToString(moveStringStyle.chessNotation)); }
public void testKingsideCastlingMoveIsExecutedCorrectly() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); square ourKing = ourBoard.addPiece(pieceType.king, pieceColour.white, 4, 0); square ourRook = ourBoard.addPiece(pieceType.rook, pieceColour.white, 7, 0); ourBoard.addPiece(pieceType.king, pieceColour.black, 0, 0); // Make our castling move.. move castlingMove = new move(ourKing, ourBoard[6, 0]); ourBoard.doMove(castlingMove); // Verify that the rook and king have both moved to their correct squares. Assert.IsTrue(ourBoard[6, 0] == ourKing); Assert.IsTrue(ourBoard[5, 0] == ourRook); }
public void testKingsideCastlingMoveIsNotAfterRookHasMoved() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); square ourKing = ourBoard.addPiece(pieceType.king, pieceColour.white, 4, 0); square ourRook = ourBoard.addPiece(pieceType.rook, pieceColour.white, 6, 0); ourBoard.addPiece(pieceType.king, pieceColour.black, 0, 0); // Move the rook to 7,0. ourBoard.doMove(new move(ourRook, ourBoard[7,0])); // Now make sure we cannot castle. sizableArray<move> possibleMoves = ourKing.getPossibleMoves(ourBoard); // None of these moves should end up at (6,0). if (Array.Find(possibleMoves.getArray(), a => a.dstPos.isSameSquareAs(new squarePos(6, 0))) != null) throw new AssertFailedException("Castling found after rook has moved"); }
public void testKingsideCastlingMoveIsFound() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); square ourKing = ourBoard.addPiece(pieceType.king, pieceColour.white, 4, 0); ourBoard.addPiece(pieceType.rook, pieceColour.white, 7, 0); ourBoard.addPiece(pieceType.king, pieceColour.black, 0, 0); sizableArray<move> possibleMoves = ourKing.getPossibleMoves(ourBoard); // One of these moves should be a non-capturing move of the king to (6,0). move[] castlingMoveList = Array.FindAll(possibleMoves.getArray(), a => !a.isCapture && a.dstPos.isSameSquareAs(new squarePos(6, 0))); Assert.AreNotEqual(0, castlingMoveList.Length, "Castling move was not found"); Assert.AreEqual(1, castlingMoveList.Length, "Multiple castling moves were found"); // Verify some other stuff on the move. move castlingMove = castlingMoveList[0]; if (!castlingMove.srcPos.isSameSquareAs(ourKing.position)) throw new AssertFailedException("Castling move has incorrect source square"); }
public void testQueenMovement() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); squarePos srcSquare = new squarePos(3, 3); ourBoard.addPiece(pieceType.queen, pieceColour.white, srcSquare.x, srcSquare.y); queenSquare queenie = (queenSquare) ourBoard[srcSquare]; sizableArray<move> possibleMoves = queenie.getPossibleMoves(ourBoard); List<move> expectedmoves = getExpectedMoveSquares(queenie); VectorMovementTests.testListsAreOfSameMoves(expectedmoves, possibleMoves); }
public void testFinishedGameScoreNoPieces() { // Generate a board which is lost via the 'no pieces remain' rule, and verify // we get the correct score. DoktorChessAIBoard ourboard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); ourboard.addPiece(pieceType.pawn, pieceColour.black, 1, 1); // position is lost for white.. BoardScorer whiteScorer = new BoardScorer(ourboard, pieceColour.white, new scoreModifiers()); Assert.AreEqual(BoardScorer.lowest, whiteScorer.getScore()); // and won for black. BoardScorer blackScorer = new BoardScorer(ourboard, pieceColour.black, new scoreModifiers()); Assert.AreEqual(BoardScorer.highest, blackScorer.getScore()); }
public void testFinishedGameScorePawnToOtherEnd() { // We make two different boards here to test two different scenarios - if a black // pawn is at rank 0 and a white at rank 7. DoktorChessAIBoard pawnAt0 = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); pawnAt0.addPiece(pieceType.pawn, pieceColour.black, 1, 0); // Should be a black win. verifyWonForWhite(pawnAt0, pieceColour.black); // Now the white pawn at rank 7. DoktorChessAIBoard pawnAt7 = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); pawnAt7.addPiece(pieceType.pawn, pieceColour.white, 1, 7); // Should be a white win. verifyWonForWhite(pawnAt7, pieceColour.white); }
public void testNonInitialPawnMovement() { // Pawns can only move one square after their initial move. DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 1, 1); // Mark pawn as having moved ourPawn.movedCount++; sizableArray<move> actual = ourPawn.getPossibleMoves(ourBoard); // We expect that the pawn can move one space forward only. List<move> expected = new List<move> { new move(ourPawn, ourBoard[1, 2]) }; VectorMovementTests.testListsAreOfSameMoves(expected, actual); }
public void testInitialPawnMovement() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); ourBoard.addPiece(pieceType.pawn, pieceColour.white, 1, 1); square ourPawn = ourBoard[1, 1]; sizableArray<move> actual = ourPawn.getPossibleMoves(ourBoard); // We expect that the pawn can move two spaces forward, or one space forward. List<move> expected = new List<move> { new move(ourPawn, ourBoard[1, 2]), new move(ourPawn, ourBoard[1, 3]) }; VectorMovementTests.testListsAreOfSameMoves(expected, actual); if (ourPawn.movedCount != 0) throw new Exception("Pawn not move count not incremented"); }
public void testMoveDoingUndoingWithPawnPromotion() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); ourBoard.addPiece(pieceType.pawn, pieceColour.white, 1, 6); string origBoard = ourBoard.ToString(); sizableArray<move> potentialMoves = ourBoard.getMoves(pieceColour.white); if (potentialMoves.Length == 0) Assert.Inconclusive("No pawn moves found"); // Find promotion moves move[] promotionMoves = Array.FindAll(potentialMoves.getArray(), a => a.isPawnPromotion); if (promotionMoves.Length == 0) Assert.Inconclusive("No promotion moves found"); foreach (move thisMove in promotionMoves) { ourBoard.doMove(thisMove); if (ourBoard.ToString() == origBoard) throw new AssertFailedException("After a pawn promotion move, the board has not changed"); // Additionally, verify that the pawn has been promoted if (ourBoard[thisMove.dstPos].type != thisMove.typeToPromoteTo) throw new AssertFailedException("Pawn was not promoted"); if (ourBoard[thisMove.dstPos].GetType() == typeof(pawnSquare)) throw new AssertFailedException("Pawn was not promoted, but type has changed"); if (ourBoard[thisMove.dstPos].colour != pieceColour.white) throw new AssertFailedException("Pawn was promoted to wrong colour"); ourBoard.undoMove(thisMove); if (ourBoard.ToString() != origBoard) throw new AssertFailedException("After a pawn promotion move undo, the board has changed"); } }
public void testPawnMovementWithCaptureCol0() { // Spawn a black pawn at 0,3 and a white pawn at 1,4. Verify that the black // pawn can capture the white. DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 0, 3); square enemyPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.black, 1, 4); sizableArray<move> possibleMoves = ourPawn.getPossibleMoves(ourBoard); checkContainsSingleCapture(possibleMoves.getArray(), ourPawn, enemyPawn); }
public void testThatEnPassantOccursWhenItShouldAsBlack() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); // En passant requires that the enemy pawn has just advanced two squares. Because of this, we make this move on a board and then check that en passant can occur. square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.black, 6, 3); square enemyPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 7, 1); // Advance the enemy pawn move advanceTwo = new move(enemyPawn, ourBoard[enemyPawn.position.up(2)]); ourBoard.doMove(advanceTwo); // Now verify that the enemy pawn is captured. sizableArray<move> possibleMoves = ourPawn.getPossibleMoves(ourBoard); move enPassantCapture = null; foreach (move thisMove in possibleMoves) { if (thisMove.isCapture) { if (enPassantCapture != null) throw new AssertFailedException("More than one capture was found"); // Note that our dest square is not the enemy square here. Assert.IsTrue(thisMove.srcPos.isSameSquareAs(ourPawn.position)); Assert.IsTrue(thisMove.dstPos.isSameSquareAs(ourPawn.position.rightOne().downOne() )); Assert.AreSame(thisMove.capturedSquare, enemyPawn); enPassantCapture = thisMove; } } if (enPassantCapture == null) throw new AssertFailedException("En passant capture did not occur"); // Make sure that the en passant capture ends up putting our pawn in the square above the enemy pawn Assert.IsTrue(enemyPawn.position.downOne().isSameSquareAs( enPassantCapture.dstPos) ); }
public void testPawnPromotionWithCapture() { // Verify promotion occurs when capturing in to the back row. DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 1, 6); ourPawn.movedCount++; ourBoard.addPiece(pieceType.knight, pieceColour.black, 1, 7); ourBoard.addPiece(pieceType.knight, pieceColour.black, 2, 7); sizableArray<move> actual = ourPawn.getPossibleMoves(ourBoard); // We expect a number of moves forward, all of which are promotions. List<move> expected = new List<move> { new move(ourPawn, ourBoard[2, 7], pieceType.bishop), new move(ourPawn, ourBoard[2, 7], pieceType.knight), new move(ourPawn, ourBoard[2, 7], pieceType.queen), new move(ourPawn, ourBoard[2, 7], pieceType.rook) }; VectorMovementTests.testListsAreOfSameMoves(expected, actual); }
public void testVectorMovement(List<squarePos> expectedPos, vectorDirection dir) { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); squarePos srcSquare = new squarePos(3, 3); ourBoard.addPiece(pieceType.queen, pieceColour.white, srcSquare.x, srcSquare.y); queenSquare queenie = (queenSquare)ourBoard[srcSquare]; List<move> expectedmoves = new List<move>(expectedPos.Count); foreach (squarePos thisPos in expectedPos) expectedmoves.Add(new move((square) queenie, ourBoard[thisPos])); sizableArray<move> possibleMoves = queenie.getMovesForVector(null, ourBoard, dir); testListsAreOfSameMoves(expectedmoves, possibleMoves); }
public void testThreatMapDeep_discoveredPromotion() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 3, 6); square enemyPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.black, 3, 7); square ourRook = ourBoard.addPiece(pieceType.rook, pieceColour.white, 0, 7); move ourMove = new move(ourPawn, ourBoard[3, 7], pieceType.queen); ourBoard.doMove(ourMove); // Observe the squares to the right of our pawn - they should not be accessible to the rook for (int x = 4; x < 7; x++) { if (ourBoard.getCoverLevel(new squarePos(x, 7), pieceColour.white) != 1) throw new AssertFailedException("Threatmap did not update cover levels correctly"); } // the pawn itself is protected once. if (ourBoard.getCoverLevel(new squarePos(3, 7), pieceColour.white) != 1) throw new AssertFailedException("Threatmap did not update cover levels of promoted piece correctly"); }
public void testFinishedGameScoreStalemate() { // Generate a board two pawns, deadlocked in front of each other. This should // be a draw via stalemate. Add a third pawn to ensure that stalemate is causing // the '0' board score, not a materian mismatch. DoktorChessAIBoard ourboard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); // Two deadlocked pawns ourboard.addPiece(pieceType.pawn, pieceColour.white, 1, 2); ourboard.addPiece(pieceType.pawn, pieceColour.black, 1, 3); // an outlier pawn ourboard.addPiece(pieceType.pawn, pieceColour.black, 4, 4); Assert.IsTrue(ourboard.getGameStatus(pieceColour.white) == gameStatus.drawn); Assert.IsTrue(ourboard.getGameStatus(pieceColour.black) == gameStatus.drawn); BoardScorer whiteScorer = new BoardScorer(ourboard, pieceColour.white, new scoreModifiers()); Assert.AreEqual(0, whiteScorer.getScore()); BoardScorer blackScorer = new BoardScorer(ourboard, pieceColour.black, new scoreModifiers()); Assert.AreEqual(0, blackScorer.getScore()); }
public void testThreatMapDeep_discoveredCapture() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 0, 1); square enemyPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.black, 1, 2); square ourRook = ourBoard.addPiece(pieceType.rook, pieceColour.white, 0, 0); square enemyRook = ourBoard.addPiece(pieceType.rook, pieceColour.black, 0, 7); move ourMove = new move(ourPawn, enemyPawn); ourBoard.doMove(ourMove); // Squares between rooks our pawn should be threatened by both rooks, so should have a threat // level of 0, apart from the one at y=3, which is threatened by a pawn. for (int x = 1; x < 7; x++) { if (x == 3) { if (ourBoard.getCoverLevel(new squarePos(0, x), pieceColour.black) != -1) throw new AssertFailedException("Threatmap did not update cover levels correctly for discovered spaces"); } else { if (ourBoard.getCoverLevel(new squarePos(0, x), pieceColour.black) != 0) throw new AssertFailedException("Threatmap did not update cover levels correctly for discovered spaces"); } } // Both rooks should be threatened once, by the other rook. if (ourBoard.getCoverLevel(new squarePos(0, 0), pieceColour.black) != 1 || ourBoard.getCoverLevel(new squarePos(0, 7), pieceColour.white) != 1 ) throw new AssertFailedException("Threatmap did not update cover levels correctly for rooks"); }
public void testKingsideCastlingMoveIsNotFoundThroughAPiece() { // Place an enemy pawn in the way which will prevent us from castling. DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); square ourKing = ourBoard.addPiece(pieceType.king, pieceColour.white, 4, 0); ourBoard.addPiece(pieceType.rook, pieceColour.white, 7, 0); ourBoard.addPiece(pieceType.pawn, pieceColour.black, 6, 0); ourBoard.addPiece(pieceType.king, pieceColour.black, 0, 0); sizableArray<move> possibleMoves = ourKing.getPossibleMoves(ourBoard); // None of these moves should end up at (6, 0). if (Array.Find(possibleMoves.getArray(), a => a.dstPos.isSameSquareAs(new squarePos(6, 0))) != null) throw new AssertFailedException("Castling found through an enemy piece"); }
public void testScoreWithDangling() { DoktorChessAIBoard ourboard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); ourboard.addPiece(pieceType.pawn, pieceColour.black, 3, 3); ourboard.addPiece(pieceType.queen, pieceColour.white, 2, 2); ourboard.addPiece(pieceType.king, pieceColour.black, 7, 7); ourboard.addPiece(pieceType.king, pieceColour.white, 5, 5); BoardScorer whiteScorer = new BoardScorer(ourboard, pieceColour.white, new scoreModifiers()); // White's queen is dangling, as is blacks pawn. int expected = whiteScorer.modifiers.materialModifier * (8 - 1); expected -= whiteScorer.modifiers.danglingModifier * 8; expected += whiteScorer.modifiers.danglingModifier * 1; Assert.AreEqual(expected, whiteScorer.getScore()); }
public void testMaterialAdvantage() { // Generate a boardScorer and present it with a queen (ours), and two pawns // (enemy). Verify the resultant score as 8-2 = 6. DoktorChessAIBoard ourboard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); ourboard.addPiece(pieceType.queen, pieceColour.white, 1, 1); ourboard.addPiece(pieceType.pawn, pieceColour.black, 3, 4); ourboard.addPiece(pieceType.pawn, pieceColour.black, 3, 5); BoardScorer myscorer = new BoardScorer(ourboard, pieceColour.white, new scoreModifiers()); // Check only material advantage myscorer.modifiers.danglingModifier = 0; myscorer.modifiers.materialModifier = 1; Assert.AreEqual(8 - 2, myscorer.getScore()); }
public void testQueensideCastlingMoveIsFoundThroughCheck() { // It is legal to castle queenside if the space next to the rook is covered, since the king // does not move through it. DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); square ourKing = ourBoard.addPiece(pieceType.king, pieceColour.white, 4, 0); ourBoard.addPiece(pieceType.rook, pieceColour.white, 0, 0); ourBoard.addPiece(pieceType.king, pieceColour.black, 7, 7); // Throw in a rook which covers (1,0) ourBoard.addPiece(pieceType.rook, pieceColour.black, 1, 7); sizableArray<move> possibleMoves = ourKing.getPossibleMoves(ourBoard); // One of these moves should be a non-capturing move of the king to (2,0). move[] castlingMoveList = Array.FindAll(possibleMoves.getArray(), a => !a.isCapture && a.dstPos.isSameSquareAs(new squarePos(2, 0))); Assert.AreNotEqual(0, castlingMoveList.Length, "Castling move was not found"); Assert.AreEqual(1, castlingMoveList.Length, "Multiple castling moves were found"); // Verify some other stuff on the move. move castlingMove = castlingMoveList[0]; if (!castlingMove.srcPos.isSameSquareAs(ourKing.position)) throw new AssertFailedException("Castling move has incorrect source square"); }
public void testKingsideCastlingMoveIsUnExecutedCorrectly() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); square ourKing = ourBoard.addPiece(pieceType.king, pieceColour.white, 4, 0); square ourRook = ourBoard.addPiece(pieceType.rook, pieceColour.white, 7, 0); ourBoard.addPiece(pieceType.king, pieceColour.black, 0, 0); string origBoard = ourBoard.ToString(); // Make out castling move move castlingMove = new move(ourKing, ourBoard[6, 0]); ourBoard.doMove(castlingMove); Assert.AreNotEqual(origBoard, ourBoard.ToString(), "Castling did not affect the board"); // Now undo our castling and verify that we get back to the original position. ourBoard.undoMove(castlingMove); Assert.AreEqual(origBoard, ourBoard.ToString(), "Castling and then un-castling did not return the original board"); }
public void testThreatMapDeep_pawnCapture() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 4, 1); square enemyPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.black, 3, 2); if (ourBoard.getCoverLevel(new squarePos(3, 2), pieceColour.white) != 1 || ourBoard.getCoverLevel(new squarePos(5, 2), pieceColour.white) != 1) throw new AssertFailedException("Threatmap created wrongly"); if (ourBoard.getCoverLevel(new squarePos(2, 1), pieceColour.white) != -1 || ourBoard.getCoverLevel(new squarePos(4, 1), pieceColour.white) != -1) throw new AssertFailedException("Enemy pawn create with no threatened squares"); if (ourPawn.coveredSquares.Count != 2) throw new AssertFailedException("Pawn created not covering two squares"); if ((!ourPawn.coveredSquares[3, 2]) || (!ourPawn.coveredSquares[5, 2]) ) throw new AssertFailedException("Pawn created with incorrect .coveredSquares"); if (((threatMap)ourBoard.coverLevel).piecesWhichThreatenSquare[3, 2].Count != 1 || ((threatMap)ourBoard.coverLevel).piecesWhichThreatenSquare[3, 2].Count != 1) throw new AssertFailedException("Pawn created with incorrect .piecesWhichThreatenSquare count"); //if (((threatMap)ourBoard.coverLevel).piecesWhichThreatenSquare[3, 2][ourPawn.position.flatten()] != ourPawn || // ((threatMap)ourBoard.coverLevel).piecesWhichThreatenSquare[5, 2][ourPawn.position.flatten()] != ourPawn) // throw new AssertFailedException("Pawn created with incorrect .piecesWhichThreatenSquare contents"); move ourMove = new move(ourPawn, ourBoard[3, 2]); ourBoard.doMove(ourMove); if (ourBoard.getCoverLevel(new squarePos(2, 3), pieceColour.white) != 1 || ourBoard.getCoverLevel(new squarePos(4, 3), pieceColour.white) != 1) throw new AssertFailedException("Threatmap did not update cover levels correctly"); if (ourBoard.getCoverLevel(new squarePos(2, 1), pieceColour.white) != 0 || ourBoard.getCoverLevel(new squarePos(4, 1), pieceColour.white) != 0) throw new AssertFailedException("Captured pawn still has threatened squares"); if (ourPawn.coveredSquares.Count != 2) throw new AssertFailedException("Pawn updated not covering two squares"); if (!ourPawn.coveredSquares[2, 3] || !ourPawn.coveredSquares[4, 3] ) throw new AssertFailedException("Pawn updated with incorrect .coveredSquares"); if (((threatMap)ourBoard.coverLevel).piecesWhichThreatenSquare[3, 2].Count != 0 || ((threatMap)ourBoard.coverLevel).piecesWhichThreatenSquare[3, 2].Count != 0) throw new AssertFailedException("Pawn's pre-update .piecesWhichThreatenSquare was not changed"); if (((threatMap)ourBoard.coverLevel).piecesWhichThreatenSquare[2, 3].Count != 1 || ((threatMap)ourBoard.coverLevel).piecesWhichThreatenSquare[4, 3].Count != 1) throw new AssertFailedException("Pawn updated with incorrect .piecesWhichThreatenSquare count"); //if (((threatMap)ourBoard.coverLevel).piecesWhichThreatenSquare[2, 3][ourPawn.position.flatten()] != ourPawn || // ((threatMap)ourBoard.coverLevel).piecesWhichThreatenSquare[4, 3][ourPawn.position.flatten()] != ourPawn) // throw new AssertFailedException("Pawn updated with incorrect .piecesWhichThreatenSquare contents"); }
public void testPawnMovementWithCaptureCol7() { // Now test the same, at the other end of the board. Test on the edge. DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig()); square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 6, 3); square enemyPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.black, 7, 4); sizableArray<move> possibleMoves = ourPawn.getPossibleMoves(ourBoard); checkContainsSingleCapture(possibleMoves.getArray(), ourPawn, enemyPawn); }
public void testPawnPromotionAsBlack() { // Pawns should be able to be promoted to any piece of their own colour, other than a // king. DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.black, 1, 1); ourPawn.movedCount++; sizableArray<move> actual = ourPawn.getPossibleMoves(ourBoard); // We expect a number of moves forward, all of which are promotions. List<move> expected = new List<move> { new move(ourPawn, ourBoard[1, 0], pieceType.bishop), new move(ourPawn, ourBoard[1, 0], pieceType.knight), new move(ourPawn, ourBoard[1, 0], pieceType.queen), new move(ourPawn, ourBoard[1, 0], pieceType.rook) }; VectorMovementTests.testListsAreOfSameMoves(expected, actual); }
public void testQueensideCastlingMoveIsNotFoundThroughCheck() { // And we cannot castle through check apart from as noted above. DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); square ourKing = ourBoard.addPiece(pieceType.king, pieceColour.white, 4, 0); ourBoard.addPiece(pieceType.rook, pieceColour.white, 0, 0); ourBoard.addPiece(pieceType.king, pieceColour.black, 7, 7); ourBoard.addPiece(pieceType.rook, pieceColour.black, 3, 7); sizableArray<move> possibleMoves = ourKing.getPossibleMoves(ourBoard); // None of these moves should end up at (2, 0). if (Array.Find(possibleMoves.getArray(), a => a.dstPos.isSameSquareAs(new squarePos(2, 0))) != null) throw new AssertFailedException("Castling found through check"); }
public void testThatKingWillNotMoveInToCheck() { boardSearchConfig config = boardSearchConfig.getDebugConfig(); config.searchDepth = 0; DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, config); square blackKing = ourBoard.addPiece(pieceType.king, pieceColour.black, 0, 0); ourBoard.addPiece(pieceType.rook, pieceColour.white, 1, 7); ourBoard.addPiece(pieceType.king, pieceColour.white, 7, 7); // Ensure that black cannot move in to the rook's line of fire. sizableArray<move> moves = blackKing.getPossibleMoves(ourBoard); foreach (move thisMove in moves) Assert.IsTrue(thisMove.dstPos.x == 0, "King moved in to check"); Assert.IsTrue(moves.Length == 1); }
public void testThreatMapDeep_discovered() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig() ); square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 4, 1); square ourRook = ourBoard.addPiece(pieceType.rook, pieceColour.white, 0, 1); move ourMove = new move(ourPawn, ourBoard[4, 2]); ourBoard.doMove(ourMove); // Observe the squares to the right of our pawn - they should now be accessible to the rook for (int x = 1; x < 7; x++) { if (ourBoard.getCoverLevel(new squarePos(x, 1), pieceColour.white) != 1) throw new AssertFailedException("Threatmap did not update cover levels correctly"); } }