Ejemplo n.º 1
0
def run(sv):

    #initialize the board
    current_board = board.Board(sv.board_h, sv.board_w, sv.mapInfo,
                                sv.startingPosition)
    status, updates = sv.update()
    current_board.updateBoard(updates)
    heuristicHistory = {}
    clock = Clock(TIME_LIMIT)
    while True:
        #print('Board :', current_board.getBoard())
        start_time = time.time()
        clock.startClock()
        minimax.nb_nodes_explore = 0
        minimax.nb_cuts = 0

        #perform tree search throw minimax and reprise optim pos
        exploredPositions = {}
        #current_pos = current_board.getCurrentPositions()
        #as new positions are sorted by pos number we do the same for the current_pos
        current_pos = list(
            dict(
                sorted(current_board.getOurDict().items(),
                       key=lambda kv: kv[1],
                       reverse=True)).keys())

        new_pos = minimax(current_board, exploredPositions, heuristicHistory,
                          clock)[0]

        #if we have more new pos than existing, this is a split to manage
        if len(new_pos) > len(current_pos):
            for i in range(len(new_pos) - len(current_pos)):
                current_pos.append(current_pos[0])
        print("current_pos", current_pos)
        print("new pos", new_pos)

        #move player
        sv.movePlayers_split_Leo(new_pos)
        end_time = time.time()
        print("Time Elapsed : " + str(end_time - start_time))
        print("Number of nodes explored :", minimax.nb_nodes_explore)
        print("Number of cuts performed :", minimax.nb_cuts)

        status, updates = sv.update()
        #print("update", updates)
        current_board.updateBoard(updates)
        #print('new board', current_board.getBoard())

        #input('are you ready ?')
        if status == "END" or status == "BYE":
            break
    print('game ended')
Ejemplo n.º 2
0
def run(sv):
    # initialize the board
    current_board = board_split.Board(sv.board_h, sv.board_w, sv.mapInfo,
                                      sv.startingPosition)
    status, updates = sv.update()
    current_board.updateBoard(updates)

    heuristicHistory = {}
    clock = Clock(1.95)
    while True:
        # print('Board :', current_board.getBoard())
        start_time = time.time()
        clock.startClock()
        minimax.nb_nodes_explore = 0
        minimax.nb_cuts = 0

        # perform tree search throw minimax and reprise optim pos
        source_pos = []
        number_moved = []
        destination_pos = []
        for current_position in current_board.getCurrentDict():
            exploredPositions = {}
            new_pos = [
                minimax(current_board, exploredPositions, heuristicHistory,
                        clock, current_position)[0]
            ]
            source_pos.append(current_position)
            number_moved.append(
                current_board.getCurrentDict()[tuple(current_position)])
            destination_pos.append(new_pos[0])
            print("moved from %s to %s" % (current_position, new_pos))

        # move player
        sv.movePlayers(source_pos, number_moved, destination_pos)
        end_time = time.time()
        print("Time Elapsed : " + str(end_time - start_time))
        print("Number of nodes explored :", minimax.nb_nodes_explore)
        print("Number of cuts performed :", minimax.nb_cuts)

        status, updates = sv.update()
        # print("update", updates)
        current_board.updateBoard(updates)
        # print('new board', current_board.getBoard())
        # input('are you ready ?')
        if status == "END" or status == "BYE":
            break
        # time.sleep(1)
    print('game ended')
Ejemplo n.º 3
0
def run(sv):

    #initialize the board
    current_board = board.Board(sv.board_h, sv.board_w, sv.mapInfo,
                                sv.startingPosition)
    status, updates = sv.update()
    current_board.updateBoard(updates)

    heuristicHistory = {}
    clock = Clock(1.95)
    while True:
        #print('Board :', current_board.getBoard())
        start_time = time.time()
        clock.startClock()
        minimax.nb_nodes_explore = 0
        minimax.nb_cuts = 0

        #perform tree search throw minimax and reprise optim pos
        exploredPositions = {}
        possibleMovesScores = []
        possibleMovesScores5 = [[0]]
        Smart_score = 0
        new_pos = [
            minimax(current_board, exploredPositions, heuristicHistory,
                    possibleMovesScores, possibleMovesScores5, Smart_score,
                    clock)[0]
        ]
        print("new pos", new_pos)

        #move player
        sv.movePlayers(current_board.getCurrentPositions(),
                       current_board.getCurrentUnitsNumber(), new_pos)
        end_time = time.time()
        print("Time Elapsed : " + str(end_time - start_time))
        print("Number of nodes explored :", minimax.nb_nodes_explore)
        print("Number of cuts performed :", minimax.nb_cuts)

        status, updates = sv.update()
        #print("update", updates)
        current_board.updateBoard(updates)
        #print('new board', current_board.getBoard())

        #input('are you ready ?')
        if status == "END" or status == "BYE":
            break
        #time.sleep(1)
    print('game ended')