From 13e65f555f7eaee17bde56a768a05cd08bfc7030 Mon Sep 17 00:00:00 2001 From: kulisak12 Date: Fri, 23 Sep 2022 10:53:59 +0200 Subject: [PATCH] =?UTF-8?q?Strategick=C3=A1:=20P=C5=99ejmenov=C3=A1n=C3=AD?= =?UTF-8?q?=20action=20->=20direction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tam, kde to dává smysl. --- klient/play.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/klient/play.py b/klient/play.py index ce22b3c..3790d81 100755 --- a/klient/play.py +++ b/klient/play.py @@ -81,19 +81,19 @@ class Field: def __hash__(self) -> int: return hash((self.i, self.j)) - def get_neighbour_field(self, action: Direction) -> Field: + def get_neighbour_field(self, direction: Direction) -> Field: """Get the next field in the given direction.""" - if action == Direction.UP: + if direction == Direction.UP: neighbour_i = self.i - 1 neighbour_j = self.j - elif action == Direction.DOWN: + elif direction == Direction.DOWN: neighbour_i = self.i + 1 neighbour_j = self.j - elif action == Direction.LEFT: + elif direction == Direction.LEFT: neighbour_i = self.i neighbour_j = self.j - 1 - elif action == Direction.RIGHT: + elif direction == Direction.RIGHT: neighbour_i = self.i neighbour_j = self.j + 1 else: @@ -201,8 +201,8 @@ def find_fields(predicate: Callable[[Field], bool]) -> List[Field]: def pathfind(member: Member, goal: Field) -> Direction: """Find the shortest path from member position to goal. - Returns the first action to take. - If there is no path, returns Action.STAY. + Returns the first direction to go in. + If there is no path, returns STAY. """ # BFS from goal to member @@ -211,13 +211,13 @@ def pathfind(member: Member, goal: Field) -> Direction: queue = collections.deque([goal]) while queue: field = queue.popleft() - for action in Direction: - neighbour = field.get_neighbour_field(action) + for direction in Direction: + neighbour = field.get_neighbour_field(direction) if (neighbour in explored or not neighbour.is_accessible(member.team)): continue if neighbour == member.field: - return action.invert() + return direction.invert() queue.append(neighbour) explored.add(neighbour) return Direction.STAY