<s> from Board import Board <EOL> from InputParser import InputParser <EOL> from AI import AI <EOL> import sys <EOL> import random <EOL> WHITE = True <EOL> BLACK = False <EOL> def askForPlayerSide ( ) : <EOL> playerChoiceInput = input ( <EOL> "<STR_LIT>" ) . lower ( ) <EOL> if '<STR_LIT:w>' in playerChoiceInput : <EOL> print ( "<STR_LIT>" ) <EOL> return WHITE <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> return BLACK <EOL> def askForDepthOfAI ( ) : <EOL> depthInput = <NUM_LIT:2> <EOL> try : <EOL> depthInput = int ( input ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> except : <EOL> print ( "<STR_LIT>" ) <EOL> return depthInput <EOL> def printCommandOptions ( ) : <EOL> undoOption = '<STR_LIT>' <EOL> printLegalMovesOption = '<STR_LIT>' <EOL> randomMoveOption = '<STR_LIT>' <EOL> quitOption = '<STR_LIT>' <EOL> moveOption = '<STR_LIT>' <EOL> options = [ undoOption , printLegalMovesOption , randomMoveOption , <EOL> quitOption , moveOption , '<STR_LIT>' , ] <EOL> print ( '<STR_LIT:\n>' . join ( options ) ) <EOL> def printAllLegalMoves ( board , parser ) : <EOL> for move in parser . getLegalMovesWithShortNotation ( board . currentSide ) : <EOL> print ( move . notation ) <EOL> def getRandomMove ( board , parser ) : <EOL> legalMoves = board . getAllMovesLegal ( board . currentSide ) <EOL> randomMove = random . choice ( legalMoves ) <EOL> randomMove . notation = parser . notationForMove ( randomMove ) <EOL> return randomMove <EOL> def makeMove ( move , board ) : <EOL> print ( ) <EOL> print ( "<STR_LIT>" + move . notation ) <EOL> board . makeMove ( move ) <EOL> def printPointAdvantage ( board ) : <EOL> print ( "<STR_LIT>" + <EOL> str ( board . getPointAdvantageOfSide ( board . currentSide ) ) ) <EOL> def undoLastTwoMoves ( board ) : <EOL> if len ( board . history ) >= <NUM_LIT:2> : <EOL> board . undoLastMove ( ) <EOL> board . undoLastMove ( ) <EOL> def startGame ( board , playerSide , ai ) : <EOL> parser = InputParser ( board , playerSide ) <EOL> while True : <EOL> print ( board ) <EOL> print ( ) <EOL> if board . isCheckmate ( ) : <EOL> if board . currentSide == playerSide : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> return <EOL> if board . isStalemate ( ) : <EOL> if board . currentSide == playerSide : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> return <EOL> if board . currentSide == playerSide : <EOL> move = None <EOL> command = input ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . lower ( ) <EOL> if command == '<STR_LIT:u>' : <EOL> undoLastTwoMoves ( board ) <EOL> continue <EOL> elif command == '<STR_LIT:?>' : <EOL> printCommandOptions ( ) <EOL> continue <EOL> elif command == '<STR_LIT:l>' : <EOL> printAllLegalMoves ( board , parser ) <EOL> continue <EOL> elif command == '<STR_LIT:r>' : <EOL> move = getRandomMove ( board , parser ) <EOL> elif command == '<STR_LIT>' : <EOL> return <EOL> else : <EOL> move = parser . moveForShortNotation ( command ) <EOL> if move : <EOL> makeMove ( move , board ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> move = ai . getBestMove ( ) <EOL> move . notation = parser . notationForMove ( move ) <EOL> makeMove ( move , board ) <EOL> board = Board ( ) <EOL> playerSide = askForPlayerSide ( ) <EOL> print ( ) <EOL> aiDepth = askForDepthOfAI ( ) <EOL> opponentAI = AI ( board , not playerSide , aiDepth ) <EOL> try : <EOL> startGame ( board , playerSide , opponentAI ) <EOL> except KeyboardInterrupt : <EOL> sys . exit ( ) </s>
