From 2227b559c3bb42d626480f7209c517a311a95ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kore=C4=8Dek?= Date: Tue, 13 Sep 2022 12:59:44 +0200 Subject: [PATCH] =?UTF-8?q?Strategick=C3=A1:=20Dod=C4=9Bl=C3=A1n=C3=AD=20s?= =?UTF-8?q?tepu=20v=20hern=C3=AD=20logice.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/hra/game.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/server/hra/game.py b/server/hra/game.py index 3fa19b2..9506695 100644 --- a/server/hra/game.py +++ b/server/hra/game.py @@ -89,7 +89,7 @@ class Occupy(Logic): # # "left", "right", "up", "down" # ] # } - # VALIDITU MOVES NEOVĚŘUJU + # Předpokládám validitu `state` # Metoda funguje velmi primitivně po krocích: # * zaznamená se poloha objektů na mapě # * vojáky se pohne podle moves @@ -107,11 +107,14 @@ class Occupy(Logic): highest_ids = [0] * self.teams_count # homes jednotlivých týmů home_positions = [None] * self.teams_count + # 2D array s `True`s tam, kde je hill + hills = [[False] * self.map_width for _ in range(self.map_height)] y = 0 for row in state["map"]: x = 0 for field in row: + hills[y][x] = field["hill"] if field["home_for_team"] is not None: home_positions[field["home_for_team"]] = [y, x] for member in field["members"]: @@ -125,6 +128,9 @@ class Occupy(Logic): for team_id, move in enumerate(moves): if move is not None: for member in move["members"]: + if member["id"] not in id_positions: + # Neplatné ID vojáka + continue id_moves[team_id][member["id"]] = member["action"] # Místo mapy tabulka seznamů vojáků pro každý tým @@ -135,9 +141,15 @@ class Occupy(Logic): for team_id in range(self.teams_count): for soldier_id in all_ids[team_id]: move_vect = self.MOVE_VECTORS[id_moves[team_id][soldier_id]] - new_y = (id_positions[team_id][soldier_id][0] + move_vect[0]) % self.map_height - new_x = (id_positions[team_id][soldier_id][1] + move_vect[1]) % self.map_width - soldier_lists[new_y][new_x][team_id].append(soldier_id) + orig_y = id_positions[team_id][soldier_id][0] + orig_x = id_positions[team_id][soldier_id][1] + new_y = (orig_y + move_vect[0]) % self.map_height + new_x = (orig_x + move_vect[1]) % self.map_width + if hills[new_y][new_x]: + # Voják se snažil lézt na skálu, zůstane na původním místě + soldier_lists[orig_y][orig_x][team_id].append(soldier_id) + else: + soldier_lists[new_y][new_x][team_id].append(soldier_id) # Přidáme vojáky v homes: for team_id in range(self.teams_count):