From f82ef022cefeeb5faec7dcbf523e635b6e32e0be Mon Sep 17 00:00:00 2001 From: hamidrezakamkari Date: Tue, 4 Feb 2020 08:50:08 +0330 Subject: [PATCH] path bug equals and path to friend fixed! --- AI.py | 19 ++++++++++++------- controller.py | 1 + model.py | 15 ++++++++++++--- world.py | 15 ++++++++++----- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/AI.py b/AI.py index a8ea284..7ce331e 100644 --- a/AI.py +++ b/AI.py @@ -1,15 +1,20 @@ class AI: def pick(self, world): + # path check: print("pick") world.choose_deck([1, 2, 3, 4]) - print(world.get_player_by_id(world.get_my_id())) - print(world.get_player_by_id(world.get_friend_id())) - for p in world.map.paths: - print(p) - print("------------") - - print(world.get_path_to_friend(world.get_my_id())) + print(world.get_me()) + print(world.get_me().path_to_friend) + print("----------") + print(world.get_friend()) + print(world.get_friend().path_to_friend) + print("----------") + print(world.get_first_enemy()) + print(world.get_first_enemy().path_to_friend) + print("----------") + print(world.get_second_enemy()) + print(world.get_second_enemy().path_to_friend) def turn(self, world): print("turn") diff --git a/controller.py b/controller.py index 3cfe65b..3283063 100644 --- a/controller.py +++ b/controller.py @@ -12,6 +12,7 @@ class Controller: + def __init__(self): self.sending_flag = True self.conf = {} diff --git a/model.py b/model.py index 9598cc4..111a5cb 100644 --- a/model.py +++ b/model.py @@ -175,15 +175,24 @@ def add_unit(self, unit): class Path: - def __init__(self, id, cells): - self.cells = cells - self.id = id + def __init__(self, id=None, cells=None, path=None): + if id is not None and cells is not None: + self.cells = cells + self.id = id + if path is not None: + self.id = path.id + self.cells = [] + for cell in path.cells: + self.cells.append(cell) def __str__(self): return "".format(self.id, ["({}, {})".format(cell.row, cell.col) for cell in self.cells]) + def __eq__(self, other): + return self.id == other.id + class Deck: def __init__(self): diff --git a/world.py b/world.py index 0dba562..4b2431d 100644 --- a/world.py +++ b/world.py @@ -84,10 +84,14 @@ def _game_constant_init(self, game_constants_msg): hand_size=game_constants_msg["handSize"], deck_size=game_constants_msg["deckSize"]) - def _find_path_starting_or_ending_with(self, first_or_last, paths): + def _find_path_starting_and_ending_with(self, first, last, paths): for path in paths: - if path.cells[0] == first_or_last or path.cells[-1] == first_or_last: - return path + c_path = Path(path=path) + if c_path.cells[0] == first and c_path.cells[-1] == last: + return c_path + c_path.cells.reverse() + if c_path.cells[0] == first and c_path.cells[-1] == last: + return c_path return None def _map_init(self, map_msg): @@ -104,7 +108,7 @@ def _map_init(self, map_msg): self.players = [Player(player_id=map_msg["kings"][i]["playerId"], king=kings[i], deck=[], hand=[], ap=self.game_constants.max_ap, paths_from_player=[], - path_to_friend=self._find_path_starting_or_ending_with(kings[i].center, paths), + path_to_friend=self._find_path_starting_and_ending_with(kings[i].center, kings[i^1].center, paths), units=[], cast_area_spell=None, cast_unit_spell=None, duplicate_units=[], hasted_units=[], @@ -117,6 +121,7 @@ def _map_init(self, map_msg): self.player_friend = self.players[1] self.player_first_enemy = self.players[2] self.player_second_enemy = self.players[3] + self.map = Map(row_num=row_num, column_num=col_num, paths=paths, kings=kings, cells=input_cells, units=[]) def get_unit_by_id(self, unit_id): @@ -262,7 +267,7 @@ def _handle_turn_message(self, msg): self.player.hand = [self._get_base_unit_by_id(hand_type_id) for hand_type_id in msg["hand"]] self._handle_turn_kings(msg["kings"]) self._handle_turn_units(msg["units"]) - #self._handle_turn_units(msg=msg["diedUnits"], is_dead_unit=True) + self._handle_turn_units(msg=msg["diedUnits"], is_dead_unit=True) self._handle_turn_cast_spells(msg["castSpells"]) self.turn_updates = TurnUpdates(received_spell=msg["receivedSpell"],