Strategická: Speciální případ pro pathfind

This commit is contained in:
David Klement 2022-09-23 13:28:22 +02:00
parent 32fc6f683a
commit 413c0a08c6
2 changed files with 6 additions and 0 deletions

View file

@ -289,6 +289,9 @@ bool is_field_accessible(Field* f, Team* t)
// Pokud žádná cesta neexistuje, vrátí STAY.
Direction pathfind(Member* m, Field* goal)
{
// speciální případ: voják už je v cíli
if (m->field == goal) return STAY;
std::set<Field*> explored;
std::queue<Field*> queue;
queue.push(goal);

View file

@ -202,6 +202,9 @@ def pathfind(member: Member, goal: Field) -> Direction:
Pokud žádná cesta neexistuje, vrátí STAY.
"""
# speciální případ: voják už je v cíli
if member.field == goal:
return Direction.STAY
# BFS od cíle k vojákovi
# tento směr umožní rychle zjistit, že cesta neexistuje,
# a také jednoduše získat první krok