From 10098da82f027796afbeecd0852b4e6059c68d57 Mon Sep 17 00:00:00 2001 From: TiynGER Date: Sat, 1 May 2021 16:21:30 +0200 Subject: [PATCH] refactoring: renaming classes and functions Renamed the 'game' type to 'chess' to make more sense of the existing filestructure. Doubled functions where removed. --- src/chess.nim | 482 +++++---- src/chessTest.nim | 1262 ++++++++++++------------ src/engine.nim | 54 +- src/engineTest.nim | 34 +- src/game.nim | 48 +- src/{lichess.nim => lichessBridge.nim} | 19 +- 6 files changed, 937 insertions(+), 962 deletions(-) rename src/{lichess.nim => lichessBridge.nim} (81%) diff --git a/src/chess.nim b/src/chess.nim index 61d12f8..5e70044 100644 --- a/src/chess.nim +++ b/src/chess.nim @@ -14,8 +14,8 @@ type wq: bool # `wq` describes White queenside castle bk: bool # `bk` describes Black kingside castle bq: bool # `bq` describes Black queenside castle - Game* = object - ## `Game` stores all important information of a chess game. + Chess* = object + ## `Chess` stores all important information of a chess chess. board*: Board toMove*: Color previousBoard: seq[Board] @@ -36,6 +36,7 @@ type b: int # `b` describes the amount of bishops. r: int # `r` describes the amount of rooks. q: int # `q` describes the amount of queens. + Pieces = array[10,int] const Block* = 999 ## \ @@ -103,8 +104,8 @@ const ## from whites perspective that are ttacks. InsufficientMaterial: array[4, PieceAmount] = [ (0, 0, 0, 0, 0), # only kings - (0, 0, 1, 0, 0), # knight only - (0, 1, 0, 0, 0), # bishop only + (0, 0, 1, 0, 0), # bishop only + (0, 1, 0, 0, 0), # knight only (0, 2, 0, 0, 0) # 2 knights ] ## `InsufficientMaterial` describes the pieces where no checkmate can be ## forced @@ -141,19 +142,13 @@ let # `FileChar` maps the files of the chessboard to numbers for better # conversion. -proc fieldToInd*(file: string, line: int): int = - ## Calculate and return board index from `file` and `line` of a chess board. - ## Returns -1 if the `field` was not input correct. - try: - return 1+(line+1)*10+(7-FileChar[file]) - except IndexDefect, ValueError: - return -1 - proc fieldToInd*(field: string): int = ## Calculate and return board index from `field` of a chess board. ## Returns -1 if the `field` was not input correct. try: - return fieldToInd($field[0], parseInt($field[1])) + var file = $field[0] + var line = parseInt($field[1]) + return 1+(line+1)*10+(7-FileChar[file]) except IndexDefect, ValueError: return -1 @@ -257,15 +252,15 @@ proc initBoard(board: array[0..63, int]): Board = Block, Block, Block, Block, Block, Block, Block, Block, Block, Block] return board -proc initGame*(): Game = - ## Create and return a Game object. - let game = Game(board: initBoard(), +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)) - return game + return chess -proc initGame*(board: array[0..63, int], color: Color): Game = - ## Create and return a Game object based on a position of choice. +proc initChess*(board: array[0..63, 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) let compare = initBoard() @@ -286,69 +281,69 @@ proc initGame*(board: array[0..63, int], color: Color): Game = bk = true for ind in board.low..board.high: same_piece = (board[ind] != compare[ind]) - let game = Game(board: board, + let chess = Chess(board: board, to_move: color, previousBoard: @[], previousCastleRights: @[], fiftyMoveCounter: 0, castleRights: (wk, wq, bk, bq)) - return game + return chess -proc echoBoard*(game: Game, color: Color) = +proc echoBoard*(chess: Chess, color: Color) = ## Prints out the given `board` with its pieces as characters and line ## indices from perspecive of `color`. var line_str = "" if (color == Color.Black): - for i in countup(0, len(game.board)-1): - if (game.board[i] == 999): + for i in countup(0, len(chess.board)-1): + if (chess.board[i] == 999): continue - line_str &= PieceChar[game.board[i]] & " " + line_str &= PieceChar[chess.board[i]] & " " if ((i+2) %% 10 == 0): line_str &= $((int)((i)/10)-1) & "\n" echo line_str echo "h g f e d c b a" else: - for i in countdown(len(game.board)-1, 0): - if (game.board[i] == 999): + for i in countdown(len(chess.board)-1, 0): + if (chess.board[i] == 999): continue - line_str &= PieceChar[game.board[i]] & " " + line_str &= PieceChar[chess.board[i]] & " " if ((i-1) %% 10 == 0): line_str &= $((int)((i)/10)-1) & "\n" echo line_str echo "a b c d e f g h" -proc genPawnAttackDests(game: Game, field: int, color: Color): seq[int] = +proc genPawnAttackDests(chess: Chess, field: int, color: Color): seq[int] = ## Generate possible attack destinations for a pawn with specific `color` - ## located at index `field` of `game`. + ## located at index `field` of `chess`. ## Returns a sequence of possible indices to move to. - if (not field in game.board.low..game.board.high): + if (not field in chess.board.low..chess.board.high): return @[] var res = newSeq[int]() var dest: int var target: int for attacks in Pawn_Moves_White_Attack: dest = field + (attacks * ord(color)) - if (not dest in game.board.low..game.board.high): + if (not dest in chess.board.low..chess.board.high): continue - target = game.board[dest] + target = chess.board[dest] if (target == 999 or ord(color) * target >= 0): continue res.add(dest) return res -proc genPawnDoubleDests(game: Game, field: int, color: Color): seq[int] = +proc genPawnDoubleDests(chess: Chess, field: int, color: Color): seq[int] = ## Generate possible double destinations for a pawn with specific `color` - ## located at index `field` of `game`. + ## located at index `field` of `chess`. ## Returns a sequence of possible indices to move to. - if (not field in game.board.low..game.board.high): + if (not field in chess.board.low..chess.board.high): return @[] var res = newSeq[int]() var dest: int var target: int for doubles in Pawn_Moves_White_Double: dest = field + doubles * ord(color) - if (not dest in game.board.low..game.board.high): + if (not dest in chess.board.low..chess.board.high): continue - target = game.board[dest] + target = chess.board[dest] if ((target != 0) or ( - game.board[dest+(S*ord(color))] != 0)): + chess.board[dest+(S*ord(color))] != 0)): continue if (color == Color.White and not (field in fieldToInd("h2")..fieldToInd("a2"))): continue @@ -357,120 +352,120 @@ proc genPawnDoubleDests(game: Game, field: int, color: Color): seq[int] = res.add(dest) return res -proc genPawnDests(game: Game, field: int, color: Color): seq[int] = +proc genPawnDests(chess: Chess, field: int, color: Color): seq[int] = ## Generate possible destinations for a pawn with specific `color` located at - ## index `field` of `game`. + ## index `field` of `chess`. ## Returns a sequence of possible indices to move to. - if (not field in game.board.low..game.board.high): + if (not field in chess.board.low..chess.board.high): return @[] var res = newSeq[int]() var dest: int var target: int for move in Pawn_Moves_White: dest = field + move * ord(color) - if (not dest in game.board.low..game.board.high): + if (not dest in chess.board.low..chess.board.high): continue - target = game.board[dest] + target = chess.board[dest] if (target != 0 and target != ord(color) * WEnPassant): continue res.add(dest) - res.add(game.genPawnAttackDests(field, color)) - res.add(game.genPawnDoubleDests(field, color)) + res.add(chess.genPawnAttackDests(field, color)) + res.add(chess.genPawnDoubleDests(field, color)) return res -proc genKnightDests(game: Game, field: int, color: Color): seq[int] = +proc genKnightDests(chess: Chess, field: int, color: Color): seq[int] = ## Generate possible destinations for a knight with specific `color` located - ## at index `field` of `game`. + ## at index `field` of `chess`. ## Returns a sequence of possible indices to move to. - if (not field in game.board.low..game.board.high): + if (not field in chess.board.low..chess.board.high): return @[] var res = newSeq[int]() var dest: int var target: int for move in Knight_Moves: dest = field + move - if (not dest in game.board.low..game.board.high): + if (not dest in chess.board.low..chess.board.high): continue - target = game.board[dest] + target = chess.board[dest] if (target == 999 or (ord(color) * target > 0 and ord(color) * target != WEnPassant)): continue res.add(dest) return res -proc genBishopDests(game: Game, field: int, color: Color): seq[int] = +proc genBishopDests(chess: Chess, field: int, color: Color): seq[int] = ## Generate possible destinations for a bishop with specific `color` located - ## at index `field` of `game`. + ## at index `field` of `chess`. ## Returns a sequence of possible indices to move to. - if (not field in game.board.low..game.board.high): + if (not field in chess.board.low..chess.board.high): return @[] var res = newSeq[int]() var dest: int var target: int for move in Bishop_Moves: dest = field+move - if (not dest in game.board.low..game.board.high): + if (not dest in chess.board.low..chess.board.high): continue - target = game.board[dest] + target = chess.board[dest] while (target != 999 and (ord(color) * target <= 0) or target == WEnPassant or target == -WEnPassant): res.add(dest) if (ord(color) * target < 0 and ord(color) * target > -WEnPassant): break dest = dest+move - target = game.board[dest] + target = chess.board[dest] return res -proc genRookDests(game: Game, field: int, color: Color): seq[int] = +proc genRookDests(chess: Chess, field: int, color: Color): seq[int] = ## Generate possible destinations for a rook with specific `color` located at - ## index `field` of `game`. + ## index `field` of `chess`. ## Returns a sequence of possible indices to move to. - if (not field in game.board.low..game.board.high): + if (not field in chess.board.low..chess.board.high): return @[] var res = newSeq[int]() var dest: int var target: int for move in Rook_Moves: dest = field+move - if (not dest in game.board.low..game.board.high): + if (not dest in chess.board.low..chess.board.high): continue - target = game.board[dest] + target = chess.board[dest] while (target != 999 and (ord(color) * target <= 0) or target == WEnPassant or target == -WEnPassant): res.add(dest) if (ord(color) * target < 0 and ord(color) * target > -WEnPassant): break dest = dest+move - target = game.board[dest] + target = chess.board[dest] return res -proc genQueenDests(game: Game, field: int, color: Color): seq[int] = +proc genQueenDests(chess: Chess, field: int, color: Color): seq[int] = ## Generate possible destinations for a queen with specific `color` located - ## at index `field` of `game`. + ## at index `field` of `chess`. ## Returns a sequence of possible indices to move to. - if (not field in game.board.low..game.board.high): + if (not field in chess.board.low..chess.board.high): return @[] var res = newSeq[int]() var dest: int var target: int for move in Queen_Moves: dest = field+move - if (not dest in game.board.low..game.board.high): + if (not dest in chess.board.low..chess.board.high): continue - target = game.board[dest] + target = chess.board[dest] while (target != 999 and (ord(color) * target <= 0) or target == WEnPassant or target == -WEnPassant): res.add(dest) if (ord(color) * target < 0 and ord(color) * target > -WEnPassant): break dest = dest+move - target = game.board[dest] + target = chess.board[dest] return res -proc genKingCastleDest(game: Game, field: int, color: Color): seq[int] = +proc genKingCastleDest(chess: Chess, field: int, color: Color): seq[int] = ## Generate possible castle destinations for a king with specific `color` - ## located at index `field` of `game` + ## located at index `field` of `chess` ## Returns a sequence of possible indices to move to. - if (not field in game.board.low..game.board.high): + if (not field in chess.board.low..chess.board.high): return @[] var res = newSeq[int]() var dest: int @@ -479,11 +474,11 @@ proc genKingCastleDest(game: Game, field: int, color: Color): seq[int] = var half_target: int for castle in King_Moves_White_Castle: dest = field + castle - if (not dest in game.board.low..game.board.high): + if (not dest in chess.board.low..chess.board.high): continue - target = game.board[dest] + target = chess.board[dest] half_dest = field + (int)castle/2 - half_target = game.board[half_dest] + half_target = chess.board[half_dest] if (target == 999 or (target != 0)): continue if (half_target == 999 or (half_target != 0)): @@ -491,90 +486,90 @@ proc genKingCastleDest(game: Game, field: int, color: Color): seq[int] = res.add(dest) return res -proc genKingDests(game: Game, field: int, color: Color): seq[int] = +proc genKingDests(chess: Chess, field: int, color: Color): seq[int] = ## Generate possible destinations for a king with specific `color` - ## located at index `field` of `game`. + ## located at index `field` of `chess`. ## Returns a sequence of possible indices to move to. - if (not field in game.board.low..game.board.high): + if (not field in chess.board.low..chess.board.high): return @[] var res = newSeq[int]() var dest: int var target: int for move in King_Moves: dest = field + move - if (not dest in game.board.low..game.board.high): + if (not dest in chess.board.low..chess.board.high): continue - target = game.board[dest] + target = chess.board[dest] if (target == 999 or (ord(color) * target > 0 and ord(color) * target != WEnPassant)): continue res.add(dest) - res.add(game.genKingCastleDest(field, color)) + res.add(chess.genKingCastleDest(field, color)) return res -proc pieceOn(game: Game, color: Color, sequence: seq[int], +proc pieceOn(chess: Chess, color: Color, sequence: seq[int], pieceID: int): bool = ## Returns true if the `PieceID` of a given `color` is in `sequence` else ## wrong. for check in sequence: - if game.board[check] == ord(color) * -1 * pieceID: + if chess.board[check] == ord(color) * -1 * pieceID: return true return false -proc isAttacked(game: Game, position: int, color: Color): bool = - ## Returns true if a `position` in a `game` is attacked by the opposite +proc isAttacked(chess: Chess, position: int, color: Color): bool = + ## Returns true if a `position` in a `chess` is attacked by the opposite ## color of `color`. var attacked = false - attacked = attacked or game.pieceOn(color, game.genPawnAttackDests( + attacked = attacked or chess.pieceOn(color, chess.genPawnAttackDests( position, color), WPawn) - attacked = attacked or game.pieceOn(color, game.genQueenDests(position, + attacked = attacked or chess.pieceOn(color, chess.genQueenDests(position, color), WQueen) - attacked = attacked or game.pieceOn(color, game.genKingDests(position, + attacked = attacked or chess.pieceOn(color, chess.genKingDests(position, color), WKing) - attacked = attacked or game.pieceOn(color, game.genRookDests(position, + attacked = attacked or chess.pieceOn(color, chess.genRookDests(position, color), WRook) - attacked = attacked or game.pieceOn(color, game.genBishopDests(position, + attacked = attacked or chess.pieceOn(color, chess.genBishopDests(position, color), WBishop) - attacked = attacked or game.pieceOn(color, game.genKnightDests(position, + attacked = attacked or chess.pieceOn(color, chess.genKnightDests(position, color), WKnight) return attacked -proc isInCheck*(game: Game, color: Color): bool = - ## Returns true if the king of a given `color` is in check in a `game`. +proc isInCheck*(chess: Chess, color: Color): bool = + ## Returns true if the king of a given `color` is in check in a `chess`. var king_pos: int - for i in countup(0, game.board.high): - if game.board[i] == ord(color) * WKing: + for i in countup(0, chess.board.high): + if chess.board[i] == ord(color) * WKing: king_pos = i - return game.isAttacked(king_pos, color) + return chess.isAttacked(king_pos, color) -proc uncheckedMove(game: var Game, start: int, dest: int): bool {.discardable.} = +proc uncheckedMove(chess: var Chess, start: int, dest: int): bool {.discardable.} = ## Moves a piece if possible from `start` position to `dest` position in a - ## `game`. - let piece = game.board[start] - game.board[start] = 0 - game.board[dest] = piece + ## `chess`. + let piece = chess.board[start] + chess.board[start] = 0 + chess.board[dest] = piece if (start == fieldToInd("e1") or start == fieldToInd("a1")): - game.castleRights.wq = false + chess.castleRights.wq = false if (start == fieldToInd("e1") or start == fieldToInd("h1")): - game.castleRights.wk = false + chess.castleRights.wk = false if (start == fieldToInd("e8") or start == fieldToInd("a8")): - game.castleRights.bq = false + chess.castleRights.bq = false if (start == fieldToInd("e8") or start == fieldToInd("h8")): - game.castleRights.bk = false + chess.castleRights.bk = false if (dest == fieldToInd("e1") or dest == fieldToInd("a1")): - game.castleRights.wq = false + chess.castleRights.wq = false if (dest == fieldToInd("e1") or dest == fieldToInd("h1")): - game.castleRights.wk = false + chess.castleRights.wk = false if (dest == fieldToInd("e8") or dest == fieldToInd("a8")): - game.castleRights.bq = false + chess.castleRights.bq = false if (dest == fieldToInd("e8") or dest == fieldToInd("h8")): - game.castleRights.bk = false + chess.castleRights.bk = false return true -proc moveLeadsToCheck(game: Game, start: int, dest: int, +proc moveLeadsToCheck(chess: Chess, start: int, dest: int, color: Color): bool = - ## Returns true if a move from `start` to `dest` in a `game` puts the `color` + ## Returns true if a move from `start` to `dest` in a `chess` puts the `color` ## king in check. - var check = game + var check = chess check.uncheckedMove(start, dest) return check.isInCheck(color) @@ -588,15 +583,15 @@ proc genPawnPromotion(move: Move, color: Color): seq[Move] = promotions.add(getMove(start, dest, piece, color)) return promotions -proc genLegalPawnMoves(game: Game, field: int, color: Color): seq[Move] = - ## Generates all legal pawn moves in a `game` starting from `field` for a +proc genLegalPawnMoves(chess: Chess, field: int, color: Color): seq[Move] = + ## Generates all legal pawn moves in a `chess` starting from `field` for a ## `color`. - if game.board[field] != WPawn * ord(color): + if chess.board[field] != WPawn * ord(color): return @[] var res = newSeq[Move]() - var moves = game.genPawnDests(field, color) + var moves = chess.genPawnDests(field, color) for dest in moves: - if not game.moveLeadsToCheck(field, dest, color): + if not chess.moveLeadsToCheck(field, dest, color): var promotions = genPawnPromotion(getMove(field, dest, color), color) if promotions != @[]: res.add(promotions) @@ -604,107 +599,107 @@ proc genLegalPawnMoves(game: Game, field: int, color: Color): seq[Move] = res.add(getMove(field, dest, color)) return res -proc genLegalKnightMoves(game: Game, field: int, color: Color): seq[Move] = - ## Generates all legal knight moves in a `game` starting from `field` for a +proc genLegalKnightMoves(chess: Chess, field: int, color: Color): seq[Move] = + ## Generates all legal knight moves in a `chess` starting from `field` for a ## `color`. - if game.board[field] != WKnight * ord(color): + if chess.board[field] != WKnight * ord(color): return @[] var res = newSeq[Move]() - var moves = game.genKnightDests(field, color) + var moves = chess.genKnightDests(field, color) for dest in moves: - if not game.moveLeadsToCheck(field, dest, color): + if not chess.moveLeadsToCheck(field, dest, color): res.add(getMove(field, dest, color)) return res -proc genLegalBishopMoves(game: Game, field: int, color: Color): seq[Move] = - ## Generates all legal bishop moves in a `game` starting from `field` for a +proc genLegalBishopMoves(chess: Chess, field: int, color: Color): seq[Move] = + ## Generates all legal bishop moves in a `chess` starting from `field` for a ## `color`. - if game.board[field] != WBishop * ord(color): + if chess.board[field] != WBishop * ord(color): return @[] var res = newSeq[Move]() - var moves = game.genBishopDests(field, color) + var moves = chess.genBishopDests(field, color) for dest in moves: - if not game.moveLeadsToCheck(field, dest, color): + if not chess.moveLeadsToCheck(field, dest, color): res.add(getMove(field, dest, color)) return res -proc genLegalRookMoves(game: Game, field: int, color: Color): seq[Move] = - ## Generates all legal rook moves in a `game` starting from `field` for a +proc genLegalRookMoves(chess: Chess, field: int, color: Color): seq[Move] = + ## Generates all legal rook moves in a `chess` starting from `field` for a ## `color`. - if game.board[field] != WRook * ord(color): + if chess.board[field] != WRook * ord(color): return @[] var res = newSeq[Move]() - var moves = game.genRookDests(field, color) + var moves = chess.genRookDests(field, color) for dest in moves: - if not game.moveLeadsToCheck(field, dest, color): + if not chess.moveLeadsToCheck(field, dest, color): res.add(getMove(field, dest, color)) return res -proc genLegalQueenMoves(game: Game, field: int, color: Color): seq[Move] = - ## Generates all legal queen moves in a `game` starting from `field` for a +proc genLegalQueenMoves(chess: Chess, field: int, color: Color): seq[Move] = + ## Generates all legal queen moves in a `chess` starting from `field` for a ## `color`. - if game.board[field] != WQueen * ord(color): + if chess.board[field] != WQueen * ord(color): return @[] var res = newSeq[Move]() - var moves = game.genQueenDests(field, color) + var moves = chess.genQueenDests(field, color) for dest in moves: - if not game.moveLeadsToCheck(field, dest, color): + if not chess.moveLeadsToCheck(field, dest, color): res.add(getMove(field, dest, color)) return res -proc genLegalKingMoves(game: Game, field: int, color: Color): seq[Move] = - ## Generates all legal king moves in a `game` starting from `field` for a +proc genLegalKingMoves(chess: Chess, field: int, color: Color): seq[Move] = + ## Generates all legal king moves in a `chess` starting from `field` for a ## `color`. - if game.board[field] != WKing * ord(color): + if chess.board[field] != WKing * ord(color): return @[] var res = newSeq[Move]() - var moves = game.genKingDests(field, color) + var moves = chess.genKingDests(field, color) for dest in moves: - if field - dest == W+W and game.isAttacked(dest+W, color): + if field - dest == W+W and chess.isAttacked(dest+W, color): continue - if field - dest == E+E and game.isAttacked(dest+E, color): + if field - dest == E+E and chess.isAttacked(dest+E, color): continue - if not game.moveLeadsToCheck(field, dest, color): + if not chess.moveLeadsToCheck(field, dest, color): res.add(getMove(field, dest, color)) return res -proc genLegalMoves*(game: Game, field: int, color: Color): seq[Move] = - ## Generates all legal moves in a `game` starting from `field` for a `color`. +proc genLegalMoves*(chess: Chess, field: int, color: Color): seq[Move] = + ## Generates all legal moves in a `chess` starting from `field` for a `color`. var legal_moves = newSeq[Move]() - var target = ord(color) * game.board[field] + var target = ord(color) * chess.board[field] if 0 < target and target < WEnPassant: legal_moves = case target: of WPawn: - game.genLegalPawnMoves(field, color) + chess.genLegalPawnMoves(field, color) of WKnight: - game.genLegalKnightMoves(field, color) + chess.genLegalKnightMoves(field, color) of WBishop: - game.genLegalBishopMoves(field, color) + chess.genLegalBishopMoves(field, color) of WRook: - game.genLegalRookMoves(field, color) + chess.genLegalRookMoves(field, color) of WQueen: - game.genLegalQueenMoves(field, color) + chess.genLegalQueenMoves(field, color) of WKing: - game.genLegalKingMoves(field, color) + chess.genLegalKingMoves(field, color) else: @[] return legal_moves -proc genLegalMoves*(game: Game, color: Color): seq[Move] = - ## Generates all legal moves in a `game` for a `color`. +proc genLegalMoves*(chess: Chess, color: Color): seq[Move] = + ## Generates all legal moves in a `chess` for a `color`. var legal_moves = newSeq[Move]() - for field in game.board.low..game.board.high: - legal_moves.add(game.genLegalMoves(field, color)) + for field in chess.board.low..chess.board.high: + legal_moves.add(chess.genLegalMoves(field, color)) return legal_moves -proc castling(game: var Game, kstart: int, dest_kingside: bool, +proc castling(chess: var Chess, kstart: int, dest_kingside: bool, color: Color): bool {.discardable.} = - ## Tries to castle in a given `game` with the king of a given `color` from + ## Tries to castle in a given `chess` with the king of a given `color` from ## `kstart`. ## `dest_kingside` for kingside castling, else castling is queenside. ## This process checks for the legality of the move and performs the switch - ## of `game.to_move` - if game.toMove != color: + ## of `chess.to_move` + if chess.toMove != color: return false var kdest = kstart var rstart: int @@ -715,32 +710,32 @@ proc castling(game: var Game, kstart: int, dest_kingside: bool, rstart = kstart + (E+E+E) rdest = rstart + (W+W) if (color == Color.White): - rights = game.castleRights.wk + rights = chess.castleRights.wk else: - rights = game.castleRights.bk + rights = chess.castleRights.bk else: rstart = kstart + (W+W+W+W) rdest = rstart + (E+E+E) kdest = kstart + (W+W) if (color == Color.White): - rights = game.castleRights.bq + rights = chess.castleRights.bq else: - rights = game.castleRights.bq + rights = chess.castleRights.bq if (rights): var check = false if (dest_kingside): - check = check or game.isAttacked(kstart, color) - check = check or game.isAttacked(kstart+(E), color) - check = check or game.isAttacked(kstart+(E+E), color) + check = check or chess.isAttacked(kstart, color) + check = check or chess.isAttacked(kstart+(E), color) + check = check or chess.isAttacked(kstart+(E+E), color) else: - check = check or game.isAttacked(kstart, color) - check = check or game.isAttacked(kstart+(W), color) - check = check or game.isAttacked(kstart+(W+W), color) + check = check or chess.isAttacked(kstart, color) + check = check or chess.isAttacked(kstart+(W), color) + check = check or chess.isAttacked(kstart+(W+W), color) if check: return false - game.uncheckedMove(kstart, kdest) - game.uncheckedMove(rstart, rdest) - game.toMove = Color(ord(game.toMove)*(-1)) + chess.uncheckedMove(kstart, kdest) + chess.uncheckedMove(rstart, rdest) + chess.toMove = Color(ord(chess.toMove)*(-1)) return true return false @@ -750,128 +745,105 @@ proc removeEnPassant(board: var Board, color: Color): void = if board[field] == ord(color) * WEnPassant: board[field] = 0 -proc checkedMove*(game: var Game, move: Move): bool {.discardable.} = - ## Tries to make a `move` in a given `game``. +proc checkedMove*(chess: var Chess, move: Move): bool {.discardable.} = + ## Tries to make a `move` in a given `chess``. ## This process checks for the legality of the move and performs the switch - ## of `game.to_move` with exception of castling (castling() switches). + ## of `chess.to_move` with exception of castling (castling() switches). let start = move.start let dest = move.dest let color = move.color let prom = move.prom - if (game.toMove != color or start == -1 or dest == -1): + if (chess.toMove != color or start == -1 or dest == -1): return false var sequence = newSeq[Move]() - let piece = game.board[start] + let piece = chess.board[start] var createEnPassant = false var capturedEnPassant = false var fiftyMoveRuleReset = false var move: Move move = getMove(start, dest, color) if (piece == WPawn * ord(color)): - createEnPassant = dest in game.genPawnDoubleDests(start, color) - capturedEnPassant = (game.board[dest] == -1 * ord(color) * WEnPassant) + createEnPassant = dest in chess.genPawnDoubleDests(start, color) + capturedEnPassant = (chess.board[dest] == -1 * ord(color) * WEnPassant) fiftyMoveRuleReset = true - if (game.board[move.dest] != 0): + if (chess.board[move.dest] != 0): fiftyMoveRuleReset = true - sequence.add(game.genLegalMoves(start, color)) + sequence.add(chess.genLegalMoves(start, color)) + # TODO: don't generate all legal moves, just check if result is legal and reachable if (move in sequence): - game.board.removeEnPassant(color) + chess.board.removeEnPassant(color) if (piece == WKing * ord(color) and (start - dest == (W+W))): - return game.castling(start, true, color) + return chess.castling(start, true, color) elif (piece == WKing * ord(color) and (start - dest == (E+E))): - return game.castling(start, false, color) + return chess.castling(start, false, color) else: - game.uncheckedMove(start, dest) - game.toMove = Color(ord(game.toMove)*(-1)) + chess.uncheckedMove(start, dest) + chess.toMove = Color(ord(chess.toMove)*(-1)) if createEnPassant: - game.board[dest-(N*ord(color))] = WEnPassant * ord(color) + chess.board[dest-(N*ord(color))] = WEnPassant * ord(color) if capturedEnPassant: - game.board[dest-(N*ord(color))] = 0 + chess.board[dest-(N*ord(color))] = 0 if ((90 < dest and dest < 99) or (20 < dest and dest < 29)) and - game.board[dest] == WPawn * ord(color): - game.board[dest] = prom - var prevBoard = game.previousBoard - var prevCastle = game.previousCastleRights - game.previousBoard.add(game.board) - game.previousCastleRights.add(game.castleRights) - game.fiftyMoveCounter = game.fiftyMoveCounter + 1 + chess.board[dest] == WPawn * ord(color): + chess.board[dest] = prom + var prevBoard = chess.previousBoard + var prevCastle = chess.previousCastleRights + chess.previousBoard.add(chess.board) + chess.previousCastleRights.add(chess.castleRights) + chess.fiftyMoveCounter = chess.fiftyMoveCounter + 1 if fiftyMoveRuleReset: - game.fiftyMoveCounter = 0 + chess.fiftyMoveCounter = 0 return true -proc hasNoMoves(game: Game, color: Color): bool = - ## Returns true if the `color` player has no legal moves in a `game`. - return (game.genLegalMoves(color) == @[]) +proc hasNoMoves(chess: Chess, color: Color): bool = + ## Returns true if the `color` player has no legal moves in a `chess`. + return (chess.genLegalMoves(color) == @[]) -proc isCheckmate*(game: Game, color: Color): bool = - ## Returns true if the `color` player is checkmate in a `game`. - return game.hasNoMoves(color) and game.isInCheck(color) +proc isCheckmate*(chess: Chess, color: Color): bool = + ## Returns true if the `color` player is checkmate in a `chess`. + return chess.hasNoMoves(color) and chess.isInCheck(color) -proc threeMoveRep(game: Game): bool = +proc threeMoveRep(chess: Chess): bool = ## Returns true if a 3-fold repitition happened on the last move of the - ## `game`. - if game.previousBoard == []: + ## `chess`. + if chess.previousBoard == []: return false - var lastState = game.previousBoard[game.previousBoard.high] - var lastCastleRights = game.previousCastleRights[game.previousBoard.high] + var lastState = chess.previousBoard[chess.previousBoard.high] + var lastCastleRights = chess.previousCastleRights[chess.previousBoard.high] var reps = 0 - for stateInd in (game.previousBoard.low)..(game.previousBoard.high): - if (game.previousBoard[stateInd] == lastState and game.previousCastleRights[ + for stateInd in (chess.previousBoard.low)..(chess.previousBoard.high): + if (chess.previousBoard[stateInd] == lastState and chess.previousCastleRights[ stateInd] == lastCastleRights): reps = reps + 1 return reps >= 3 -proc fiftyMoveRule(game: Game): bool = - ## Returns true if a draw can be claimed by the 50 move rule in a `game`. - return game.fiftyMoveCounter >= 100 +proc fiftyMoveRule(chess: Chess): bool = + ## Returns true if a draw can be claimed by the 50 move rule in a `chess`. + return chess.fiftyMoveCounter >= 100 -proc isDrawClaimable*(game: Game): bool = +proc isDrawClaimable*(chess: Chess): bool = ## Returns true if a draw is claimable by either player. - return game.threeMoveRep() or game.fiftyMoveRule() + return chess.threeMoveRep() or chess.fiftyMoveRule() proc checkInsufficientMaterial(board: Board): bool = ## Checks for combinations of pieces on a `board`, where no checkmate can be ## forced. ## Returns true if no player can force a checkmate to the other. - var wp = 0 - var wn = 0 - var wb = 0 - var wr = 0 - var wq = 0 - var bp = 0 - var bn = 0 - var bb = 0 - var br = 0 - var bq = 0 + var pieces: Pieces for field in board.low..board.high: - case board[field]: - of WPawn: - wp += 1 - of BPawn: - bp += 1 - of WKnight: - wn += 1 - of BKnight: - bn += 1 - of WBishop: - wb += 1 - of BBishop: - bb += 1 - of WRook: - wr += 1 - of BRook: - br += 1 - of WQueen: - wq += 1 - of BQueen: - bq += 1 - else: - continue - let wpieces: PieceAmount = (wp, wn, wb, wr, wq) - let bpieces: PieceAmount = (bp, bn, bb, br, bq) + var piece = board[field] + var index: int + if piece >= WPawn and piece <= WRook: + index = piece - WPawn # map lowest value to 0 + pieces[index] += 1 + elif piece <= BPawn and piece >= BRook: + index = WRook - piece # map black pieces after whites + pieces[index] += 1 + let wpieces: PieceAmount = (pieces[0], pieces[1], pieces[2], pieces[3], pieces[4]) + let bpieces: PieceAmount = (pieces[5], pieces[6], pieces[7], pieces[8], pieces[9]) return (wpieces in InsufficientMaterial) and (bpieces in InsufficientMaterial) -proc isStalemate*(game: Game, color: Color): bool = - ## Returns true if the `color` player is stalemate in a `game`. - return (game.hasNoMoves(color) and not game.isInCheck(color)) or - game.board.checkInsufficientMaterial() +proc isStalemate*(chess: Chess, color: Color): bool = + ## Returns true if the `color` player is stalemate in a `chess`. + return (chess.hasNoMoves(color) and not chess.isInCheck(color)) or + chess.board.checkInsufficientMaterial() diff --git a/src/chessTest.nim b/src/chessTest.nim index 543afdc..9a8ee2d 100644 --- a/src/chessTest.nim +++ b/src/chessTest.nim @@ -1,89 +1,89 @@ import einheit import algorithm -import ./chess +import ./chess.nim -testSuite GameTest of TestSuite: +testSuite ChessTest of TestSuite: var - game: Game + chess: Chess method setup() = - self.game = initGame() + self.chess = initChess() ## Tests for isInCheck() method testIsInCheckFalse() = self.setup() - self.game.checkedMove(notationToMove("e2e4", Color.White)) - self.game.checkedMove(notationToMove("e7e5", Color.Black)) - self.game.checkedMove(notationToMove("d2d3", Color.White)) - self.game.checkedMove(notationToMove("d8h4", Color.Black)) - self.check(not self.game.isInCheck(Color.White)) - self.check(not self.game.isInCheck(Color.White)) + self.chess.checkedMove(notationToMove("e2e4", Color.White)) + self.chess.checkedMove(notationToMove("e7e5", Color.Black)) + self.chess.checkedMove(notationToMove("d2d3", Color.White)) + self.chess.checkedMove(notationToMove("d8h4", Color.Black)) + self.check(not self.chess.isInCheck(Color.White)) + self.check(not self.chess.isInCheck(Color.White)) method testIsInCheckTrueWhite() = self.setup() - self.game.checkedMove(notationToMove("f2f4", Color.White)) - self.game.checkedMove(notationToMove("e7e5", Color.Black)) - self.game.checkedMove(notationToMove("e2e3", Color.White)) - self.game.checkedMove(notationToMove("d8h4", Color.Black)) - self.check(self.game.isInCheck(Color.White)) + self.chess.checkedMove(notationToMove("f2f4", Color.White)) + self.chess.checkedMove(notationToMove("e7e5", Color.Black)) + self.chess.checkedMove(notationToMove("e2e3", Color.White)) + self.chess.checkedMove(notationToMove("d8h4", Color.Black)) + self.check(self.chess.isInCheck(Color.White)) method testIsInCheckTrueBlack() = self.setup() - self.game.checkedMove(notationToMove("e2e4", Color.White)) - self.game.checkedMove(notationToMove("f7f6", Color.Black)) - self.game.checkedMove(notationToMove("d2d4", Color.White)) - self.game.checkedMove(notationToMove("g7g5", Color.Black)) - self.game.checkedMove(notationToMove("d1h5", Color.White)) - self.check(self.game.isInCheck(Color.Black)) + self.chess.checkedMove(notationToMove("e2e4", Color.White)) + self.chess.checkedMove(notationToMove("f7f6", Color.Black)) + self.chess.checkedMove(notationToMove("d2d4", Color.White)) + self.chess.checkedMove(notationToMove("g7g5", Color.Black)) + self.chess.checkedMove(notationToMove("d1h5", Color.White)) + self.check(self.chess.isInCheck(Color.Black)) ## Tests for isCheckmate() method testIsCheckmateFalseWhite() = self.setup() - self.game.checkedMove(notationToMove("f2f4", Color.White)) - self.game.checkedMove(notationToMove("e7e5", Color.Black)) - self.game.checkedMove(notationToMove("e2e3", Color.White)) - self.game.checkedMove(notationToMove("d8h4", Color.Black)) - self.check(not self.game.isCheckmate(Color.White)) + self.chess.checkedMove(notationToMove("f2f4", Color.White)) + self.chess.checkedMove(notationToMove("e7e5", Color.Black)) + self.chess.checkedMove(notationToMove("e2e3", Color.White)) + self.chess.checkedMove(notationToMove("d8h4", Color.Black)) + self.check(not self.chess.isCheckmate(Color.White)) method testIsCheckmateFalseBlack() = self.setup() - self.game.checkedMove(notationToMove("f2f4", Color.White)) - self.game.checkedMove(notationToMove("e7e5", Color.Black)) - self.game.checkedMove(notationToMove("e2e3", Color.White)) - self.game.checkedMove(notationToMove("d8h4", Color.Black)) - self.check(not self.game.isCheckmate(Color.Black)) + self.chess.checkedMove(notationToMove("f2f4", Color.White)) + self.chess.checkedMove(notationToMove("e7e5", Color.Black)) + self.chess.checkedMove(notationToMove("e2e3", Color.White)) + self.chess.checkedMove(notationToMove("d8h4", Color.Black)) + self.check(not self.chess.isCheckmate(Color.Black)) method testIsCheckmateTrueWhite() = self.setup() - self.game.checkedMove(notationToMove("f2f3", Color.White)) - self.game.checkedMove(notationToMove("e7e6", Color.Black)) - self.game.checkedMove(notationToMove("g2g4", Color.White)) - self.game.checkedMove(notationToMove("d8h4", Color.Black)) - self.check(self.game.isCheckmate(Color.White)) + self.chess.checkedMove(notationToMove("f2f3", Color.White)) + self.chess.checkedMove(notationToMove("e7e6", Color.Black)) + self.chess.checkedMove(notationToMove("g2g4", Color.White)) + self.chess.checkedMove(notationToMove("d8h4", Color.Black)) + self.check(self.chess.isCheckmate(Color.White)) method testIsCheckmateTrueBlack() = self.setup() - self.game.checkedMove(notationToMove("e2e4", Color.White)) - self.game.checkedMove(notationToMove("g7g5", Color.Black)) - self.game.checkedMove(notationToMove("d2d4", Color.White)) - self.game.checkedMove(notationToMove("f7f6", Color.Black)) - self.game.checkedMove(notationToMove("d1h5", Color.White)) - self.check(self.game.isCheckmate(Color.Black)) + self.chess.checkedMove(notationToMove("e2e4", Color.White)) + self.chess.checkedMove(notationToMove("g7g5", Color.Black)) + self.chess.checkedMove(notationToMove("d2d4", Color.White)) + self.chess.checkedMove(notationToMove("f7f6", Color.Black)) + self.chess.checkedMove(notationToMove("d1h5", Color.White)) + self.check(self.chess.isCheckmate(Color.Black)) ## Tests for isStalemate() method testIsStalemateFalse() = self.setup() - self.game.checkedMove(notationToMove("f2f3", Color.White)) - self.game.checkedMove(notationToMove("e7e6", Color.Black)) - self.game.checkedMove(notationToMove("g2g4", Color.White)) - self.game.checkedMove(notationToMove("d8h4", Color.Black)) - self.check(not self.game.isStalemate(Color.White)) - self.check(not self.game.isStalemate(Color.Black)) + self.chess.checkedMove(notationToMove("f2f3", Color.White)) + self.chess.checkedMove(notationToMove("e7e6", Color.Black)) + self.chess.checkedMove(notationToMove("g2g4", Color.White)) + self.chess.checkedMove(notationToMove("d8h4", Color.Black)) + self.check(not self.chess.isStalemate(Color.White)) + self.check(not self.chess.isStalemate(Color.Black)) method testIsStalemateTrueWhite() = - self.game = initGame([ + 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, @@ -93,10 +93,10 @@ testSuite GameTest of TestSuite: 0, BPawn, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.White) - self.check(self.game.isStalemate(Color.White)) + self.check(self.chess.isStalemate(Color.White)) method testIsStalemateTrueBlack() = - self.game = initGame([ + 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, @@ -106,10 +106,10 @@ testSuite GameTest of TestSuite: 0, WPawn, WKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(self.game.isStalemate(Color.Black)) + self.check(self.chess.isStalemate(Color.Black)) method testIsStalemateInsufficientMaterialTrue() = - self.game = initGame([ + 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, @@ -119,9 +119,9 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(self.game.isStalemate(Color.Black)) - self.check(self.game.isStalemate(Color.White)) - self.game = initGame([ + 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, @@ -131,9 +131,9 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(self.game.isStalemate(Color.Black)) - self.check(self.game.isStalemate(Color.White)) - self.game = initGame([ + 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, @@ -143,9 +143,9 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(self.game.isStalemate(Color.Black)) - self.check(self.game.isStalemate(Color.White)) - self.game = initGame([ + 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, @@ -155,9 +155,9 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(self.game.isStalemate(Color.Black)) - self.check(self.game.isStalemate(Color.White)) - self.game = initGame([ + 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, @@ -167,9 +167,9 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(self.game.isStalemate(Color.Black)) - self.check(self.game.isStalemate(Color.White)) - self.game = initGame([ + 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, @@ -179,9 +179,9 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(self.game.isStalemate(Color.Black)) - self.check(self.game.isStalemate(Color.White)) - self.game = initGame([ + 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, @@ -191,11 +191,11 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(self.game.isStalemate(Color.Black)) - self.check(self.game.isStalemate(Color.White)) + self.check(self.chess.isStalemate(Color.Black)) + self.check(self.chess.isStalemate(Color.White)) method testIsStalemateInsufficientMaterialFalse() = - self.game = initGame([ + 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, @@ -205,9 +205,9 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(not self.game.isStalemate(Color.Black)) - self.check(not self.game.isStalemate(Color.White)) - self.game = initGame([ + 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, @@ -217,9 +217,9 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(not self.game.isStalemate(Color.Black)) - self.check(not self.game.isStalemate(Color.White)) - self.game = initGame([ + 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, @@ -229,9 +229,9 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(not self.game.isStalemate(Color.Black)) - self.check(not self.game.isStalemate(Color.White)) - self.game = initGame([ + 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, @@ -241,9 +241,9 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(not self.game.isStalemate(Color.Black)) - self.check(not self.game.isStalemate(Color.White)) - self.game = initGame([ + 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, @@ -253,9 +253,9 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(not self.game.isStalemate(Color.Black)) - self.check(not self.game.isStalemate(Color.White)) - self.game = initGame([ + 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, @@ -265,37 +265,37 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - self.check(not self.game.isStalemate(Color.Black)) - self.check(not self.game.isStalemate(Color.White)) + self.check(not self.chess.isStalemate(Color.Black)) + self.check(not self.chess.isStalemate(Color.White)) ## Check isDrawClaimable method testIsDrawClaimableThreeFoldRepTrue() = self.setup() - self.game.checkedMove(notationToMove("g1f3", Color.White)) - self.game.checkedMove(notationToMove("g8f6", Color.Black)) - self.game.checkedMove(notationToMove("f3g1", Color.White)) - self.game.checkedMove(notationToMove("f6g8", Color.Black)) - self.game.checkedMove(notationToMove("g1f3", Color.White)) - self.game.checkedMove(notationToMove("g8f6", Color.Black)) - self.game.checkedMove(notationToMove("f3g1", Color.White)) - self.game.checkedMove(notationToMove("f6g8", Color.Black)) - self.game.checkedMove(notationToMove("g1f3", Color.White)) - self.check(self.game.isDrawClaimable()) + self.chess.checkedMove(notationToMove("g1f3", Color.White)) + self.chess.checkedMove(notationToMove("g8f6", Color.Black)) + self.chess.checkedMove(notationToMove("f3g1", Color.White)) + self.chess.checkedMove(notationToMove("f6g8", Color.Black)) + self.chess.checkedMove(notationToMove("g1f3", Color.White)) + self.chess.checkedMove(notationToMove("g8f6", Color.Black)) + self.chess.checkedMove(notationToMove("f3g1", Color.White)) + self.chess.checkedMove(notationToMove("f6g8", Color.Black)) + self.chess.checkedMove(notationToMove("g1f3", Color.White)) + self.check(self.chess.isDrawClaimable()) method testIsDrawClaimableThreeFoldRepFalse() = self.setup() - self.game.checkedMove(notationToMove("g1f3", Color.White)) - self.game.checkedMove(notationToMove("g8f6", Color.Black)) - self.game.checkedMove(notationToMove("f3g1", Color.White)) - self.game.checkedMove(notationToMove("f6g8", Color.Black)) - self.game.checkedMove(notationToMove("g1f3", Color.White)) - self.game.checkedMove(notationToMove("g8f6", Color.Black)) - self.game.checkedMove(notationToMove("f3g1", Color.White)) - self.game.checkedMove(notationToMove("f6g8", Color.Black)) - self.check(not self.game.isDrawClaimable()) + self.chess.checkedMove(notationToMove("g1f3", Color.White)) + self.chess.checkedMove(notationToMove("g8f6", Color.Black)) + self.chess.checkedMove(notationToMove("f3g1", Color.White)) + self.chess.checkedMove(notationToMove("f6g8", Color.Black)) + self.chess.checkedMove(notationToMove("g1f3", Color.White)) + self.chess.checkedMove(notationToMove("g8f6", Color.Black)) + self.chess.checkedMove(notationToMove("f3g1", Color.White)) + self.chess.checkedMove(notationToMove("f6g8", Color.Black)) + self.check(not self.chess.isDrawClaimable()) method testIsDrawClaimableFiftyMoveRuleTrue() = - self.game = initGame([ + 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, @@ -305,110 +305,110 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, 0, WRook, 0, 0, 0, 0, BKing, 0, 0, 0, 0 ], Color.Black) - self.game.checkedMove(notationToMove("a2a5", Color.Black)) - self.game.checkedMove(notationToMove("f5g6", Color.White)) - self.game.checkedMove(notationToMove("a5e5", Color.Black)) - self.game.checkedMove(notationToMove("h4f6", Color.White)) - self.game.checkedMove(notationToMove("e5e2", Color.Black)) - self.game.checkedMove(notationToMove("b7a7", Color.White)) - self.game.checkedMove(notationToMove("e2e1", Color.Black)) - self.game.checkedMove(notationToMove("g6f5", Color.White)) - self.game.checkedMove(notationToMove("e1b1", Color.Black)) - self.game.checkedMove(notationToMove("f6d4", Color.White)) - self.game.checkedMove(notationToMove("e8d8", Color.Black)) - self.game.checkedMove(notationToMove("f5e6", Color.White)) - self.game.checkedMove(notationToMove("d8c8", Color.Black)) - self.game.checkedMove(notationToMove("d4e5", Color.White)) - self.game.checkedMove(notationToMove("b1c1", Color.Black)) - self.game.checkedMove(notationToMove("a7f7", Color.White)) - self.game.checkedMove(notationToMove("c1c2", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("c2c1", Color.Black)) - self.game.checkedMove(notationToMove("e6d5", Color.White)) - self.game.checkedMove(notationToMove("c1a1", Color.Black)) - self.game.checkedMove(notationToMove("f7h7", Color.White)) - self.game.checkedMove(notationToMove("a1a2", Color.Black)) - self.game.checkedMove(notationToMove("d6f4", Color.White)) - self.game.checkedMove(notationToMove("a2a6", Color.Black)) - self.game.checkedMove(notationToMove("f4e5", Color.White)) - self.game.checkedMove(notationToMove("a6b6", Color.Black)) - self.game.checkedMove(notationToMove("h7c7", Color.White)) - self.game.checkedMove(notationToMove("c8d8", Color.Black)) - self.game.checkedMove(notationToMove("c7a7", Color.White)) - self.game.checkedMove(notationToMove("d8c8", Color.Black)) - self.game.checkedMove(notationToMove("a7c7", Color.White)) - self.game.checkedMove(notationToMove("c8d8", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("b6b1", Color.Black)) - self.game.checkedMove(notationToMove("c7a7", Color.White)) - self.game.checkedMove(notationToMove("b1e1", Color.Black)) - self.game.checkedMove(notationToMove("d6e5", Color.White)) - self.game.checkedMove(notationToMove("e1d1", Color.Black)) - self.game.checkedMove(notationToMove("d5e6", Color.White)) - self.game.checkedMove(notationToMove("d1c1", Color.Black)) - self.game.checkedMove(notationToMove("a7b7", Color.White)) - self.game.checkedMove(notationToMove("c1c2", Color.Black)) - self.game.checkedMove(notationToMove("b7b3", Color.White)) - self.game.checkedMove(notationToMove("c2c6", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("c6c1", Color.Black)) - self.game.checkedMove(notationToMove("b3h3", Color.White)) - self.game.checkedMove(notationToMove("d8c8", Color.Black)) - self.game.checkedMove(notationToMove("h3h8", Color.White)) - self.game.checkedMove(notationToMove("c8b7", Color.Black)) - self.game.checkedMove(notationToMove("h8b8", Color.White)) - self.game.checkedMove(notationToMove("b7a7", Color.Black)) - self.game.checkedMove(notationToMove("b8b4", Color.White)) - self.game.checkedMove(notationToMove("c1d1", Color.Black)) - self.game.checkedMove(notationToMove("e6d7", Color.White)) - self.game.checkedMove(notationToMove("d1c1", Color.Black)) - self.game.checkedMove(notationToMove("d6c7", Color.White)) - self.game.checkedMove(notationToMove("c1h1", Color.Black)) - self.game.checkedMove(notationToMove("c7f4", Color.White)) - self.game.checkedMove(notationToMove("h1h3", Color.Black)) - self.game.checkedMove(notationToMove("f4e5", Color.White)) - self.game.checkedMove(notationToMove("h3h1", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("h1c1", Color.Black)) - self.game.checkedMove(notationToMove("d6f4", Color.White)) - self.game.checkedMove(notationToMove("c1c2", Color.Black)) - self.game.checkedMove(notationToMove("f4c7", Color.White)) - self.game.checkedMove(notationToMove("c2c1", Color.Black)) - self.game.checkedMove(notationToMove("b4b5", Color.White)) - self.game.checkedMove(notationToMove("c1c2", Color.Black)) - self.game.checkedMove(notationToMove("b5b6", Color.White)) - self.game.checkedMove(notationToMove("c2g2", Color.Black)) - self.game.checkedMove(notationToMove("b6b3", Color.White)) - self.game.checkedMove(notationToMove("g2c2", Color.Black)) - self.game.checkedMove(notationToMove("b3b1", Color.White)) - self.game.checkedMove(notationToMove("c2c3", Color.Black)) - self.game.checkedMove(notationToMove("c7e5", Color.White)) - self.game.checkedMove(notationToMove("c3c2", Color.Black)) - self.game.checkedMove(notationToMove("d7d6", Color.White)) - self.game.checkedMove(notationToMove("c2d2", Color.Black)) - self.game.checkedMove(notationToMove("d6c6", Color.White)) - self.game.checkedMove(notationToMove("d2c2", Color.Black)) - self.game.checkedMove(notationToMove("c6d5", Color.White)) - self.game.checkedMove(notationToMove("c2g2", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("g2g5", Color.Black)) - self.game.checkedMove(notationToMove("d5c6", Color.White)) - self.game.checkedMove(notationToMove("a7a6", Color.Black)) - self.game.checkedMove(notationToMove("b1b8", Color.White)) - self.game.checkedMove(notationToMove("g5g7", Color.Black)) - self.game.checkedMove(notationToMove("b8b6", Color.White)) - self.game.checkedMove(notationToMove("a6a7", Color.Black)) - self.game.checkedMove(notationToMove("b6b1", Color.White)) - self.game.checkedMove(notationToMove("a7a8", Color.Black)) - self.game.checkedMove(notationToMove("b1e1", Color.White)) - self.game.checkedMove(notationToMove("g7b7", Color.Black)) - self.game.checkedMove(notationToMove("e1e8", Color.White)) - self.game.checkedMove(notationToMove("a8a7", Color.Black)) - self.game.checkedMove(notationToMove("d6c5", Color.White)) - self.check(self.game.isDrawClaimable()) + self.chess.checkedMove(notationToMove("a2a5", Color.Black)) + self.chess.checkedMove(notationToMove("f5g6", Color.White)) + self.chess.checkedMove(notationToMove("a5e5", Color.Black)) + self.chess.checkedMove(notationToMove("h4f6", Color.White)) + self.chess.checkedMove(notationToMove("e5e2", Color.Black)) + self.chess.checkedMove(notationToMove("b7a7", Color.White)) + self.chess.checkedMove(notationToMove("e2e1", Color.Black)) + self.chess.checkedMove(notationToMove("g6f5", Color.White)) + self.chess.checkedMove(notationToMove("e1b1", Color.Black)) + self.chess.checkedMove(notationToMove("f6d4", Color.White)) + self.chess.checkedMove(notationToMove("e8d8", Color.Black)) + self.chess.checkedMove(notationToMove("f5e6", Color.White)) + self.chess.checkedMove(notationToMove("d8c8", Color.Black)) + self.chess.checkedMove(notationToMove("d4e5", Color.White)) + self.chess.checkedMove(notationToMove("b1c1", Color.Black)) + self.chess.checkedMove(notationToMove("a7f7", Color.White)) + self.chess.checkedMove(notationToMove("c1c2", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("c2c1", Color.Black)) + self.chess.checkedMove(notationToMove("e6d5", Color.White)) + self.chess.checkedMove(notationToMove("c1a1", Color.Black)) + self.chess.checkedMove(notationToMove("f7h7", Color.White)) + self.chess.checkedMove(notationToMove("a1a2", Color.Black)) + self.chess.checkedMove(notationToMove("d6f4", Color.White)) + self.chess.checkedMove(notationToMove("a2a6", Color.Black)) + self.chess.checkedMove(notationToMove("f4e5", Color.White)) + self.chess.checkedMove(notationToMove("a6b6", Color.Black)) + self.chess.checkedMove(notationToMove("h7c7", Color.White)) + self.chess.checkedMove(notationToMove("c8d8", Color.Black)) + self.chess.checkedMove(notationToMove("c7a7", Color.White)) + self.chess.checkedMove(notationToMove("d8c8", Color.Black)) + self.chess.checkedMove(notationToMove("a7c7", Color.White)) + self.chess.checkedMove(notationToMove("c8d8", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("b6b1", Color.Black)) + self.chess.checkedMove(notationToMove("c7a7", Color.White)) + self.chess.checkedMove(notationToMove("b1e1", Color.Black)) + self.chess.checkedMove(notationToMove("d6e5", Color.White)) + self.chess.checkedMove(notationToMove("e1d1", Color.Black)) + self.chess.checkedMove(notationToMove("d5e6", Color.White)) + self.chess.checkedMove(notationToMove("d1c1", Color.Black)) + self.chess.checkedMove(notationToMove("a7b7", Color.White)) + self.chess.checkedMove(notationToMove("c1c2", Color.Black)) + self.chess.checkedMove(notationToMove("b7b3", Color.White)) + self.chess.checkedMove(notationToMove("c2c6", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("c6c1", Color.Black)) + self.chess.checkedMove(notationToMove("b3h3", Color.White)) + self.chess.checkedMove(notationToMove("d8c8", Color.Black)) + self.chess.checkedMove(notationToMove("h3h8", Color.White)) + self.chess.checkedMove(notationToMove("c8b7", Color.Black)) + self.chess.checkedMove(notationToMove("h8b8", Color.White)) + self.chess.checkedMove(notationToMove("b7a7", Color.Black)) + self.chess.checkedMove(notationToMove("b8b4", Color.White)) + self.chess.checkedMove(notationToMove("c1d1", Color.Black)) + self.chess.checkedMove(notationToMove("e6d7", Color.White)) + self.chess.checkedMove(notationToMove("d1c1", Color.Black)) + self.chess.checkedMove(notationToMove("d6c7", Color.White)) + self.chess.checkedMove(notationToMove("c1h1", Color.Black)) + self.chess.checkedMove(notationToMove("c7f4", Color.White)) + self.chess.checkedMove(notationToMove("h1h3", Color.Black)) + self.chess.checkedMove(notationToMove("f4e5", Color.White)) + self.chess.checkedMove(notationToMove("h3h1", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("h1c1", Color.Black)) + self.chess.checkedMove(notationToMove("d6f4", Color.White)) + self.chess.checkedMove(notationToMove("c1c2", Color.Black)) + self.chess.checkedMove(notationToMove("f4c7", Color.White)) + self.chess.checkedMove(notationToMove("c2c1", Color.Black)) + self.chess.checkedMove(notationToMove("b4b5", Color.White)) + self.chess.checkedMove(notationToMove("c1c2", Color.Black)) + self.chess.checkedMove(notationToMove("b5b6", Color.White)) + self.chess.checkedMove(notationToMove("c2g2", Color.Black)) + self.chess.checkedMove(notationToMove("b6b3", Color.White)) + self.chess.checkedMove(notationToMove("g2c2", Color.Black)) + self.chess.checkedMove(notationToMove("b3b1", Color.White)) + self.chess.checkedMove(notationToMove("c2c3", Color.Black)) + self.chess.checkedMove(notationToMove("c7e5", Color.White)) + self.chess.checkedMove(notationToMove("c3c2", Color.Black)) + self.chess.checkedMove(notationToMove("d7d6", Color.White)) + self.chess.checkedMove(notationToMove("c2d2", Color.Black)) + self.chess.checkedMove(notationToMove("d6c6", Color.White)) + self.chess.checkedMove(notationToMove("d2c2", Color.Black)) + self.chess.checkedMove(notationToMove("c6d5", Color.White)) + self.chess.checkedMove(notationToMove("c2g2", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("g2g5", Color.Black)) + self.chess.checkedMove(notationToMove("d5c6", Color.White)) + self.chess.checkedMove(notationToMove("a7a6", Color.Black)) + self.chess.checkedMove(notationToMove("b1b8", Color.White)) + self.chess.checkedMove(notationToMove("g5g7", Color.Black)) + self.chess.checkedMove(notationToMove("b8b6", Color.White)) + self.chess.checkedMove(notationToMove("a6a7", Color.Black)) + self.chess.checkedMove(notationToMove("b6b1", Color.White)) + self.chess.checkedMove(notationToMove("a7a8", Color.Black)) + self.chess.checkedMove(notationToMove("b1e1", Color.White)) + self.chess.checkedMove(notationToMove("g7b7", Color.Black)) + self.chess.checkedMove(notationToMove("e1e8", Color.White)) + self.chess.checkedMove(notationToMove("a8a7", Color.Black)) + self.chess.checkedMove(notationToMove("d6c5", Color.White)) + self.check(self.chess.isDrawClaimable()) method testIsDrawClaimableFiftyMoveRuleFalseNinetyFour() = - self.game = initGame([ + 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, @@ -418,110 +418,110 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, 0, WRook, 0, 0, 0, 0, BKing, 0, 0, 0, 0 ], Color.Black) - self.game.checkedMove(notationToMove("a2a5", Color.Black)) - self.game.checkedMove(notationToMove("f5g6", Color.White)) - self.game.checkedMove(notationToMove("a5e5", Color.Black)) - self.game.checkedMove(notationToMove("h4f6", Color.White)) - self.game.checkedMove(notationToMove("e5e2", Color.Black)) - self.game.checkedMove(notationToMove("b7a7", Color.White)) - self.game.checkedMove(notationToMove("e2e1", Color.Black)) - self.game.checkedMove(notationToMove("g6f5", Color.White)) - self.game.checkedMove(notationToMove("e1b1", Color.Black)) - self.game.checkedMove(notationToMove("f6d4", Color.White)) - self.game.checkedMove(notationToMove("e8d8", Color.Black)) - self.game.checkedMove(notationToMove("f5e6", Color.White)) - self.game.checkedMove(notationToMove("d8c8", Color.Black)) - self.game.checkedMove(notationToMove("d4e5", Color.White)) - self.game.checkedMove(notationToMove("b1c1", Color.Black)) - self.game.checkedMove(notationToMove("a7f7", Color.White)) - self.game.checkedMove(notationToMove("c1c2", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("c2c1", Color.Black)) - self.game.checkedMove(notationToMove("e6d5", Color.White)) - self.game.checkedMove(notationToMove("c1a1", Color.Black)) - self.game.checkedMove(notationToMove("f7h7", Color.White)) - self.game.checkedMove(notationToMove("a1a2", Color.Black)) - self.game.checkedMove(notationToMove("d6f4", Color.White)) - self.game.checkedMove(notationToMove("a2a6", Color.Black)) - self.game.checkedMove(notationToMove("f4e5", Color.White)) - self.game.checkedMove(notationToMove("a6b6", Color.Black)) - self.game.checkedMove(notationToMove("h7c7", Color.White)) - self.game.checkedMove(notationToMove("c8d8", Color.Black)) - self.game.checkedMove(notationToMove("c7a7", Color.White)) - self.game.checkedMove(notationToMove("d8c8", Color.Black)) - self.game.checkedMove(notationToMove("a7c7", Color.White)) - self.game.checkedMove(notationToMove("c8d8", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("b6b1", Color.Black)) - self.game.checkedMove(notationToMove("c7a7", Color.White)) - self.game.checkedMove(notationToMove("b1e1", Color.Black)) - self.game.checkedMove(notationToMove("d6e5", Color.White)) - self.game.checkedMove(notationToMove("e1d1", Color.Black)) - self.game.checkedMove(notationToMove("d5e6", Color.White)) - self.game.checkedMove(notationToMove("d1c1", Color.Black)) - self.game.checkedMove(notationToMove("a7b7", Color.White)) - self.game.checkedMove(notationToMove("c1c2", Color.Black)) - self.game.checkedMove(notationToMove("b7b3", Color.White)) - self.game.checkedMove(notationToMove("c2c6", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("c6c1", Color.Black)) - self.game.checkedMove(notationToMove("b3h3", Color.White)) - self.game.checkedMove(notationToMove("d8c8", Color.Black)) - self.game.checkedMove(notationToMove("h3h8", Color.White)) - self.game.checkedMove(notationToMove("c8b7", Color.Black)) - self.game.checkedMove(notationToMove("h8b8", Color.White)) - self.game.checkedMove(notationToMove("b7a7", Color.Black)) - self.game.checkedMove(notationToMove("b8b4", Color.White)) - self.game.checkedMove(notationToMove("c1d1", Color.Black)) - self.game.checkedMove(notationToMove("e6d7", Color.White)) - self.game.checkedMove(notationToMove("d1c1", Color.Black)) - self.game.checkedMove(notationToMove("d6c7", Color.White)) - self.game.checkedMove(notationToMove("c1h1", Color.Black)) - self.game.checkedMove(notationToMove("c7f4", Color.White)) - self.game.checkedMove(notationToMove("h1h3", Color.Black)) - self.game.checkedMove(notationToMove("f4e5", Color.White)) - self.game.checkedMove(notationToMove("h3h1", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("h1c1", Color.Black)) - self.game.checkedMove(notationToMove("d6f4", Color.White)) - self.game.checkedMove(notationToMove("c1c2", Color.Black)) - self.game.checkedMove(notationToMove("f4c7", Color.White)) - self.game.checkedMove(notationToMove("c2c1", Color.Black)) - self.game.checkedMove(notationToMove("b4b5", Color.White)) - self.game.checkedMove(notationToMove("c1c2", Color.Black)) - self.game.checkedMove(notationToMove("b5b6", Color.White)) - self.game.checkedMove(notationToMove("c2g2", Color.Black)) - self.game.checkedMove(notationToMove("b6b3", Color.White)) - self.game.checkedMove(notationToMove("g2c2", Color.Black)) - self.game.checkedMove(notationToMove("b3b1", Color.White)) - self.game.checkedMove(notationToMove("c2c3", Color.Black)) - self.game.checkedMove(notationToMove("c7e5", Color.White)) - self.game.checkedMove(notationToMove("c3c2", Color.Black)) - self.game.checkedMove(notationToMove("d7d6", Color.White)) - self.game.checkedMove(notationToMove("c2d2", Color.Black)) - self.game.checkedMove(notationToMove("d6c6", Color.White)) - self.game.checkedMove(notationToMove("d2c2", Color.Black)) - self.game.checkedMove(notationToMove("c6d5", Color.White)) - self.game.checkedMove(notationToMove("c2g2", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("g2g5", Color.Black)) - self.game.checkedMove(notationToMove("d5c6", Color.White)) - self.game.checkedMove(notationToMove("a7a6", Color.Black)) - self.game.checkedMove(notationToMove("b1b8", Color.White)) - self.game.checkedMove(notationToMove("g5g7", Color.Black)) - self.game.checkedMove(notationToMove("b8b6", Color.White)) - self.game.checkedMove(notationToMove("a6a7", Color.Black)) - self.game.checkedMove(notationToMove("b6b1", Color.White)) - self.game.checkedMove(notationToMove("a7a8", Color.Black)) - self.game.checkedMove(notationToMove("b1e1", Color.White)) - self.game.checkedMove(notationToMove("g7b7", Color.Black)) - self.game.checkedMove(notationToMove("e1e8", Color.White)) - self.game.checkedMove(notationToMove("a8a7", Color.Black)) - self.game.checkedMove(notationToMove("d6c5", Color.White)) - self.check(self.game.isDrawClaimable()) + self.chess.checkedMove(notationToMove("a2a5", Color.Black)) + self.chess.checkedMove(notationToMove("f5g6", Color.White)) + self.chess.checkedMove(notationToMove("a5e5", Color.Black)) + self.chess.checkedMove(notationToMove("h4f6", Color.White)) + self.chess.checkedMove(notationToMove("e5e2", Color.Black)) + self.chess.checkedMove(notationToMove("b7a7", Color.White)) + self.chess.checkedMove(notationToMove("e2e1", Color.Black)) + self.chess.checkedMove(notationToMove("g6f5", Color.White)) + self.chess.checkedMove(notationToMove("e1b1", Color.Black)) + self.chess.checkedMove(notationToMove("f6d4", Color.White)) + self.chess.checkedMove(notationToMove("e8d8", Color.Black)) + self.chess.checkedMove(notationToMove("f5e6", Color.White)) + self.chess.checkedMove(notationToMove("d8c8", Color.Black)) + self.chess.checkedMove(notationToMove("d4e5", Color.White)) + self.chess.checkedMove(notationToMove("b1c1", Color.Black)) + self.chess.checkedMove(notationToMove("a7f7", Color.White)) + self.chess.checkedMove(notationToMove("c1c2", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("c2c1", Color.Black)) + self.chess.checkedMove(notationToMove("e6d5", Color.White)) + self.chess.checkedMove(notationToMove("c1a1", Color.Black)) + self.chess.checkedMove(notationToMove("f7h7", Color.White)) + self.chess.checkedMove(notationToMove("a1a2", Color.Black)) + self.chess.checkedMove(notationToMove("d6f4", Color.White)) + self.chess.checkedMove(notationToMove("a2a6", Color.Black)) + self.chess.checkedMove(notationToMove("f4e5", Color.White)) + self.chess.checkedMove(notationToMove("a6b6", Color.Black)) + self.chess.checkedMove(notationToMove("h7c7", Color.White)) + self.chess.checkedMove(notationToMove("c8d8", Color.Black)) + self.chess.checkedMove(notationToMove("c7a7", Color.White)) + self.chess.checkedMove(notationToMove("d8c8", Color.Black)) + self.chess.checkedMove(notationToMove("a7c7", Color.White)) + self.chess.checkedMove(notationToMove("c8d8", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("b6b1", Color.Black)) + self.chess.checkedMove(notationToMove("c7a7", Color.White)) + self.chess.checkedMove(notationToMove("b1e1", Color.Black)) + self.chess.checkedMove(notationToMove("d6e5", Color.White)) + self.chess.checkedMove(notationToMove("e1d1", Color.Black)) + self.chess.checkedMove(notationToMove("d5e6", Color.White)) + self.chess.checkedMove(notationToMove("d1c1", Color.Black)) + self.chess.checkedMove(notationToMove("a7b7", Color.White)) + self.chess.checkedMove(notationToMove("c1c2", Color.Black)) + self.chess.checkedMove(notationToMove("b7b3", Color.White)) + self.chess.checkedMove(notationToMove("c2c6", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("c6c1", Color.Black)) + self.chess.checkedMove(notationToMove("b3h3", Color.White)) + self.chess.checkedMove(notationToMove("d8c8", Color.Black)) + self.chess.checkedMove(notationToMove("h3h8", Color.White)) + self.chess.checkedMove(notationToMove("c8b7", Color.Black)) + self.chess.checkedMove(notationToMove("h8b8", Color.White)) + self.chess.checkedMove(notationToMove("b7a7", Color.Black)) + self.chess.checkedMove(notationToMove("b8b4", Color.White)) + self.chess.checkedMove(notationToMove("c1d1", Color.Black)) + self.chess.checkedMove(notationToMove("e6d7", Color.White)) + self.chess.checkedMove(notationToMove("d1c1", Color.Black)) + self.chess.checkedMove(notationToMove("d6c7", Color.White)) + self.chess.checkedMove(notationToMove("c1h1", Color.Black)) + self.chess.checkedMove(notationToMove("c7f4", Color.White)) + self.chess.checkedMove(notationToMove("h1h3", Color.Black)) + self.chess.checkedMove(notationToMove("f4e5", Color.White)) + self.chess.checkedMove(notationToMove("h3h1", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("h1c1", Color.Black)) + self.chess.checkedMove(notationToMove("d6f4", Color.White)) + self.chess.checkedMove(notationToMove("c1c2", Color.Black)) + self.chess.checkedMove(notationToMove("f4c7", Color.White)) + self.chess.checkedMove(notationToMove("c2c1", Color.Black)) + self.chess.checkedMove(notationToMove("b4b5", Color.White)) + self.chess.checkedMove(notationToMove("c1c2", Color.Black)) + self.chess.checkedMove(notationToMove("b5b6", Color.White)) + self.chess.checkedMove(notationToMove("c2g2", Color.Black)) + self.chess.checkedMove(notationToMove("b6b3", Color.White)) + self.chess.checkedMove(notationToMove("g2c2", Color.Black)) + self.chess.checkedMove(notationToMove("b3b1", Color.White)) + self.chess.checkedMove(notationToMove("c2c3", Color.Black)) + self.chess.checkedMove(notationToMove("c7e5", Color.White)) + self.chess.checkedMove(notationToMove("c3c2", Color.Black)) + self.chess.checkedMove(notationToMove("d7d6", Color.White)) + self.chess.checkedMove(notationToMove("c2d2", Color.Black)) + self.chess.checkedMove(notationToMove("d6c6", Color.White)) + self.chess.checkedMove(notationToMove("d2c2", Color.Black)) + self.chess.checkedMove(notationToMove("c6d5", Color.White)) + self.chess.checkedMove(notationToMove("c2g2", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("g2g5", Color.Black)) + self.chess.checkedMove(notationToMove("d5c6", Color.White)) + self.chess.checkedMove(notationToMove("a7a6", Color.Black)) + self.chess.checkedMove(notationToMove("b1b8", Color.White)) + self.chess.checkedMove(notationToMove("g5g7", Color.Black)) + self.chess.checkedMove(notationToMove("b8b6", Color.White)) + self.chess.checkedMove(notationToMove("a6a7", Color.Black)) + self.chess.checkedMove(notationToMove("b6b1", Color.White)) + self.chess.checkedMove(notationToMove("a7a8", Color.Black)) + self.chess.checkedMove(notationToMove("b1e1", Color.White)) + self.chess.checkedMove(notationToMove("g7b7", Color.Black)) + self.chess.checkedMove(notationToMove("e1e8", Color.White)) + self.chess.checkedMove(notationToMove("a8a7", Color.Black)) + self.chess.checkedMove(notationToMove("d6c5", Color.White)) + self.check(self.chess.isDrawClaimable()) method testIsDrawClaimableFiftyMoveRuleFalseCapture() = - self.game = initGame([ + 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, @@ -531,125 +531,125 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, 0, WRook, 0, 0, 0, 0, BKing, 0, 0, 0, 0 ], Color.Black) - self.game.checkedMove(notationToMove("a2a5", Color.Black)) - self.game.checkedMove(notationToMove("f5g6", Color.White)) - self.game.checkedMove(notationToMove("a5e5", Color.Black)) - self.game.checkedMove(notationToMove("h4f6", Color.White)) - self.game.checkedMove(notationToMove("e5e2", Color.Black)) - self.game.checkedMove(notationToMove("b7a7", Color.White)) - self.game.checkedMove(notationToMove("e2e1", Color.Black)) - self.game.checkedMove(notationToMove("g6f5", Color.White)) - self.game.checkedMove(notationToMove("e1b1", Color.Black)) - self.game.checkedMove(notationToMove("f6d4", Color.White)) - self.game.checkedMove(notationToMove("e8d8", Color.Black)) - self.game.checkedMove(notationToMove("f5e6", Color.White)) - self.game.checkedMove(notationToMove("d8c8", Color.Black)) - self.game.checkedMove(notationToMove("d4e5", Color.White)) - self.game.checkedMove(notationToMove("b1c1", Color.Black)) - self.game.checkedMove(notationToMove("a7f7", Color.White)) - self.game.checkedMove(notationToMove("c1c2", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("c2c1", Color.Black)) - self.game.checkedMove(notationToMove("e6d5", Color.White)) - self.game.checkedMove(notationToMove("c1a1", Color.Black)) - self.game.checkedMove(notationToMove("f7h7", Color.White)) - self.game.checkedMove(notationToMove("a1a2", Color.Black)) - self.game.checkedMove(notationToMove("d6f4", Color.White)) - self.game.checkedMove(notationToMove("a2a6", Color.Black)) - self.game.checkedMove(notationToMove("f4e5", Color.White)) - self.game.checkedMove(notationToMove("a6b6", Color.Black)) - self.game.checkedMove(notationToMove("h7c7", Color.White)) - self.game.checkedMove(notationToMove("c8d8", Color.Black)) - self.game.checkedMove(notationToMove("c7a7", Color.White)) - self.game.checkedMove(notationToMove("d8c8", Color.Black)) - self.game.checkedMove(notationToMove("a7c7", Color.White)) - self.game.checkedMove(notationToMove("c8d8", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("b6b1", Color.Black)) - self.game.checkedMove(notationToMove("c7a7", Color.White)) - self.game.checkedMove(notationToMove("b1e1", Color.Black)) - self.game.checkedMove(notationToMove("d6e5", Color.White)) - self.game.checkedMove(notationToMove("e1d1", Color.Black)) - self.game.checkedMove(notationToMove("d5e6", Color.White)) - self.game.checkedMove(notationToMove("d1c1", Color.Black)) - self.game.checkedMove(notationToMove("a7b7", Color.White)) - self.game.checkedMove(notationToMove("c1c2", Color.Black)) - self.game.checkedMove(notationToMove("b7b3", Color.White)) - self.game.checkedMove(notationToMove("c2c6", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("c6c1", Color.Black)) - self.game.checkedMove(notationToMove("b3h3", Color.White)) - self.game.checkedMove(notationToMove("d8c8", Color.Black)) - self.game.checkedMove(notationToMove("h3h8", Color.White)) - self.game.checkedMove(notationToMove("c8b7", Color.Black)) - self.game.checkedMove(notationToMove("h8b8", Color.White)) - self.game.checkedMove(notationToMove("b7a7", Color.Black)) - self.game.checkedMove(notationToMove("b8b4", Color.White)) - self.game.checkedMove(notationToMove("c1d1", Color.Black)) - self.game.checkedMove(notationToMove("e6d7", Color.White)) - self.game.checkedMove(notationToMove("d1c1", Color.Black)) - self.game.checkedMove(notationToMove("d6c7", Color.White)) - self.game.checkedMove(notationToMove("c1h1", Color.Black)) - self.game.checkedMove(notationToMove("c7f4", Color.White)) - self.game.checkedMove(notationToMove("h1h3", Color.Black)) - self.game.checkedMove(notationToMove("f4e5", Color.White)) - self.game.checkedMove(notationToMove("h3h1", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("h1c1", Color.Black)) - self.game.checkedMove(notationToMove("d6f4", Color.White)) - self.game.checkedMove(notationToMove("c1c2", Color.Black)) - self.game.checkedMove(notationToMove("f4c7", Color.White)) - self.game.checkedMove(notationToMove("c2c1", Color.Black)) - self.game.checkedMove(notationToMove("b4b5", Color.White)) - self.game.checkedMove(notationToMove("c1c2", Color.Black)) - self.game.checkedMove(notationToMove("b5b6", Color.White)) - self.game.checkedMove(notationToMove("c2g2", Color.Black)) - self.game.checkedMove(notationToMove("b6b3", Color.White)) - self.game.checkedMove(notationToMove("g2c2", Color.Black)) - self.game.checkedMove(notationToMove("b3b1", Color.White)) - self.game.checkedMove(notationToMove("c2c3", Color.Black)) - self.game.checkedMove(notationToMove("c7e5", Color.White)) - self.game.checkedMove(notationToMove("c3c2", Color.Black)) - self.game.checkedMove(notationToMove("d7d6", Color.White)) - self.game.checkedMove(notationToMove("c2d2", Color.Black)) - self.game.checkedMove(notationToMove("d6c6", Color.White)) - self.game.checkedMove(notationToMove("d2c2", Color.Black)) - self.game.checkedMove(notationToMove("c6d5", Color.White)) - self.game.checkedMove(notationToMove("c2g2", Color.Black)) - self.game.checkedMove(notationToMove("e5d6", Color.White)) - self.game.checkedMove(notationToMove("g2g5", Color.Black)) - self.game.checkedMove(notationToMove("d5c6", Color.White)) - self.game.checkedMove(notationToMove("a7a6", Color.Black)) - self.game.checkedMove(notationToMove("b1b8", Color.White)) - self.game.checkedMove(notationToMove("g5g7", Color.Black)) - self.game.checkedMove(notationToMove("b8b6", Color.White)) - self.game.checkedMove(notationToMove("a6a7", Color.Black)) - self.game.checkedMove(notationToMove("b6b1", Color.White)) - self.game.checkedMove(notationToMove("a7a8", Color.Black)) - self.game.checkedMove(notationToMove("b1e1", Color.White)) - self.game.checkedMove(notationToMove("g7b7", Color.Black)) - self.game.checkedMove(notationToMove("e1e8", Color.White)) - self.game.checkedMove(notationToMove("a8a7", Color.Black)) - self.game.checkedMove(notationToMove("d6c5", Color.White)) - self.check(not self.game.isDrawClaimable()) + self.chess.checkedMove(notationToMove("a2a5", Color.Black)) + self.chess.checkedMove(notationToMove("f5g6", Color.White)) + self.chess.checkedMove(notationToMove("a5e5", Color.Black)) + self.chess.checkedMove(notationToMove("h4f6", Color.White)) + self.chess.checkedMove(notationToMove("e5e2", Color.Black)) + self.chess.checkedMove(notationToMove("b7a7", Color.White)) + self.chess.checkedMove(notationToMove("e2e1", Color.Black)) + self.chess.checkedMove(notationToMove("g6f5", Color.White)) + self.chess.checkedMove(notationToMove("e1b1", Color.Black)) + self.chess.checkedMove(notationToMove("f6d4", Color.White)) + self.chess.checkedMove(notationToMove("e8d8", Color.Black)) + self.chess.checkedMove(notationToMove("f5e6", Color.White)) + self.chess.checkedMove(notationToMove("d8c8", Color.Black)) + self.chess.checkedMove(notationToMove("d4e5", Color.White)) + self.chess.checkedMove(notationToMove("b1c1", Color.Black)) + self.chess.checkedMove(notationToMove("a7f7", Color.White)) + self.chess.checkedMove(notationToMove("c1c2", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("c2c1", Color.Black)) + self.chess.checkedMove(notationToMove("e6d5", Color.White)) + self.chess.checkedMove(notationToMove("c1a1", Color.Black)) + self.chess.checkedMove(notationToMove("f7h7", Color.White)) + self.chess.checkedMove(notationToMove("a1a2", Color.Black)) + self.chess.checkedMove(notationToMove("d6f4", Color.White)) + self.chess.checkedMove(notationToMove("a2a6", Color.Black)) + self.chess.checkedMove(notationToMove("f4e5", Color.White)) + self.chess.checkedMove(notationToMove("a6b6", Color.Black)) + self.chess.checkedMove(notationToMove("h7c7", Color.White)) + self.chess.checkedMove(notationToMove("c8d8", Color.Black)) + self.chess.checkedMove(notationToMove("c7a7", Color.White)) + self.chess.checkedMove(notationToMove("d8c8", Color.Black)) + self.chess.checkedMove(notationToMove("a7c7", Color.White)) + self.chess.checkedMove(notationToMove("c8d8", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("b6b1", Color.Black)) + self.chess.checkedMove(notationToMove("c7a7", Color.White)) + self.chess.checkedMove(notationToMove("b1e1", Color.Black)) + self.chess.checkedMove(notationToMove("d6e5", Color.White)) + self.chess.checkedMove(notationToMove("e1d1", Color.Black)) + self.chess.checkedMove(notationToMove("d5e6", Color.White)) + self.chess.checkedMove(notationToMove("d1c1", Color.Black)) + self.chess.checkedMove(notationToMove("a7b7", Color.White)) + self.chess.checkedMove(notationToMove("c1c2", Color.Black)) + self.chess.checkedMove(notationToMove("b7b3", Color.White)) + self.chess.checkedMove(notationToMove("c2c6", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("c6c1", Color.Black)) + self.chess.checkedMove(notationToMove("b3h3", Color.White)) + self.chess.checkedMove(notationToMove("d8c8", Color.Black)) + self.chess.checkedMove(notationToMove("h3h8", Color.White)) + self.chess.checkedMove(notationToMove("c8b7", Color.Black)) + self.chess.checkedMove(notationToMove("h8b8", Color.White)) + self.chess.checkedMove(notationToMove("b7a7", Color.Black)) + self.chess.checkedMove(notationToMove("b8b4", Color.White)) + self.chess.checkedMove(notationToMove("c1d1", Color.Black)) + self.chess.checkedMove(notationToMove("e6d7", Color.White)) + self.chess.checkedMove(notationToMove("d1c1", Color.Black)) + self.chess.checkedMove(notationToMove("d6c7", Color.White)) + self.chess.checkedMove(notationToMove("c1h1", Color.Black)) + self.chess.checkedMove(notationToMove("c7f4", Color.White)) + self.chess.checkedMove(notationToMove("h1h3", Color.Black)) + self.chess.checkedMove(notationToMove("f4e5", Color.White)) + self.chess.checkedMove(notationToMove("h3h1", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("h1c1", Color.Black)) + self.chess.checkedMove(notationToMove("d6f4", Color.White)) + self.chess.checkedMove(notationToMove("c1c2", Color.Black)) + self.chess.checkedMove(notationToMove("f4c7", Color.White)) + self.chess.checkedMove(notationToMove("c2c1", Color.Black)) + self.chess.checkedMove(notationToMove("b4b5", Color.White)) + self.chess.checkedMove(notationToMove("c1c2", Color.Black)) + self.chess.checkedMove(notationToMove("b5b6", Color.White)) + self.chess.checkedMove(notationToMove("c2g2", Color.Black)) + self.chess.checkedMove(notationToMove("b6b3", Color.White)) + self.chess.checkedMove(notationToMove("g2c2", Color.Black)) + self.chess.checkedMove(notationToMove("b3b1", Color.White)) + self.chess.checkedMove(notationToMove("c2c3", Color.Black)) + self.chess.checkedMove(notationToMove("c7e5", Color.White)) + self.chess.checkedMove(notationToMove("c3c2", Color.Black)) + self.chess.checkedMove(notationToMove("d7d6", Color.White)) + self.chess.checkedMove(notationToMove("c2d2", Color.Black)) + self.chess.checkedMove(notationToMove("d6c6", Color.White)) + self.chess.checkedMove(notationToMove("d2c2", Color.Black)) + self.chess.checkedMove(notationToMove("c6d5", Color.White)) + self.chess.checkedMove(notationToMove("c2g2", Color.Black)) + self.chess.checkedMove(notationToMove("e5d6", Color.White)) + self.chess.checkedMove(notationToMove("g2g5", Color.Black)) + self.chess.checkedMove(notationToMove("d5c6", Color.White)) + self.chess.checkedMove(notationToMove("a7a6", Color.Black)) + self.chess.checkedMove(notationToMove("b1b8", Color.White)) + self.chess.checkedMove(notationToMove("g5g7", Color.Black)) + self.chess.checkedMove(notationToMove("b8b6", Color.White)) + self.chess.checkedMove(notationToMove("a6a7", Color.Black)) + self.chess.checkedMove(notationToMove("b6b1", Color.White)) + self.chess.checkedMove(notationToMove("a7a8", Color.Black)) + self.chess.checkedMove(notationToMove("b1e1", Color.White)) + self.chess.checkedMove(notationToMove("g7b7", Color.Black)) + self.chess.checkedMove(notationToMove("e1e8", Color.White)) + self.chess.checkedMove(notationToMove("a8a7", Color.Black)) + self.chess.checkedMove(notationToMove("d6c5", Color.White)) + self.check(not self.chess.isDrawClaimable()) ## Tests for Pawn moves method testCheckedMovePawnSingleTrue() = self.setup() var test: bool for file in "abcdefgh": - test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "3" & $file & "4", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "3" & $file & "4", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "6" & $file & "5", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "6" & $file & "5", Color.Black)) self.check(test) method testCheckedMovePawnSingleFalseIntoEnemyPiece() = var test: bool - let pos = initGame([ + 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, @@ -659,16 +659,16 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, 0, 0, 0, BRook, 0, 0, BKing, 0, 0, 0, BRook ], Color.White) - self.game = pos + self.chess = pos for file in "abcdefgh": - test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "4" & $file & "5", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black)) self.check(not test) method testCheckedMovePawnSingleFalseIntoOwnPiece() = var test: bool - let pos = initGame([ + 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, @@ -678,25 +678,25 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BRook, 0, 0, BKing, 0, 0, 0, BRook ], Color.White) - self.game = pos + self.chess = pos for file in "abcdefgh": - test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black)) self.check(not test) method testCheckedMovePawnDoubleTrue() = self.setup() var test: bool for file in "abcdefgh": - test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "2" & $file & "4", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black)) self.check(test) method testCheckedMovePawnDoubleFalseAlreadyMoved() = var test: bool - let pos = initGame([ + 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, @@ -706,16 +706,16 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, 0, 0, 0, BRook, 0, 0, BKing, 0, 0, 0, BRook ], Color.White) - self.game = pos + self.chess = pos for file in "abcdefgh": - test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black)) self.check(not test) method testCheckedMovePawnDoubleFalseThroughEnemyPiece() = var test: bool - let pos = initGame([ + 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, @@ -725,16 +725,16 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BRook, 0, 0, BKing, 0, 0, 0, BRook ], Color.White) - self.game = pos + self.chess = pos for file in "abcdefgh": - test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black)) self.check(not test) method testCheckedMovePawnDoubleFalseThroughOwnPiece() = var test: bool - let pos = initGame([ + 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, @@ -744,16 +744,16 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BRook, 0, 0, BKing, 0, 0, 0, BRook ], Color.White) - self.game = pos + self.chess = pos for file in "abcdefgh": - test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black)) self.check(not test) method testCheckedMovePawnDoubleFalseIntoEnemyPiece() = var test: bool - let pos = initGame([ + 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, @@ -763,16 +763,16 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BRook, 0, 0, BKing, 0, 0, 0, BRook ], Color.White) - self.game = pos + self.chess = pos for file in "abcdefgh": - test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black)) self.check(not test) method testCheckedMovePawnDoubleFalseIntoOwnPiece() = var test: bool - let pos = initGame([ + 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, @@ -782,16 +782,16 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BRook, 0, 0, BKing, 0, 0, 0, BRook ], Color.White) - self.game = pos + self.chess = pos for file in "abcdefgh": - test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "3" & $file & "5", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black)) self.check(not test) method testCheckedMovePawnCaptureTrueWhite() = var test: bool - let pos = initGame([ + 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, @@ -805,21 +805,21 @@ testSuite GameTest of TestSuite: str = "abcdefgh" for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] & + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "4" & $str[ind+1] & "5", Color.White)) self.check(test) str.reverse() for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] & + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "4" & $str[ind+1] & "5", Color.White)) self.check(test) method testCheckedMovePawnCaptureTrueBlack() = var test: bool - let pos = initGame([ + 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, @@ -833,21 +833,21 @@ testSuite GameTest of TestSuite: str = "abcdefgh" for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] & + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "5" & $str[ind+1] & "4", Color.Black)) self.check(test) str.reverse() for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] & + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "5" & $str[ind+1] & "4", Color.Black)) self.check(test) method testCheckedMovePawnCaptureFalseWhite() = var test: bool - let pos = initGame([ + 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, @@ -861,21 +861,21 @@ testSuite GameTest of TestSuite: str = "abcdefgh" for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] & + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "4" & $str[ind+1] & "5", Color.White)) self.check(not test) str.reverse() for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] & + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "4" & $str[ind+1] & "5", Color.White)) self.check(not test) method testCheckedMovePawnCaptureFalseBlack() = var test: bool - let pos = initGame([ + 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, @@ -889,21 +889,21 @@ testSuite GameTest of TestSuite: str = "abcdefgh" for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] & + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "5" & $str[ind+1] & "4", Color.Black)) self.check(not test) str.reverse() for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] & + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "5" & $str[ind+1] & "4", Color.Black)) self.check(not test) method testCheckedMovePawnEnPassantTrueWhite() = var test: bool - let pos = initGame([ + 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, @@ -917,43 +917,43 @@ testSuite GameTest of TestSuite: str = "abcdefgh" for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White)) + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "2" & $file & "4", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "4" & $file & "5", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[ + test = self.chess.checkedMove(notationToMove($str[ind+1] & "7" & $str[ ind+1] & "5", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] & + test = self.chess.checkedMove(notationToMove($file & "5" & $str[ind+1] & "6", Color.White)) self.check(test) - test = (0 == self.game.board[fieldToInd($str[ind+1] & "5")]) + test = (0 == self.chess.board[fieldToInd($str[ind+1] & "5")]) self.check(test) str.reverse() for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White)) + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "2" & $file & "4", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "4" & $file & "5", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[ + test = self.chess.checkedMove(notationToMove($str[ind+1] & "7" & $str[ ind+1] & "5", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] & + test = self.chess.checkedMove(notationToMove($file & "5" & $str[ind+1] & "6", Color.White)) self.check(test) - test = (0 == self.game.board[fieldToInd($str[ind+1] & "5")]) + test = (0 == self.chess.board[fieldToInd($str[ind+1] & "5")]) self.check(test) method testCheckedMovePawnEnPassantTrueBlack() = var test: bool - let pos = initGame([ + 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, @@ -967,43 +967,43 @@ testSuite GameTest of TestSuite: str = "abcdefgh" for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black)) + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[ + test = self.chess.checkedMove(notationToMove($str[ind+1] & "2" & $str[ ind+1] & "4", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] & + test = self.chess.checkedMove(notationToMove($file & "4" & $str[ind+1] & "3", Color.Black)) self.check(test) - test = (0 == self.game.board[fieldToInd($str[ind+1] & "4")]) + test = (0 == self.chess.board[fieldToInd($str[ind+1] & "4")]) self.check(test) str.reverse() for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black)) + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[ + test = self.chess.checkedMove(notationToMove($str[ind+1] & "2" & $str[ ind+1] & "4", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] & + test = self.chess.checkedMove(notationToMove($file & "4" & $str[ind+1] & "3", Color.Black)) self.check(test) - test = (0 == self.game.board[fieldToInd($str[ind+1] & "4")]) + test = (0 == self.chess.board[fieldToInd($str[ind+1] & "4")]) self.check(test) method testCheckedMovePawnEnPassantFalseWhite() = var test: bool - let pos = initGame([ + 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, @@ -1017,43 +1017,43 @@ testSuite GameTest of TestSuite: str = "abcdefgh" for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White)) + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "2" & $file & "4", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[ + test = self.chess.checkedMove(notationToMove($str[ind+1] & "7" & $str[ ind+1] & "5", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "4" & $file & "5", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] & + test = self.chess.checkedMove(notationToMove($file & "5" & $str[ind+1] & "6", Color.White)) self.check(not test) - test = (0 == self.game.board[fieldToInd($str[ind+1] & "5")]) + test = (0 == self.chess.board[fieldToInd($str[ind+1] & "5")]) self.check(not test) str.reverse() for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White)) + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "2" & $file & "4", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[ + test = self.chess.checkedMove(notationToMove($str[ind+1] & "7" & $str[ ind+1] & "5", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "4" & $file & "5", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] & + test = self.chess.checkedMove(notationToMove($file & "5" & $str[ind+1] & "6", Color.White)) self.check(not test) - test = (0 == self.game.board[fieldToInd($str[ind+1] & "5")]) + test = (0 == self.chess.board[fieldToInd($str[ind+1] & "5")]) self.check(not test) method testCheckedMovePawnEnPassantFalseBlack() = var test: bool - let pos = initGame([ + 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, @@ -1067,44 +1067,44 @@ testSuite GameTest of TestSuite: str = "abcdefgh" for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black)) + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[ + test = self.chess.checkedMove(notationToMove($str[ind+1] & "2" & $str[ ind+1] & "4", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] & + test = self.chess.checkedMove(notationToMove($file & "4" & $str[ind+1] & "3", Color.Black)) self.check(not test) - test = (0 == self.game.board[fieldToInd($str[ind+1] & "4")]) + test = (0 == self.chess.board[fieldToInd($str[ind+1] & "4")]) self.check(not test) str.reverse() for ind, file in str: if ind < len(str)-1: - self.game = pos - test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black)) + self.chess = pos + test = self.chess.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[ + test = self.chess.checkedMove(notationToMove($str[ind+1] & "2" & $str[ ind+1] & "4", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black)) + test = self.chess.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) + test = self.chess.checkedMove(notationToMove($file & "2" & $file & "3", Color.White)) self.check(test) - test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] & + test = self.chess.checkedMove(notationToMove($file & "4" & $str[ind+1] & "3", Color.Black)) self.check(not test) - test = (0 == self.game.board[fieldToInd($str[ind+1] & "4")]) + test = (0 == self.chess.board[fieldToInd($str[ind+1] & "4")]) self.check(not test) ## Tests for King moves method testCheckedMoveKingCastleTrueWhite() = var test: bool - let pos = initGame([ + 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, @@ -1114,16 +1114,16 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BRook, 0, 0, BKing, 0, 0, 0, BRook ], Color.White) - self.game = pos - test = self.game.checkedMove(notationToMove("e1c1", Color.White)) + self.chess = pos + test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(test) - self.game = pos - self.game.checkedMove(notationToMove("e1g1", Color.White)) + self.chess = pos + self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(test) method testCheckedMoveKingCastleTrueBlack() = var test: bool - let pos = initGame([ + 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, @@ -1133,16 +1133,16 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BRook, 0, 0, BKing, 0, 0, 0, BRook ], Color.Black) - self.game = pos - test = self.game.checkedMove(notationToMove("e8c8", Color.Black)) + self.chess = pos + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) self.check(test) - self.game = pos - test = self.game.checkedMove(notationToMove("e8g8", Color.Black)) + self.chess = pos + test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(test) method testCheckedMoveKingCastleFalseAlreadyMovedKing() = var test: bool - let pos = initGame([ + 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, @@ -1152,21 +1152,21 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BRook, 0, 0, 0, BKing, 0, 0, BRook ], Color.White) - self.game.checkedMove(notationToMove("d1e1", Color.White)) - self.game.checkedMove(notationToMove("d8e8", Color.White)) - self.game = pos - test = self.game.checkedMove(notationToMove("e1c1", Color.White)) + self.chess.checkedMove(notationToMove("d1e1", Color.White)) + self.chess.checkedMove(notationToMove("d8e8", Color.White)) + self.chess = pos + test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8c8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) self.check(not test) - self.game.checkedMove(notationToMove("e1g1", Color.White)) + self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8g8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingCastleFalseAlreadyMovedRook() = var test: bool - let pos = initGame([ + 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, @@ -1176,23 +1176,23 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, 0, BRook, 0, BKing, 0, 0, BRook, 0 ], Color.White) - self.game = pos - self.game.checkedMove(notationToMove("b1a1", Color.White)) - self.game.checkedMove(notationToMove("b8a8", Color.Black)) - self.game.checkedMove(notationToMove("g1h1", Color.White)) - self.game.checkedMove(notationToMove("g8h8", Color.Black)) - test = self.game.checkedMove(notationToMove("e1c1", Color.White)) + self.chess = pos + self.chess.checkedMove(notationToMove("b1a1", Color.White)) + self.chess.checkedMove(notationToMove("b8a8", Color.Black)) + self.chess.checkedMove(notationToMove("g1h1", Color.White)) + self.chess.checkedMove(notationToMove("g8h8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8c8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) self.check(not test) - self.game.checkedMove(notationToMove("e1g1", Color.White)) + self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8g8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingCastleFalseThroughCheck() = var test: bool - let pos = initGame([ + 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, @@ -1202,19 +1202,19 @@ testSuite GameTest of TestSuite: BPawn, BPawn, WRook, BPawn, WRook, BPawn, BPawn, BPawn, BRook, 0, 0, BKing, 0, 0, 0, BRook ], Color.White) - self.game = pos - test = self.game.checkedMove(notationToMove("e1c1", Color.White)) + self.chess = pos + test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8c8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) self.check(not test) - self.game.checkedMove(notationToMove("e1g1", Color.White)) + self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8g8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingCastleFalseIntoCheck() = var test: bool - let pos = initGame([ + 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, @@ -1224,19 +1224,19 @@ testSuite GameTest of TestSuite: BPawn, WRook, BPawn, BPawn, BPawn, WRook, BPawn, BPawn, BRook, 0, 0, BKing, 0, 0, 0, BRook ], Color.White) - self.game = pos - test = self.game.checkedMove(notationToMove("e1c1", Color.White)) + self.chess = pos + test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8c8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) self.check(not test) - self.game.checkedMove(notationToMove("e1g1", Color.White)) + self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8g8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingCastleFalseThroughOwnPiece() = var test: bool - let pos = initGame([ + 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, @@ -1246,19 +1246,19 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BRook, 0, BBishop, BKing, BBishop, 0, 0, BRook ], Color.White) - self.game = pos - test = self.game.checkedMove(notationToMove("e1c1", Color.White)) + self.chess = pos + test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8c8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) self.check(not test) - self.game.checkedMove(notationToMove("e1g1", Color.White)) + self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8g8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingCastleFalseThroughEnemyPiece() = var test: bool - let pos = initGame([ + 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, @@ -1268,19 +1268,19 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BRook, 0, WBishop, BKing, WBishop, 0, 0, BRook ], Color.White) - self.game = pos - test = self.game.checkedMove(notationToMove("e1c1", Color.White)) + self.chess = pos + test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8c8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) self.check(not test) - self.game.checkedMove(notationToMove("e1g1", Color.White)) + self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8g8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingCastleFalseIntoOwnPiece() = var test: bool - let pos = initGame([ + 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, @@ -1290,19 +1290,19 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BRook, BBishop, 0, BKing, 0, BBishop, 0, BRook ], Color.White) - self.game = pos - test = self.game.checkedMove(notationToMove("e1c1", Color.White)) + self.chess = pos + test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8c8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) self.check(not test) - self.game.checkedMove(notationToMove("e1g1", Color.White)) + self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8g8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingCastleFalseIntoEnemyPiece() = var test: bool - let pos = initGame([ + 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, @@ -1312,19 +1312,19 @@ testSuite GameTest of TestSuite: BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BRook, WBishop, 0, BKing, 0, WBishop, 0, BRook ], Color.White) - self.game = pos - test = self.game.checkedMove(notationToMove("e1c1", Color.White)) + self.chess = pos + test = self.chess.checkedMove(notationToMove("e1c1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8c8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8c8", Color.Black)) self.check(not test) - self.game.checkedMove(notationToMove("e1g1", Color.White)) + self.chess.checkedMove(notationToMove("e1g1", Color.White)) self.check(not test) - test = self.game.checkedMove(notationToMove("e8g8", Color.Black)) + test = self.chess.checkedMove(notationToMove("e8g8", Color.Black)) self.check(not test) method testCheckedMoveKingWhite() = var test: bool - let pos = initGame([ + 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, @@ -1340,9 +1340,9 @@ testSuite GameTest of TestSuite: var move: string for cha in str: for num in 1..8: - self.game = pos + self.chess = pos move = $cha & $num - test = self.game.checkedMove(notationToMove(start & move, Color.White)) + test = self.chess.checkedMove(notationToMove(start & move, Color.White)) if move in legalMoves: self.check(test) else: @@ -1350,7 +1350,7 @@ testSuite GameTest of TestSuite: method testCheckedMoveKingBlack() = var test: bool - let pos = initGame([ + 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, @@ -1366,9 +1366,9 @@ testSuite GameTest of TestSuite: var move: string for cha in str: for num in 1..8: - self.game = pos + self.chess = pos move = $cha & $num - test = self.game.checkedMove(notationToMove(start & move, Color.Black)) + test = self.chess.checkedMove(notationToMove(start & move, Color.Black)) if move in legalMoves: self.check(test) else: @@ -1377,7 +1377,7 @@ testSuite GameTest of TestSuite: ## Tests for Bishop moves method testCheckedMoveBishopWhite() = var test: bool - let pos = initGame([ + 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, @@ -1393,9 +1393,9 @@ testSuite GameTest of TestSuite: var move: string for cha in str: for num in 1..8: - self.game = pos + self.chess = pos move = $cha & $num - test = self.game.checkedMove(notationToMove(start & move, Color.White)) + test = self.chess.checkedMove(notationToMove(start & move, Color.White)) if move in legalMoves: self.check(test) else: @@ -1403,7 +1403,7 @@ testSuite GameTest of TestSuite: method testCheckedMoveBishopBlack() = var test: bool - let pos = initGame([ + 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, @@ -1419,9 +1419,9 @@ testSuite GameTest of TestSuite: var move: string for cha in str: for num in 1..8: - self.game = pos + self.chess = pos move = $cha & $num - test = self.game.checkedMove(notationToMove(start & move, Color.Black)) + test = self.chess.checkedMove(notationToMove(start & move, Color.Black)) if move in legalMoves: self.check(test) else: @@ -1430,7 +1430,7 @@ testSuite GameTest of TestSuite: ## Tests for Knight moves method testCheckedMoveKnightWhite() = var test: bool - let pos = initGame([ + 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, @@ -1446,9 +1446,9 @@ testSuite GameTest of TestSuite: var move: string for cha in str: for num in 1..8: - self.game = pos + self.chess = pos move = $cha & $num - test = self.game.checkedMove(notationToMove(start & move, Color.White)) + test = self.chess.checkedMove(notationToMove(start & move, Color.White)) if move in legalMoves: self.check(test) else: @@ -1456,7 +1456,7 @@ testSuite GameTest of TestSuite: method testCheckedMoveKnightBlack() = var test: bool - let pos = initGame([ + 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, @@ -1472,9 +1472,9 @@ testSuite GameTest of TestSuite: var move: string for cha in str: for num in 1..8: - self.game = pos + self.chess = pos move = $cha & $num - test = self.game.checkedMove(notationToMove(start & move, Color.Black)) + test = self.chess.checkedMove(notationToMove(start & move, Color.Black)) if move in legalMoves: self.check(test) else: @@ -1483,7 +1483,7 @@ testSuite GameTest of TestSuite: ## Tests for Rook moves method testCheckedMoveRookWhite() = var test: bool - let pos = initGame([ + 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, @@ -1499,9 +1499,9 @@ testSuite GameTest of TestSuite: var move: string for cha in str: for num in 1..8: - self.game = pos + self.chess = pos move = $cha & $num - test = self.game.checkedMove(notationToMove(start & move, Color.White)) + test = self.chess.checkedMove(notationToMove(start & move, Color.White)) if move in legalMoves: self.check(test) else: @@ -1509,7 +1509,7 @@ testSuite GameTest of TestSuite: method testCheckedMoveRookBlack() = var test: bool - let pos = initGame([ + 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, @@ -1525,9 +1525,9 @@ testSuite GameTest of TestSuite: var move: string for cha in str: for num in 1..8: - self.game = pos + self.chess = pos move = $cha & $num - test = self.game.checkedMove(notationToMove(start & move, Color.Black)) + test = self.chess.checkedMove(notationToMove(start & move, Color.Black)) if move in legalMoves: self.check(test) else: @@ -1536,7 +1536,7 @@ testSuite GameTest of TestSuite: ## Tests for Queen moves method testCheckedMoveQueenWhite() = var test: bool - let pos = initGame([ + 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, @@ -1553,9 +1553,9 @@ testSuite GameTest of TestSuite: var move: string for cha in str: for num in 1..8: - self.game = pos + self.chess = pos move = $cha & $num - test = self.game.checkedMove(notationToMove(start & move, Color.White)) + test = self.chess.checkedMove(notationToMove(start & move, Color.White)) if move in legalMoves: self.check(test) else: @@ -1563,7 +1563,7 @@ testSuite GameTest of TestSuite: method testCheckedMoveQueenBlack() = var test: bool - let pos = initGame([ + 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, @@ -1580,9 +1580,9 @@ testSuite GameTest of TestSuite: var move: string for cha in str: for num in 1..8: - self.game = pos + self.chess = pos move = $cha & $num - test = self.game.checkedMove(notationToMove(start & move, Color.Black)) + test = self.chess.checkedMove(notationToMove(start & move, Color.Black)) if move in legalMoves: self.check(test) else: @@ -1591,18 +1591,18 @@ testSuite GameTest of TestSuite: method testcheckedMoveFaultyInput() = var test: bool self.setup() - let startPos = self.game - test = self.game.checkedMove(notationToMove("aaaa", Color.White)) + let startPos = self.chess + test = self.chess.checkedMove(notationToMove("aaaa", Color.White)) self.check(not test) - test = (self.game == startPos) + test = (self.chess == startPos) self.check(test) - test = self.game.checkedMove(notationToMove("1bb6&111", Color.White)) + test = self.chess.checkedMove(notationToMove("1bb6&111", Color.White)) self.check(not test) - test = (self.game == startPos) + test = (self.chess == startPos) self.check(test) - test = self.game.checkedMove(notationToMove("e1g1sdfa", Color.White)) + test = self.chess.checkedMove(notationToMove("e1g1sdfa", Color.White)) self.check(not test) - test = (self.game == startPos) + test = (self.chess == startPos) self.check(test) when isMainModule: diff --git a/src/engine.nim b/src/engine.nim index b89021a..89ea3c4 100644 --- a/src/engine.nim +++ b/src/engine.nim @@ -1,9 +1,9 @@ -import ./chess +import ./chess.nim type MoveTree* = object ## `Movetree` is a visualization for possible moves. - game*: Game + chess*: Chess evaluation: float children*: seq[Movetree] @@ -17,10 +17,10 @@ const DrawVal = 0 ## `DrawVal` is the engines value for a draw. LoVal = -1000000 ## `LoVal` is a value always lower than any evaluation. -proc pieceEval*(game: Game): int = +proc pieceEval*(chess: Chess): int = ## Returns the evaluation of existing pieces on the `board` var evaluation = DrawVal - for square in game.board: + for square in chess.board: case square: of WPawn: evaluation += ord(Color.White) * PawnVal @@ -46,56 +46,56 @@ proc pieceEval*(game: Game): int = continue return evaluation -proc evaluate(game: Game): int = - ## Returns a complete evaluation of a `game` with player `toMove` about to make +proc evaluate(chess: Chess): int = + ## Returns a complete evaluation of a `chess` with player `toMove` about to make ## a move. var evaluation: int - if game.isCheckmate(game.toMove): - evaluation = ord(game.toMove) * CheckmateVal - if game.isStalemate(game.toMove): + if chess.isCheckmate(chess.toMove): + evaluation = ord(chess.toMove) * CheckmateVal + if chess.isStalemate(chess.toMove): evaluation = DrawVal else: - evaluation = game.pieceEval() - if game.isDrawClaimable(): - if game.toMove == Color.White: + evaluation = chess.pieceEval() + if chess.isDrawClaimable(): + if chess.toMove == Color.White: evaluation = max(DrawVal, evaluation) else: evaluation = min(DrawVal, evaluation) return evaluation -proc spanMoveTree*(game: Game, depth: int): MoveTree = - ## Create and return a Movetree of a given `game` with a given maximum `depth`. +proc spanMoveTree*(chess: Chess, depth: int): MoveTree = + ## Create and return a Movetree of a given `chess` with a given maximum `depth`. var mTree: MoveTree - mTree.game = game - if depth != 0 and not game.isCheckmate(game.toMove) and not game.isStalemate(game.toMove): - let possibleMoves = game.genLegalMoves(game.toMove) + mTree.chess = chess + if depth != 0 and not chess.isCheckmate(chess.toMove) and not chess.isStalemate(chess.toMove): + let possibleMoves = chess.genLegalMoves(chess.toMove) for move in possibleMoves: - var tmpGame = game - tmpGame.checkedMove(move) - mTree.children.add(spanMoveTree(tmpGame, depth-1)) + var tmpChess = chess + tmpChess.checkedMove(move) + mTree.children.add(spanMoveTree(tmpChess, depth-1)) return mTree proc negaMax*(mTree: MoveTree): int = ## Return the value of the root node of a given `MoveTree` if mTree.children == []: - return mTree.game.evaluate() + return mTree.chess.evaluate() var bestVal = LoVal for child in mTree.children: var tmpVal = -negaMax(child) bestVal = max(bestVal, tmpVal) return bestVal -proc bestMove*(game: Game, depth: int): Move = - ## Generate a MoveTree of a `game` with a given `depth`, run negaMax and return +proc bestMove*(chess: Chess, depth: int): Move = + ## Generate a MoveTree of a `chess` with a given `depth`, run negaMax and return ## the best evaluated move. - var moves = game.genLegalMoves(game.toMove) + var moves = chess.genLegalMoves(chess.toMove) var bestMove: Move var bestEval: int bestEval = LoVal for move in moves: - var tmpGame = game - tmpGame.checkedMove(move) - var tmpMTree = tmpGame.spanMoveTree(depth) + var tmpChess = chess + tmpChess.checkedMove(move) + var tmpMTree = tmpChess.spanMoveTree(depth) var tmpEval = -tmpMTree.negaMax() echo("move:", moveToNotation(move),"; eval:", tmpEval) if tmpEval > bestEval: diff --git a/src/engineTest.nim b/src/engineTest.nim index bc2d3c5..2cf2ab6 100644 --- a/src/engineTest.nim +++ b/src/engineTest.nim @@ -1,18 +1,18 @@ import einheit -import ./chess -import ./engine +import ./chess.nim +import ./engine.nim -testSuite GameTest of TestSuite: +testSuite ChessTest of TestSuite: var - game: Game + chess: Chess method setup() = - self.game = initGame() + self.chess = initChess() method testPieceEvalStalemate() = - self.game = initGame([ + 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, @@ -22,11 +22,11 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - var pieceEvaluation = self.game.pieceEval() + var pieceEvaluation = self.chess.pieceEval() self.check(pieceEvaluation == 0) method testSpanMoveTree() = - self.game = initGame([ + 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, @@ -36,11 +36,11 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - var mTree = self.game.spanMoveTree(1) + var mTree = self.chess.spanMoveTree(1) self.check(mTree.children == []) method testBestMoveProm() = - self.game = initGame([ + 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, @@ -50,7 +50,7 @@ testSuite GameTest of TestSuite: 0, 0, 0, WPawn, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.White) - var testBestMove = self.game.bestMove(2) + var testBestMove = self.chess.bestMove(2) self.check(testBestMove.start != 0) self.check(indToField(testBestMove.start) == "e7") self.check(indToField(testBestMove.dest) == "e8") @@ -58,7 +58,7 @@ testSuite GameTest of TestSuite: method testBestMoveStopProm() = - self.game = initGame([ + 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, @@ -68,13 +68,13 @@ testSuite GameTest of TestSuite: 0, 0, 0, 0, WPawn, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - var testBestMove = self.game.bestMove(2) + var testBestMove = self.chess.bestMove(2) self.check(testBestMove.start != 0) self.check(indToField(testBestMove.start) == "c7") self.check(indToField(testBestMove.dest) == "d7") method testBestMoveTacticBlack() = - self.game = initGame([ + self.chess = initChess([ 0, 0, 0, 0, 0, 0, 0, 0, 0, WRook, 0, WKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -84,12 +84,12 @@ testSuite GameTest of TestSuite: 0, BRook, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.Black) - var testBestMove = self.game.bestMove(2) + var testBestMove = self.chess.bestMove(2) self.check(testBestMove.start != 0) self.check(indToField(testBestMove.start) != "g5" or indToField(testBestMove.dest) != "f4") method testBestMoveTacticWhite() = - self.game = initGame([ + self.chess = initChess([ 0, 0, 0, 0, 0, 0, 0, 0, 0, WRook, 0, WKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -99,7 +99,7 @@ testSuite GameTest of TestSuite: 0, BRook, 0, 0, 0, BKing, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], Color.White) - var testBestMove = self.game.bestMove(2) + var testBestMove = self.chess.bestMove(2) self.check(testBestMove.start != 0) self.check(indToField(testBestMove.start) != "g4" or indToField(testBestMove.dest) != "f5") diff --git a/src/game.nim b/src/game.nim index 0d7afd8..ceff353 100644 --- a/src/game.nim +++ b/src/game.nim @@ -5,52 +5,53 @@ import ./engine.nim proc runGameHotseat*(): void = ## Initializes and runs a game of chess as hotseat. - var game = initGame() + var chess = initChess() var draw: string - game.echoBoard(game.toMove) - while not game.isCheckmate(game.toMove) and not game.isStalemate(game.toMove): + chess.echoBoard(chess.toMove) + while not chess.isCheckmate(chess.toMove) and not chess.isStalemate(chess.toMove): echo "Make a move" - echo game.toMove + echo chess.toMove var move = readLine(stdin) - while not game.checkedMove(notationToMove(move, game.toMove)): + while not chess.checkedMove(notationToMove(move, chess.toMove)): move = readLine(stdin) - game.echoBoard(game.toMove) - if (game.isDrawClaimable): + chess.echoBoard(chess.toMove) + if (chess.isDrawClaimable): echo "Do you want to claim a draw? (y/N)" draw = readLine(stdin) if (draw == "y"): echo "Draw claimed" break - if game.isCheckmate(game.toMove): - echo $game.toMove & " was checkmated" - if game.isStalemate(game.toMove): + if chess.isCheckmate(chess.toMove): + echo $chess.toMove & " was checkmated" + if chess.isStalemate(chess.toMove): echo "Stalemate" proc runGameSolo*(color: Color, difficulty: int): void = ## Initializes and runs a solo game of chess. ## The player plays as `color`. - var game = initGame() + echo("run game") + var chess = initChess() var draw: string - while not game.isCheckmate(game.toMove) and not game.isStalemate(game.toMove): - if (game.toMove == color): - game.echoBoard(color) + while not chess.isCheckmate(chess.toMove) and not chess.isStalemate(chess.toMove): + if (chess.toMove == color): + chess.echoBoard(color) echo "Make a move" var hMove = readLine(stdin) - while not game.checkedMove(notationToMove(hMove, game.toMove)): + while not chess.checkedMove(notationToMove(hMove, chess.toMove)): hMove = readLine(stdin) - game.echoBoard(color) - if (game.isDrawClaimable): + chess.echoBoard(color) + if (chess.isDrawClaimable): echo "Do you want to claim a draw? (y/N)" draw = readLine(stdin) if (draw == "y"): echo "Draw claimed" break else: - var cMove = bestMove(game, 3) - game.checkedMove(cMove) - if game.isCheckmate(game.toMove): - echo $game.toMove & " was checkmated" - if game.isStalemate(game.toMove): + var cMove = bestMove(chess, difficulty) + chess.checkedMove(cMove) + if chess.isCheckmate(chess.toMove): + echo $chess.toMove & " was checkmated" + if chess.isStalemate(chess.toMove): echo "Stalemate" proc menu(): void = @@ -88,4 +89,5 @@ proc menu(): void = echo("\n\n\n") runGameHotseat() -menu() +when isMainModule: + menu() diff --git a/src/lichess.nim b/src/lichessBridge.nim similarity index 81% rename from src/lichess.nim rename to src/lichessBridge.nim index fdcd1cf..70ca38f 100644 --- a/src/lichess.nim +++ b/src/lichessBridge.nim @@ -11,14 +11,14 @@ var session = berserk.TokenSession(secret.api_token) var client = berserk.Client(session=session) let engineID = "tiyn-ychess" -let engineDifficulty = 3 +let engineDifficulty = 2 let toAccept = ["tiynger"] -proc playGame(id: string) {.async.} = +proc playLichessGame(id: string) {.async.} = ## Plays a lichess game with `id` asynchronously. var color: Color - var game = initGame() + var chess = initChess() for event in client.bots.stream_game_state(id): echo(event) if $event["type"] in ["gameState", "gameFull"]: @@ -35,11 +35,11 @@ proc playGame(id: string) {.async.} = movesString = event["moves"] if $movesString != "": var moves = movesString.split(" ") - game.checkedMove(notationToMove($moves[-1], game.toMove)) - game.echoBoard(game.toMove) - if game.toMove == color: + chess.checkedMove(notationToMove($moves[-1], chess.toMove)) + chess.echoBoard(chess.toMove) + if chess.toMove == color: echo("engine has to make a move") - var bestMove = moveToNotation(game.bestMove(engineDifficulty)) + var bestMove = moveToNotation(chess.bestMove(engineDifficulty)) echo(bestMove) discard client.bots.make_move(id, bestMove) @@ -56,10 +56,11 @@ proc acceptChallenge(whiteList: openArray[string]): void = if challenger in whiteList and speed == "correspondence": echo("challenge of ", challenger, " whiteList: ", id) discard client.bots.accept_challenge(id) - discard playGame($event["challenge"]["id"]) + discard playLichessGame($event["challenge"]["id"]) else: discard client.bots.decline_challenge(id) echo("challenge of ", challenger, " whiteList: ", id) -acceptChallenge(toAccept) +when isMainModule: + acceptChallenge(toAccept)