Skip to content
Snippets Groups Projects
Commit 8e81a464 authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Correct movement graph test

parent 968826dd
No related branches found
No related tags found
1 merge request!89Resolve "simple pathfinding"
Pipeline #49049 passed
......@@ -59,7 +59,9 @@ def test_setup_logging():
def test_movement_graph(env_config_no_validation, layout_empty_config, item_info):
env = Environment(env_config_no_validation, layout_empty_config, item_info, as_files=False)
env = Environment(
env_config_no_validation, layout_empty_config, item_info, as_files=False
)
player_name = "0"
env.add_player(player_name)
......@@ -94,8 +96,6 @@ def test_movement_graph(env_config_no_validation, layout_empty_config, item_info
heuristic=astar_heuristic,
)
assert len(path) != 0, "No path found, but should have."
path = networkx.astar_path(
restrict_movement_graph(
graph=graph_diag,
......@@ -105,22 +105,43 @@ def test_movement_graph(env_config_no_validation, layout_empty_config, item_info
target=(5, 5),
heuristic=astar_heuristic,
)
assert len(path) != 0
assert len(path) != 0, "No path found, but should have."
graph_diag_restricted = restrict_movement_graph(
graph_diag, [(1, 0), (0, 1), (1, 1)]
# now with diagonal movement
graph = create_movement_graph(
json.loads(env.get_json_state(player_id=player_name)), diagonal=True
)
path = networkx.astar_path(
graph,
source=(0, 0),
target=(3, 3),
heuristic=astar_heuristic,
)
assert len(path) != 0, "No path found, but should have."
graph_restricted = restrict_movement_graph(graph_diag, [(1, 0), (0, 1), (1, 1)])
with pytest.raises(networkx.exception.NetworkXNoPath) as e_info:
_ = networkx.astar_path(
graph_diag_restricted,
path = networkx.astar_path(
graph_restricted,
source=(0, 0),
target=(3, 3),
heuristic=astar_heuristic,
)
with pytest.raises(networkx.exception.NodeNotFound) as e_info:
_ = networkx.astar_path(
graph_diag,
path = networkx.astar_path(
graph_restricted,
source=(20, 20),
target=(40, 40),
heuristic=astar_heuristic,
)
path = networkx.astar_path(
restrict_movement_graph(
graph=graph_diag,
player_positions=[],
),
source=(0, 0),
target=(5, 5),
heuristic=astar_heuristic,
)
assert len(path) != 0, "No path found, but should have."
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment