From a383e52bd75c84ec5adc49195e2c330eeef5a0a4 Mon Sep 17 00:00:00 2001 From: TiynGER Date: Thu, 6 May 2021 02:26:57 +0200 Subject: [PATCH] ches: added fen FEN is a notation to describe a state of a chess game. Added a initChess function, which is able to create a chess object from FEN --- src/chess.nim | 62 ++++- src/chessTest.nim | 633 ++++++---------------------------------------- src/engine.nim | 2 +- 3 files changed, 133 insertions(+), 564 deletions(-) diff --git a/src/chess.nim b/src/chess.nim index 87f2e61..5f04bff 100644 --- a/src/chess.nim +++ b/src/chess.nim @@ -1,12 +1,15 @@ +import algorithm +import sequtils +import strutils +import sugar import tables -from strutils import parseInt type Color* = enum ## `Color` describes the possible color of players. Black = -1, White = 1 - Board = array[0..119, int] ## \ + Board = array[120, int] ## \ ## `Board` saves the position of the chess pieces. CastleRights = tuple ## `CastleRights` contains the rights to castling for each player. @@ -41,6 +44,8 @@ type const Block = 999 ## \ ## `Block` is the value assigned to empty blocked fields in a board. + Empty = 0 ## \ + ## `Empty` is the value assigned to empty fields on a board. WPawn* = 1 ## `WPawn` is the value assigned to a square in a board with a white pawn. WKnight* = 2 ## \ @@ -226,7 +231,7 @@ proc initBoard(): Board = Block, Block, Block, Block, Block, Block, Block, Block, Block, Block] return board -proc initBoard(board: array[0..63, int]): Board = +proc initBoard(board: array[64, int]): Board = ## Create and return a board with pieces in position of choice, described in ## `board`. let board = [ @@ -255,11 +260,10 @@ proc initBoard(board: array[0..63, int]): Board = proc initChess*(): Chess = ## Create and return a Chess object. let chess = Chess(board: initBoard(), - to_move: Color.White, previousBoard: @[], previousCastleRights: @[], - fiftyMoveCounter: 0, castleRights: (true, true, true, true)) + to_move: Color.White, castleRights: (true, true, true, true)) return chess -proc initChess(board: array[0..63, int], color: Color): Chess = +proc initChess(board: array[64, int], color: Color): Chess = ## Create and return a Chess object based on a position of choice. ## `board` describes the pieces, `color` the color that is about to move. let board = initBoard(board) @@ -282,6 +286,49 @@ proc initChess(board: array[0..63, int], color: Color): Chess = to_move: color, castleRights: (wk, wq, bk, bq)) return chess +proc initChess*(fen: string): Chess = + ## Create and return a Chess object from `fen`. + var revPieceChar = toSeq(PieceChar.pairs).map(y => (y[1], y[0])).toTable + revPieceChar[" "] = Empty + var fenArr = fen.split(" ") + var squares: array[64, int] + var tmp: seq[int] + var squaresInd: int + for i, subc in fenArr[0].reversed(): + if subc == '/': + continue + if subc.isDigit(): + for j in 1..parseInt($subc): + squares[squaresInd] = revPieceChar[" "] + squaresInd += 1 + continue + else: + squares[squaresInd] = revPieceChar[$subc] + squaresInd += 1 + var board = initBoard(squares) + var toMove: Color + if fenArr[1] == "w": + toMove = Color.White + else: + toMove = Color.Black + var castleRights: CastleRights + if fenArr[2].contains("K"): + castleRights.wk = true + if fenArr[2].contains("Q"): + castleRights.wq = true + if fenArr[2].contains("k"): + castleRights.bk = true + if fenArr[2].contains("q"): + castleRights.bq = true + if fenArr[3] != "-": + if toMove == Color.White: + board[fieldToInd(fenArr[3])] = BEnPassant + else: + board[fieldToInd(fenArr[3])] = WEnPassant + var fiftyMoveCounter = parseInt(fenArr[4]) + return Chess(board: board, toMove: toMove, castleRights: castleRights, + fiftyMoveCounter: fiftyMoveCounter) + proc echoBoard*(chess: Chess, color: Color) = ## Prints out the given `board` with its pieces as characters and line ## indices from perspecive of `color`. @@ -543,8 +590,7 @@ proc genPawnPromotion(move: Move, color: Color): seq[Move] = var promotions = newSeq[Move]() let start = move.start let dest = move.dest - if (fieldToInd("h8") <= dest and dest <= fieldToInd("a8")) or - (fieldToInd("h1") <= dest and dest <= fieldToInd("a1")): + if (fieldToInd("h8") >= dest) or (fieldToInd("a8") >= dest): for piece in WKnight..WQueen: promotions.add(getMove(start, dest, piece, color)) return promotions diff --git a/src/chessTest.nim b/src/chessTest.nim index 8818a72..1cdea35 100644 --- a/src/chessTest.nim +++ b/src/chessTest.nim @@ -83,188 +83,53 @@ testSuite ChessTest of TestSuite: self.check(not self.chess.isStalemate(Color.Black)) method testIsStalemateTrueWhite() = - self.chess = initChess([ - 0, 0, 0, 0, BRook, BQueen, BRook, BKnight, - 0, BPawn, 0, 0, BPawn, BPawn, BBishop, WKing, - 0, BPawn, 0, BPawn, 0, BPawn, 0, BKnight, - 0, 0, 0, 0, 0, 0, BPawn, 0, - 0, 0, BBishop, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, BPawn, BKing, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.White) + self.chess = initChess("8/5kp1/8/5b2/1p6/n1p1p1p1/Kbpp2p1/nrqr4 w - - 0 0") self.check(self.chess.isStalemate(Color.White)) method testIsStalemateTrueBlack() = - self.chess = initChess([ - 0, 0, 0, 0, WRook, WQueen, WRook, WKnight, - 0, WPawn, 0, 0, WPawn, WPawn, WBishop, BKing, - 0, WPawn, 0, WPawn, 0, WPawn, 0, WKnight, - 0, 0, 0, 0, 0, 0, WPawn, 0, - 0, 0, WBishop, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, WPawn, WKing, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/5KP1/8/5B2/1P6/N1P1P1P1/kBPP2P1/NRQR4 b - - 0 0") self.check(self.chess.isStalemate(Color.Black)) method testIsStalemateInsufficientMaterialTrue() = - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/8/8/8/4K3/8 b - - 0 0") self.check(self.chess.isStalemate(Color.Black)) self.check(self.chess.isStalemate(Color.White)) - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, WKnight, - 0, 0, WKnight, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/5N2/N7/8/4K3/8 b - - 0 0") self.check(self.chess.isStalemate(Color.Black)) self.check(self.chess.isStalemate(Color.White)) - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, BKnight, - 0, 0, BKnight, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/5n2/n7/8/4K3/8 b - - 0 0") self.check(self.chess.isStalemate(Color.Black)) self.check(self.chess.isStalemate(Color.White)) - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, BKnight, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/8/n7/8/4K3/8 b - - 0 0") self.check(self.chess.isStalemate(Color.Black)) self.check(self.chess.isStalemate(Color.White)) - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, WKnight, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/8/N7/8/4K3/8 b - - 0 0") self.check(self.chess.isStalemate(Color.Black)) self.check(self.chess.isStalemate(Color.White)) - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, BBishop, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/8/b7/8/4K3/8 b - - 0 0") self.check(self.chess.isStalemate(Color.Black)) self.check(self.chess.isStalemate(Color.White)) - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, WBishop, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/8/B7/8/4K3/8 b - - 0 0") self.check(self.chess.isStalemate(Color.Black)) self.check(self.chess.isStalemate(Color.White)) method testIsStalemateInsufficientMaterialFalse() = - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, BPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/8/p7/8/4K3/8 b - - 0 0") self.check(not self.chess.isStalemate(Color.Black)) self.check(not self.chess.isStalemate(Color.White)) - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/8/P7/8/4K3/8 b - - 0 0") self.check(not self.chess.isStalemate(Color.Black)) self.check(not self.chess.isStalemate(Color.White)) - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, BRook, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/8/r7/8/4K3/8 b - - 0 0") self.check(not self.chess.isStalemate(Color.Black)) self.check(not self.chess.isStalemate(Color.White)) - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, WRook, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/8/R7/8/4K3/8 b - - 0 0") self.check(not self.chess.isStalemate(Color.Black)) self.check(not self.chess.isStalemate(Color.White)) - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, WBishop, 0, 0, 0, 0, 0, BPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/8/p5B1/8/4K3/8 b - - 0 0") self.check(not self.chess.isStalemate(Color.Black)) self.check(not self.chess.isStalemate(Color.White)) - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WKing, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, BBishop, 0, 0, 0, 0, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, BKing, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("8/2k5/8/8/P4b2/8/4K3/8 b - - 0 0") self.check(not self.chess.isStalemate(Color.Black)) self.check(not self.chess.isStalemate(Color.White)) @@ -295,16 +160,7 @@ testSuite ChessTest of TestSuite: self.check(not self.chess.isDrawClaimable()) method testIsDrawClaimableFiftyMoveRuleTrue() = - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, BRook, - 0, 0, 0, 0, 0, 0, 0, 0, - WBishop, 0, 0, 0, 0, 0, 0, 0, - 0, 0, WKing, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, WRook, 0, - 0, 0, 0, BKing, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("4k3/1R6/8/5K2/7B/8/r7/8 b - - 0 0") self.chess.checkedMove(notationToMove("a2a5", Color.Black)) self.chess.checkedMove(notationToMove("f5g6", Color.White)) self.chess.checkedMove(notationToMove("a5e5", Color.Black)) @@ -408,16 +264,7 @@ testSuite ChessTest of TestSuite: self.check(self.chess.isDrawClaimable()) method testIsDrawClaimableFiftyMoveRuleFalseNinetyFour() = - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, BRook, - 0, 0, 0, 0, 0, 0, 0, 0, - WBishop, 0, 0, 0, 0, 0, 0, 0, - 0, 0, WKing, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, WRook, 0, - 0, 0, 0, BKing, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("4k3/1R6/8/5K2/7B/8/r7/8 b - - 0 0") self.chess.checkedMove(notationToMove("a2a5", Color.Black)) self.chess.checkedMove(notationToMove("f5g6", Color.White)) self.chess.checkedMove(notationToMove("a5e5", Color.Black)) @@ -521,16 +368,7 @@ testSuite ChessTest of TestSuite: self.check(self.chess.isDrawClaimable()) method testIsDrawClaimableFiftyMoveRuleFalseCapture() = - self.chess = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, BRook, - 0, 0, 0, 0, 0, 0, 0, 0, - WBishop, 0, 0, 0, 0, 0, 0, 0, - 0, 0, WKing, 0, 0, 0, 0, 0, - 0, 0, BPawn, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, WRook, 0, - 0, 0, 0, BKing, 0, 0, 0, 0 - ], Color.Black) + self.chess = initChess("4k3/1R6/5p2/5K2/7B/8/r7/8 b - - 0 0") self.chess.checkedMove(notationToMove("a2a5", Color.Black)) self.chess.checkedMove(notationToMove("f5g6", Color.White)) self.chess.checkedMove(notationToMove("a5e5", Color.Black)) @@ -649,17 +487,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnSingleFalseIntoEnemyPiece() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r3k2r/8/8/pppppppp/PPPPPPPP/8/8/R3K2R w - - 0 0") for file in "abcdefgh": test = self.chess.checkedMove(notationToMove($file & "4" & $file & "5", Color.White)) self.check(not test) @@ -668,17 +496,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnSingleFalseIntoOwnPiece() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r3k2r/pppppppp/pppppppp/8/8/PPPPPPPP/PPPPPPPP/R3K2R w - - 0 0") for file in "abcdefgh": test = self.chess.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) self.check(not test) @@ -696,17 +514,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnDoubleFalseAlreadyMoved() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - 0, 0, 0, 0, 0, 0, 0, 0, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r3k2r/8/pppppppp/8/8/PPPPPPPP/8/R3K2R w - - 0 0") for file in "abcdefgh": test = self.chess.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) self.check(not test) @@ -715,17 +523,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnDoubleFalseThroughEnemyPiece() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r3k2r/pppppppp/PPPPPPPP/8/8/pppppppp/PPPPPPPP/R3K2R w - - 0 0") for file in "abcdefgh": test = self.chess.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) self.check(not test) @@ -734,17 +532,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnDoubleFalseThroughOwnPiece() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r3k2r/pppppppp/pppppppp/8/8/PPPPPPPP/PPPPPPPP/R3K2R w - - 0 0") for file in "abcdefgh": test = self.chess.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) self.check(not test) @@ -753,17 +541,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnDoubleFalseIntoEnemyPiece() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r3k2r/pppppppp/8/PPPPPPPP/pppppppp/8/PPPPPPPP/R3K2R w - - 0 0") for file in "abcdefgh": test = self.chess.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) self.check(not test) @@ -772,17 +550,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnDoubleFalseIntoOwnPiece() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r3k2r/pppppppp/8/pppppppp/PPPPPPPP/8/PPPPPPPP/R3K2R w - - 0 0") for file in "abcdefgh": test = self.chess.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) self.check(not test) @@ -791,16 +559,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnCaptureTrueWhite() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) + let pos = initChess("r3k2r/8/8/pppppppp/PPPPPPPP/8/8/R3K2R w - - 0 0") var str: string str = "abcdefgh" for ind, file in str: @@ -819,16 +578,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnCaptureTrueBlack() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.Black) + let pos = initChess("r3k2r/8/8/pppppppp/PPPPPPPP/8/8/R3K2R b - - 0 0") var str: string str = "abcdefgh" for ind, file in str: @@ -847,16 +597,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnCaptureFalseWhite() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) + let pos = initChess("r3k2r/8/8/8/PPPPPPPP/8/8/R3K2R w - - 0 0") var str: string str = "abcdefgh" for ind, file in str: @@ -875,16 +616,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnCaptureFalseBlack() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.Black) + let pos = initChess("r3k2r/8/8/pppppppp/8/8/8/R3K2R b - - 0 0") var str: string str = "abcdefgh" for ind, file in str: @@ -903,16 +635,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnEnPassantTrueWhite() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) + let pos = initChess("r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R w - - 0 0") var str: string str = "abcdefgh" for ind, file in str: @@ -953,16 +676,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnEnPassantTrueBlack() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.Black) + let pos = initChess("r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b - - 0 0") var str: string str = "abcdefgh" for ind, file in str: @@ -1003,16 +717,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnEnPassantFalseWhite() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) + let pos = initChess("r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R w - - 0 0") var str: string str = "abcdefgh" for ind, file in str: @@ -1053,16 +758,7 @@ testSuite ChessTest of TestSuite: method testCheckedMovePawnEnPassantFalseBlack() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.Black) + let pos = initChess("r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b - - 0 0") var str: string str = "abcdefgh" for ind, file in str: @@ -1104,16 +800,7 @@ testSuite ChessTest of TestSuite: ## Tests for King moves method testCheckedMoveKingCastleTrueWhite() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) + let pos = initChess("r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R w KQkq - 0 0") self.chess = pos test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(test) @@ -1123,16 +810,7 @@ testSuite ChessTest of TestSuite: method testCheckedMoveKingCastleTrueBlack() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.Black) + let pos = initChess("r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b KQkq - 0 0") self.chess = pos test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) self.check(test) @@ -1142,16 +820,10 @@ testSuite ChessTest of TestSuite: method testCheckedMoveKingCastleFalseAlreadyMovedKing() = var test: bool - let pos = initChess([ - WRook, 0, 0, 0, WKing, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, 0, 0, BKing, 0, 0, BRook - ], Color.White) + var pos = initChess("r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b KQkq - 0 0") + pos.checkedMove(notationToMove("e8d8", Color.Black)) + pos.checkedMove(notationToMove("e1d1", Color.White)) + self.chess = pos self.chess.checkedMove(notationToMove("d1e1", Color.White)) self.chess.checkedMove(notationToMove("d8e8", Color.White)) self.chess = pos @@ -1166,16 +838,11 @@ testSuite ChessTest of TestSuite: method testCheckedMoveKingCastleFalseAlreadyMovedRook() = var test: bool - let pos = initChess([ - 0, WRook, 0, WKing, 0, 0, WRook, 0, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - 0, BRook, 0, BKing, 0, 0, BRook, 0 - ], Color.White) + var pos = initChess("r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R w KQkq - 0 0") + pos.checkedMove(notationToMove("a1b1", Color.White)) + pos.checkedMove(notationToMove("a8b8", Color.Black)) + pos.checkedMove(notationToMove("h1g1", Color.White)) + pos.checkedMove(notationToMove("h8g8", Color.Black)) self.chess = pos self.chess.checkedMove(notationToMove("b1a1", Color.White)) self.chess.checkedMove(notationToMove("b8a8", Color.Black)) @@ -1192,148 +859,85 @@ testSuite ChessTest of TestSuite: method testCheckedMoveKingCastleFalseThroughCheck() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, WPawn, BRook, WPawn, BRook, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, WRook, BPawn, WRook, BPawn, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r3k2r/pppRpRpp/8/8/8/8/PPPrPrPP/R3K2R w KQkq - 0 0") test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) - self.check(not test) self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) + self.chess = initChess("r3k2r/pppRpRpp/8/8/8/8/PPPrPrPP/R3K2R b KQkq - 0 0") + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) + self.check(not test) test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingCastleFalseIntoCheck() = var test: bool - let pos = initChess([ - WRook, 0, 0, WKing, 0, 0, 0, WRook, - WPawn, BRook, WPawn, WPawn, WPawn, BRook, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, WRook, BPawn, BPawn, BPawn, WRook, BPawn, BPawn, - BRook, 0, 0, BKing, 0, 0, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r3k2r/ppRpppRp/8/8/8/8/PPrPPPrP/R3K2R w KQkq - 0 0") test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) - self.check(not test) self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) + self.chess = initChess("r3k2r/ppRpppRp/8/8/8/8/PPrPPPrP/R3K2R b KQkq - 0 0") test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) + self.check(not test) method testCheckedMoveKingCastleFalseThroughOwnPiece() = var test: bool - let pos = initChess([ - WRook, 0, WBishop, WKing, WBishop, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, BBishop, BKing, BBishop, 0, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r2bkb1r/pppppppp/8/8/8/8/PPPPPPPP/R2BKB1R w KQkq - 0 0") test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) - self.check(not test) self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) + self.chess = initChess("r2bkb1r/pppppppp/8/8/8/8/PPPPPPPP/R2BKB1R b KQkq - 0 0") + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) + self.check(not test) test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingCastleFalseThroughEnemyPiece() = var test: bool - let pos = initChess([ - WRook, 0, BBishop, WKing, BBishop, 0, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, 0, WBishop, BKing, WBishop, 0, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r2BkB1r/pppppppp/8/8/8/8/PPPPPPPP/R2bKb1R w KQkq - 0 0") test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) - self.check(not test) self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) + self.chess = initChess("r2BkB1r/pppppppp/8/8/8/8/PPPPPPPP/R2bKb1R b KQkq - 0 0") + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) + self.check(not test) test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingCastleFalseIntoOwnPiece() = var test: bool - let pos = initChess([ - WRook, WBishop, 0, WKing, 0, WBishop, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, BBishop, 0, BKing, 0, BBishop, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r1b1k1br/pppppppp/8/8/8/8/PPPPPPPP/R1b1K1bR w KQkq - 0 0") test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) - self.check(not test) self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) + self.chess = initChess("r1b1k1br/pppppppp/8/8/8/8/PPPPPPPP/R1b1K1bR b KQkq - 0 0") + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) + self.check(not test) test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingCastleFalseIntoEnemyPiece() = var test: bool - let pos = initChess([ - WRook, BBishop, 0, WKing, 0, BBishop, 0, WRook, - WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, - BRook, WBishop, 0, BKing, 0, WBishop, 0, BRook - ], Color.White) - self.chess = pos + self.chess = initChess("r1B1k1Br/pppppppp/8/8/8/8/PPPPPPPP/R1B1K1BR w KQkq - 0 0") test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) - self.check(not test) self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) + self.chess = initChess("r1B1k1Br/pppppppp/8/8/8/8/PPPPPPPP/R1B1K1BR b KQkq - 0 0") + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) + self.check(not test) test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingWhite() = var test: bool - let pos = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, WEnPassant, 0, 0, 0, - 0, 0, BPawn, WKing, WPawn, 0, 0, 0, - 0, 0, BEnPassant, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - ], Color.White) + let pos = initChess("8/8/8/3PKp2/8/8/8/8 w - f6 0 0") let start = "e5" let legalMoves = ["f4", "d4", "f5", "f6", "e6", "d6"] let str = "abcdefgh" @@ -1350,16 +954,7 @@ testSuite ChessTest of TestSuite: method testCheckedMoveKingBlack() = var test: bool - let pos = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, BEnPassant, 0, 0, 0, - 0, 0, WPawn, BKing, BPawn, 0, 0, 0, - 0, 0, WEnPassant, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - ], Color.Black) + let pos = initChess("8/8/8/3pkP2/8/8/8/8 b - f6 0 0") let start = "e5" let legalMoves = ["f4", "d4", "f5", "f6", "e4", "d6"] let str = "abcdefgh" @@ -1377,16 +972,7 @@ testSuite ChessTest of TestSuite: ## Tests for Bishop moves method testCheckedMoveBishopWhite() = var test: bool - let pos = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, BEnPassant, 0, WPawn, 0, 0, - 0, 0, 0, 0, WBishop, 0, 0, 0, - 0, 0, 0, BPawn, 0, WEnPassant, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - ], Color.White) + let pos = initChess("8/8/4p3/3B4/2P5/8/8/8 w - c6 0 0") let start = "d5" let legalMoves = ["e4", "f3", "g2", "h1", "c6", "b7", "a8", "e6"] let str = "abcdefgh" @@ -1403,16 +989,7 @@ testSuite ChessTest of TestSuite: method testCheckedMoveBishopBlack() = var test: bool - let pos = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WEnPassant, 0, BPawn, 0, 0, - 0, 0, 0, 0, BBishop, 0, 0, 0, - 0, 0, 0, WPawn, 0, BEnPassant, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - ], Color.Black) + let pos = initChess("8/8/4P3/3b4/2p5/8/8/8 b - c6 0 0") let start = "d5" let legalMoves = ["e4", "f3", "g2", "h1", "c6", "b7", "a8", "e6"] let str = "abcdefgh" @@ -1430,16 +1007,7 @@ testSuite ChessTest of TestSuite: ## Tests for Knight moves method testCheckedMoveKnightWhite() = var test: bool - let pos = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, WEnPassant, 0, WPawn, 0, 0, - 0, 0, BEnPassant, 0, 0, 0, 0, 0, - 0, 0, 0, 0, WKnight, 0, 0, 0, - 0, 0, BPawn, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - ], Color.White) + let pos = initChess("8/8/5p2/3N4/8/2P5/8/8 w - f4 0 0") let start = "d5" let legalMoves = ["f6", "f4", "e3", "b4", "b6", "c7", "e7"] let str = "abcdefgh" @@ -1456,16 +1024,7 @@ testSuite ChessTest of TestSuite: method testCheckedMoveKnightBlack() = var test: bool - let pos = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, BEnPassant, 0, BPawn, 0, 0, - 0, 0, WEnPassant, 0, 0, 0, 0, 0, - 0, 0, 0, 0, BKnight, 0, 0, 0, - 0, 0, WPawn, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - ], Color.Black) + let pos = initChess("8/8/5P2/3n4/8/2p5/8/8 b - f4 0 0") let start = "d5" let legalMoves = ["f6", "f4", "e3", "b4", "b6", "c7", "e7"] let str = "abcdefgh" @@ -1483,16 +1042,7 @@ testSuite ChessTest of TestSuite: ## Tests for Rook moves method testCheckedMoveRookWhite() = var test: bool - let pos = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, WPawn, 0, 0, 0, - 0, 0, 0, BPawn, WRook, WEnPassant, 0, 0, - 0, 0, 0, 0, BEnPassant, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - ], Color.White) + let pos = initChess("8/8/8/3Rp3/3P4/8/8/8 w - c6 0 0") let start = "d5" let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5"] let str = "abcdefgh" @@ -1509,16 +1059,7 @@ testSuite ChessTest of TestSuite: method testCheckedMoveRookBlack() = var test: bool - let pos = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, BPawn, 0, 0, 0, - 0, 0, 0, WPawn, BRook, BEnPassant, 0, 0, - 0, 0, 0, 0, WEnPassant, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - ], Color.Black) + let pos = initChess("8/8/8/3rP3/3p4/8/8/8 b - c6 0 0") let start = "d5" let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5"] let str = "abcdefgh" @@ -1536,16 +1077,7 @@ testSuite ChessTest of TestSuite: ## Tests for Queen moves method testCheckedMoveQueenWhite() = var test: bool - let pos = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, WPawn, 0, 0, 0, - 0, 0, 0, BPawn, WQueen, WEnPassant, 0, 0, - 0, 0, 0, 0, BEnPassant, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - ], Color.White) + let pos = initChess("8/8/8/3Qp3/3P4/8/8/8 w - c6 0 0") let start = "d5" let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5", "h1", "g2", "f3", "e4", "c4", "b3", "a2", "g8", "f7", "e6", "c6", "b7", "a8"] @@ -1563,16 +1095,7 @@ testSuite ChessTest of TestSuite: method testCheckedMoveQueenBlack() = var test: bool - let pos = initChess([ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, BPawn, 0, 0, 0, - 0, 0, 0, WPawn, BQueen, BEnPassant, 0, 0, - 0, 0, 0, 0, WEnPassant, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - ], Color.Black) + let pos = initChess("8/8/8/3qP3/3p4/8/8/8 b - c6 0 0") let start = "d5" let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5", "h1", "g2", "f3", "e4", "c4", "b3", "a2", "g8", "f7", "e6", "c6", "b7", "a8"] diff --git a/src/engine.nim b/src/engine.nim index 7e01b69..6869e13 100644 --- a/src/engine.nim +++ b/src/engine.nim @@ -184,7 +184,7 @@ proc bestMove*(chess: Chess, depth: int): Move = var tmpChess = chess tmpChess.checkedMove(move) var tmpEval = -tmpChess.negaMax(depth, LoVal, HiVal) - echo("move:", moveToNotation(move, tmpChess.board), "; eval:", tmpEval) + #echo("move:", moveToNotation(move, tmpChess.board), "; eval:", tmpEval) if tmpEval > bestEval: bestEval = tmpEval bestMove = move