示例#1
0
文件: client.py 项目: Obeyed/AIMAS
        if complex_priority:
            sorted_goals = grid.get_goal_priorities(open_goals)
            g_cell, g_letter = next(iter(sorted_goals))
            goal = (g_letter, g_cell) # reverse
        else:
            prioritized = prioritized_goals(open_goals)
            while not prioritized.empty():
                goal = prioritized.get()[1]
                if goal[1] in open_goals: break
    # reset and start over
    MOVES = {i: [] for i in range(NUM_AGENTS)}

    next_path = hlp.find_next_path(goal)
    #inform(next_path)
    # find agent's index
    agent_idx = AGENTS.index(grid.agent_position[next_path[0]])
    MOVES[agent_idx] = calculate_movements_new(next_path, grid)
    align_movements()
    while len(MOVES[agent_idx]):
        move = next_move()
        #inform(move) # debug
        print(move)  # send to server
        server_response = input()
        while len(server_response.strip()) == 0:
            server_response = input()
        if server_response == '\n' or len(server_response) < 1:
            server_response = input()
        #inform("server response: " + server_response)
        update_grid(server_response, move)

示例#2
0
    if goal is None or goal[1] not in open_goals:
        if complex_priority:
            sorted_goals = grid.get_goal_priorities(open_goals)
            g_cell, g_letter = next(iter(sorted_goals))
            goal = (g_letter, g_cell)  # reverse
        else:
            prioritized = prioritized_goals(open_goals)
            while not prioritized.empty():
                goal = prioritized.get()[1]
                if goal[1] in open_goals: break
    # reset and start over
    MOVES = {i: [] for i in range(NUM_AGENTS)}

    next_path = hlp.find_next_path(goal)
    #inform(next_path)
    # find agent's index
    agent_idx = AGENTS.index(grid.agent_position[next_path[0]])
    MOVES[agent_idx] = calculate_movements_new(next_path, grid)
    align_movements()
    while len(MOVES[agent_idx]):
        move = next_move()
        #inform(move) # debug
        print(move)  # send to server
        server_response = input()
        while len(server_response.strip()) == 0:
            server_response = input()
        if server_response == '\n' or len(server_response) < 1:
            server_response = input()
        #inform("server response: " + server_response)
        update_grid(server_response, move)
示例#3
0
        (5, 4): "A",
        (6, 4): "A",
    }
    colors = {"green": ["0", "B"]}

    for i in range(8):
        for j in range(7):
            cell = (i, j)
            if cell in walls:
                print("+", end="")
            elif cell in goals:
                print(goals[cell], end="")
            elif cell in agents:
                print(agents[cell], end="")
            elif cell in boxes:
                print(boxes[cell], end="")
            else:
                print(" ", end="")
        print()

    grid = SimpleGrid(walls, goals, boxes, agents, colors, free)

    goal = list(goals.keys())[0]
    start = list(agents.keys())[0]

    agent = grid.agent_position[(1, 1)]
    steps = a_star_search(grid, start, goal, agent=agent)

    print(steps)
    print(calculate_movements_new(steps, grid))
示例#4
0
        (3, 2): 'A',
        (4, 2): 'A',
        (2, 3): 'A',
        (3, 4): 'A',
        (4, 4): 'A',
        (5, 4): 'A',
        (6, 4): 'A'
    }
    colors = {'green': ['0', 'B']}

    for i in range(8):
        for j in range(7):
            cell = (i, j)
            if cell in walls: print("+", end="")
            elif cell in goals: print(goals[cell], end="")
            elif cell in agents: print(agents[cell], end="")
            elif cell in boxes: print(boxes[cell], end="")
            else: print(" ", end="")
        print()

    grid = SimpleGrid(walls, goals, boxes, agents, colors, free)

    goal = list(goals.keys())[0]
    start = list(agents.keys())[0]

    agent = grid.agent_position[(1, 1)]
    steps = a_star_search(grid, start, goal, agent=agent)

    print(steps)
    print(calculate_movements_new(steps, grid))