def AITurn(connection: 'connection', currentBoard: cf.GameState) -> cf.GameState: while True: cff.printInfo(currentBoard) response = cfs.receive_response(connection) print(response) if response.upper().startswith("POP "): newBoard, action, col = cff.processTurn(currentBoard, "P", int(response[3::]) - 1) return newBoard elif response.upper().startswith("DROP "): newBoard, action, col = cff.processTurn(currentBoard, "D", int(response[4::]) - 1) return newBoard else: print('Response:' + response + '\nCut') cfs.close(connection) ##CUT
def AITurn(connection: 'connection', currentBoard: cf.GameState) -> cf.GameState: while True: cff.printInfo(currentBoard) response = cfs.receive_response(connection) #Listen for Server print(response) #Print Server Move #Run/Process Server Input if response.upper().startswith("POP "): newBoard, action, col = cff.processTurn(currentBoard, "P", int(response[3::]) - 1) return newBoard elif response.upper().startswith("DROP "): newBoard, action, col = cff.processTurn(currentBoard, "D", int(response[4::]) - 1) return newBoard else: #Bad Response cfs.close(connection) #Cut Connection
def playerTurn(connection: 'connection', currentBoard: cf.GameState) -> cf.GameState: while True: cff.printInfo(currentBoard) while True: newBoard, action, col = cff.userInput(currentBoard) if (action == "INVALID_INPUT"): ## print("Please Enter Valid Input") cff.printBoard(currentBoard) continue elif (action == "NO_COLUMN"): ## print("Please Enter Valid Column") cff.printBoard(currentBoard) continue elif (action == "INVALID_COLUMN"): ## print("Please Enter Valid Column") cff.printBoard(currentBoard) continue elif (action == "INVALID_MOVE"): ## print("PLease Enter Valid Move") cff.printBoard(currentBoard) continue else: break response = cfs.send_receive(connection, action + str(col + 1)) if (response.startswith('WINNER_') ): #Since player turn, received WINNER_RED ## AI_Winner = response[6::]#Not Used ## print('GameOverPlayer') ## cfs.close(connection)#Cut, Game Over return newBoard elif (response == 'ERROR'): print("Invalid Input") continue elif (response != 'OKAY'): print('Response1:' + response + '\nCut') cfs.close(connection) ##CUT return newBoard
def playerTurn(connection: 'connection', currentBoard: cf.GameState) -> cf.GameState: while True: cff.printInfo(currentBoard) while True: newBoard, action, col = cff.userInput( currentBoard) #Run/Process User Input #Check For Errors if (action == "INVALID_INPUT"): cff.printBoard(currentBoard) continue elif (action == "NO_COLUMN"): cff.printBoard(currentBoard) continue elif (action == "INVALID_COLUMN"): cff.printBoard(currentBoard) continue elif (action == "INVALID_MOVE"): cff.printBoard(currentBoard) continue else: break response = cfs.send_receive(connection, action + str(col + 1)) #Send Move to Server if (response.startswith('WINNER_') ): #Since player turn, received WINNER_RED return newBoard elif (response == 'ERROR'): #Should Never Run print("Invalid Input") continue elif (response == "INVALID"): #Should Never Run print("Invalid Input") elif (response != 'OKAY'): #Bad Response cfs.close(connection) #Cut Connection return newBoard
def turn(currentBoard: cf.GameState) -> cf.GameState: while True: cff.printInfo(currentBoard) newBoard, action, col = cff.userInput(currentBoard) return newBoard