Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
WHITE = True
BLACK = False

VISIBLE = True
INVISIBLE = False


def askForPlayerSide() -> bool:
playerChoiceInput = input(
Expand Down Expand Up @@ -53,6 +56,18 @@ def askForDepthOfAI() -> int:
return depthInput


def askForBoardDisplay() -> bool:
displayInput = input(
'Would you like to display a board [yN]?'
).lower()
if 'y' in displayInput:
print('You will see the board during the game')
return VISIBLE
else:
print('You will play a blind game')
return INVISIBLE


def printCommandOptions() -> None:
undoOption = 'u : undo last move'
printLegalMovesOption = 'l : show all legal moves'
Expand Down Expand Up @@ -116,7 +131,7 @@ def printGameMoves(history: list[tuple[Move, Piece | None]]) -> None:
print()


def startGame(board: Board, playerSide: bool, ai: AI) -> None:
def startGame(board: Board, playerSide: bool, boardDisplay: bool, ai: AI) -> None:
parser = InputParser(board, playerSide)
while True:
if board.isCheckmate():
Expand Down Expand Up @@ -164,14 +179,16 @@ def startGame(board: Board, playerSide: bool, ai: AI) -> None:
print('%s' % error)
continue
makeMove(move, board)
printBoard(board)
if boardDisplay:
printBoard(board)

else:
print('AI thinking...')
move = ai.getBestMove()
move.notation = parser.notationForMove(move)
makeMove(move, board)
printBoard(board)
if boardDisplay:
printBoard(board)


def twoPlayerGame(board: Board) -> None:
Expand Down Expand Up @@ -281,11 +298,13 @@ def main() -> None:
print()
aiDepth = askForDepthOfAI()
opponentAI = AI(board, not playerSide, aiDepth)
printBoard(board)
startGame(board, playerSide, opponentAI)
boardDisplay = askForBoardDisplay()
if boardDisplay:
printBoard(board)
startGame(board, playerSide, boardDisplay, opponentAI)
except KeyboardInterrupt:
sys.exit()


if __name__ == '__main__':
main()
main()