Skip to content
Snippets Groups Projects

Resolve "simple pathfinding"

Merged Fabian Heinrich requested to merge 120-simple-pathfinding into dev
1 file
+ 23
13
Compare changes
  • Side-by-side
  • Inline
@@ -22,7 +22,9 @@ from cooperative_cuisine.utils import custom_asdict_factory
TIME_TO_STOP_ACTION = 3.0
ADD_RANDOM_MOVEMENTS = True
ADD_RANDOM_MOVEMENTS = False
DIAGONAL_MOVEMENTS = False
AVOID_OTHER_PLAYERS = True
def get_free_neighbours(
@@ -90,8 +92,9 @@ async def agent():
continue
if movement_graph is None:
movement_graph = create_movement_graph(state, diagonal=True)
movement_graph = create_movement_graph(
state, diagonal=DIAGONAL_MOVEMENTS
)
if counters is None:
counters = defaultdict(list)
@@ -170,16 +173,17 @@ async def agent():
paths = []
for free in target_free_spaces:
try:
modified_graph = restrict_movement_graph(
graph=movement_graph.copy(),
player_positions=[
p["pos"]
for p in state["players"]
if p["id"] != args.player_id
],
)
path = networkx.astar_path(
modified_graph,
restrict_movement_graph(
graph=movement_graph.copy(),
player_positions=[
p["pos"]
for p in state["players"]
if p["id"] != args.player_id
],
)
if AVOID_OTHER_PLAYERS
else movement_graph,
source,
free,
heuristic=astar_heuristic,
@@ -314,7 +318,13 @@ async def agent():
random_counter = random.choice(all_counters)
counter_type = random_counter["type"]
task_args = random_counter["pos"]
print(args.player_hash, args.player_id, task_type, counter_type, task_args)
print(
args.player_hash,
args.player_id,
task_type,
counter_type,
task_args,
)
else:
print(args.player_hash, args.player_id, task_type)
task_args = None
Loading