def loadGame(file_name=constants.SAVE_FILE, redraw=True):
    #Load game info
    saved_state = fileHandler.loadVariable(constants.VARIABLE_STATE, file_name)
    saved_move_num = fileHandler.loadVariable(constants.VARIABLE_MOVE,
                                              file_name)

    #Write loaded variables to variables file
    fileHandler.saveVariable(constants.VARIABLE_STATE, saved_state)
    fileHandler.saveVariable(constants.VARIABLE_MOVE, saved_move_num)

    #Convert state from string to list
    saved_state = converter.toList(saved_state)

    if redraw:
        #Load board configuration
        listInterpret.listToPiece(saved_state)

    #Write turn number
    screenWriter.writeTurn(saved_move_num)

    #Update the scoreboard
    updateScoreBoard(saved_state)

    #Reset valid moves from turtleMove
    turtleMove.SHOWN_MOVES = []

    #Show possible moves
    displayValidMoves(saved_state, int(saved_move_num))
def startMove():
    #Save variable
    fileHandler.saveVariable(constants.VARIABLE_MOVING,
                             constants.VARIABLE_BOOL_TRUE)

    #Load the variables we need
    game_state = converter.toList(
        fileHandler.loadVariable(constants.VARIABLE_STATE))
    move_num = int(fileHandler.loadVariable(constants.VARIABLE_MOVE))

    #Return game_state and move_num as a tuple
    return (game_state, move_num)
def endMove(game_state, move_num):
    #Save the variables
    fileHandler.saveVariable(constants.VARIABLE_STATE,
                             converter.toString(game_state))
    fileHandler.saveVariable(constants.VARIABLE_MOVE, str(move_num))

    #Reload the board
    loadGame(constants.TEMP_FILE, False)

    #Update the scoreboard
    updateScoreBoard(
        converter.toList(fileHandler.loadVariable(constants.VARIABLE_STATE)))

    #Update the window
    constants.WINDOW.update()
Example #4
0
def updateGameState(game_state, move, turn_letter, draw_move=True):
    #Get the x and y coordinates in the move,
    #Subtract 1 so they can be used as list indexes
    xy = convertMove(move)
    x = xy[0] - 1
    y = xy[1] - 1

    #Create a copy of the state
    temp_game_state = converter.toList(converter.toString(game_state))

    #Update the row
    temp_row = updateRow(temp_game_state[y], x, turn_letter)
    temp_game_state[y] = temp_row

    #Update the column
    temp_game_state = updateColumn(game_state, x, y, turn_letter, draw_move)

    #Update the diagonals in both directions
    temp_game_state = updatediagonalDU2(temp_game_state, x, y, turn_letter,
                                        draw_move)
    temp_game_state = update_diagonalUD2(game_state, x, y, turn_letter,
                                         draw_move)

    #Update the row
    temp_row = updateRow(temp_game_state[y], x, turn_letter)
    temp_game_state[y] = temp_row

    #Because updateRow does not draw the pieces on the board, unlike the other update functions, we must draw them here
    if draw_move == True:
        counter = 0
        for i in temp_row:
            conv_move = convertMoveType(counter, y + 1)
            Tx = conv_move[0]
            Ty = conv_move[1]
            if i != constants.PIECE_NONE:
                if i == constants.PIECE_BLACK:
                    temp_piece = constants.PIECE_COLOR_BLACK
                else:
                    temp_piece = constants.PIECE_COLOR_WHITE
                if draw_move:
                    turtleMove.placePiece(Tx, Ty, temp_piece)
            counter = counter + 1

    return temp_game_state
Example #5
0
def directionStrCheckList(game_state, stringID, turn_colour, isTesting=False):

    if game_state == type(list):
        string_state = converter.toString(game_state)

    string_state = CheckNorth(game_state, stringID, turn_colour, isTesting)
    print(string_state)
    string_state = CheckNorthEast(game_state, stringID, turn_colour, isTesting)
    print(string_state)
    string_state = CheckEast(game_state, stringID, turn_colour, isTesting)
    print(string_state)
    string_state = CheckSouthEast(game_state, stringID, turn_colour, isTesting)
    string_state = CheckSouth(game_state, stringID, turn_colour, isTesting)
    string_state = CheckSouthWest(game_state, stringID, turn_colour, isTesting)
    string_state = CheckWest(game_state, stringID, turn_colour, isTesting)
    string_state = CheckNorthWest(game_state, stringID, turn_colour, isTesting)
    list_state = converter.toList(string_state)

    return list_state
Example #6
0
def testFunction(function,
                 param_one,
                 param_two,
                 param_three,
                 param_four=False):
    #	turtleMove.setup()

    result = function(param_one, param_two, param_three, param_four)
    formatted_start = converter.asBoardRepresentation(param_one)
    formatted_end = converter.asBoardRepresentation(result)
    formatted_list = converter.toList(result)
    print("At:", stringInterpret.pieceToString(param_two))
    print("Input".center(8))
    print(formatted_start)
    print("Output".center(8))
    print(formatted_end)
    print(param_one)
    print(result)
    print(param_two)
    print(param_three)
def countUpdatedPieces(game_state, move, move_num):
    #Create a deep copy of game state
    state_string = converter.toString(game_state)
    copy_state = converter.toList(state_string)

    #Find which piece is being placed
    piece = listInterpret.whoseTurn(move_num)

    #Get an updated state after the move
    changed_state = listUpdater.updateGameState(copy_state, move, piece, False)

    #Count how many pieces changed
    change_count = 0

    #Traverse both states and compare pieces
    for i in range(len(game_state)):
        for j in range(len(game_state[i])):
            if game_state[j][i] != changed_state[j][i]:
                change_count += 1

    return change_count