I am pretty sure my code does not follow PEP 8 and would definitely want someone to point out my errors specifically. I am open any form of criticism or suggestions.
import chess import chess.engine import time import stockfish engine = chess.engine.SimpleEngine.popen_uci("stockfish") board = chess.Board() def pact(): # Player's Action print('----------------\n' + 'The legal moves are: \n' + str(board.legal_moves) + '\n' + str(board)) Action = input('Declare your moves: ') try: board.push_san(Action) except ValueError: # output: "integer division or modulo by zero" print('Invalid move, try again') def cact(): # Computer's Action result = engine.play(board, chess.engine.Limit(time=2.0)) board.push(result.move) print(board) print(board) for index in range(3, 0, -1): print('The game starts in ' + str(index) + 'seconds') time.sleep(1) while(board.is_checkmate() == False): pact() cact() # print(engine.play.move(board, limit)
Ideally I would like to incorporate sound recognition and making it a hands-free chess playing with Stockfish or other player. For now, I just want to get the basics right to avoid any future bugs and improve overall tidiness so I can have a good habit in my future coding progress.