Esempio n. 1
0
def addGhostPiecesToBoard():
    # Gets the array containing all the valid moves the player can perform, and the board array, and adds ghost pieces
    #  into unoccupied valid move spots
    playerValidMoves = backend.findValids(True)
    currentBoardState = backend.getBoard()
    for rowCounter in range(8):
        for columnCounter in range(8):
            if playerValidMoves[rowCounter][columnCounter] == 1 and currentBoardState[rowCounter][columnCounter] == 0:
                teleAddPieceToBoard(rowCounter, columnCounter, 3)
Esempio n. 2
0
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!")