def performFirstMove(): # Stores a randomly generated number (either 1 or 2), and if it is 1 skips to the human's turn otherwise allows the # AI to make a move randomPlayerGeneration = random.randrange(1, 3) if randomPlayerGeneration == 1: pass elif randomPlayerGeneration == 2: backend.getAiMove()
def graphicalOverlayClicked(inputX, inputY): # Calculates the tile clicked, gets the number of valid moves possible for the player & the AI, and stores the # current board's status (to keep track of updated pieces) calculatedCoordinates = coordinatesCalculateTile(inputX, inputY) numberOfValidMoves = checkForRemainingValidMoves(recursiveListDeepCopy(backend.findValids(True)), recursiveListDeepCopy(backend.findValids(False))) oldBoardState = recursiveListDeepCopy(backend.getBoard()) # Checks to see if the human can perform a move, otherwise skips to the AI, otherwise runs the end game function if numberOfValidMoves[0] > 0: if 7 >= calculatedCoordinates[0] >= 0 and 7 >= calculatedCoordinates[1] >= 0: if (recursiveListDeepCopy(backend.findValids(True))[calculatedCoordinates[0]][calculatedCoordinates[1]]) == 1: # Feeds the backend with the user's inputted piece row & column values, and updates the board's pieces, # while removing the now outdated ghost pieces backend.playerMove(calculatedCoordinates[0], calculatedCoordinates[1]) updateBoardPieces(backend.getBoard(), oldBoardState) ghostPieceTurtle.clear() # Stores the current board's status (to keep track of updated pieces), allows the AI to make a move, # and updates the board based on the changes, and adds new ghost pieces oldBoardState = recursiveListDeepCopy(backend.getBoard()) backend.getAiMove() updateBoardPieces(backend.getBoard(), oldBoardState) addGhostPiecesToBoard() elif numberOfValidMoves[1] > 0: # Removes the current ghost pieces, allows the AI to make a move, and updates the board based on the changes, # and adds new ghost pieces ghostPieceTurtle.clear() backend.getAiMove() updateBoardPieces(backend.getBoard(), oldBoardState) addGhostPiecesToBoard() elif numberOfValidMoves[0] == 0 and numberOfValidMoves[1] == 0: pieceCount = [0, 0] for rowCounter in range(8): for columnCounter in range(8): if backend.getBoard()[rowCounter][columnCounter] == 1: pieceCount[0] += 1 elif backend.getBoard()[rowCounter][columnCounter] == 2: pieceCount[1] += 1 if pieceCount[0] > pieceCount[1]: endGame("Player Has Won By " + str(pieceCount[0] - pieceCount[1]) + " Pieces!") elif pieceCount[1] > pieceCount[0]: endGame("AI Has Won By " + str(pieceCount[1] - pieceCount[0]) + " Pieces!") elif pieceCount[0] == pieceCount[1]: endGame("Draw, No One Has Won!")