From ed79dc31b39cc095c4e6005d83bf5eba907ff4f9 Mon Sep 17 00:00:00 2001 From: hamidrezakamkari Date: Tue, 4 Feb 2020 11:23:16 +0330 Subject: [PATCH] path to friend bug fixed --- AI.py | 10 ++++++---- model.py | 4 ++-- world.py | 12 ++++++------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/AI.py b/AI.py index 1b80206..c2dac2d 100644 --- a/AI.py +++ b/AI.py @@ -1,13 +1,13 @@ class AI: def pick(self, world): + print("pick") #self.path_to_friend_check(world) world.choose_deck([1, 2, 3, 4]) + def path_to_friend_check(self, world): # path check: - print("pick") - world.choose_deck([1, 2, 3, 4]) print(world.get_me()) print(world.get_me().path_to_friend) print("----------") @@ -22,5 +22,7 @@ def path_to_friend_check(self, world): def turn(self, world): print("turn") - for item in world.get_me().hand: - print(item) + if world.get_current_turn() == 20: + print("its turn 2!!!") + world.put_unit(base_unit=world.get_me().hand[0], path=world.get_me().paths_from_player[0]) + diff --git a/model.py b/model.py index 8f47b9e..2bbb187 100644 --- a/model.py +++ b/model.py @@ -20,7 +20,7 @@ def clear_units(self): cell.clear_units() def get_path_by_id(self, path_id): - return self.paths_dict[path_id] + return None if not path_id in self.paths_dict else self.paths_dict[path_id] def add_unit_in_cell(self, row, column, unit): self.cells[row][column].add_unit(unit) @@ -210,7 +210,7 @@ def __init__(self, type_id, max_hp, base_attack, base_range, target_type, is_fly def __str__(self): return "".format(self.type_id) class King: diff --git a/world.py b/world.py index 25339ec..00c3ea6 100644 --- a/world.py +++ b/world.py @@ -118,6 +118,9 @@ def _map_init(self, map_msg): range_upgraded_unit=None, damage_upgraded_unit=None) for i in range(4)] + for player in self.players: + player.paths_from_player.remove(player.path_to_friend) + self.player = self.players[0] self.player_friend = self.players[1] self.player_first_enemy = self.players[2] @@ -210,7 +213,7 @@ def _handle_turn_units(self, msg, is_dead_unit=False): target=unit_msg["target"], target_cell=target_cell, affected_spells=[self.get_cast_spell_by_id(cast_spell_id) for cast_spell_id in unit_msg["affectedSpells"]], - target_if_king=self.get_player_by_id(unit_msg["target"]).king, + target_if_king=None if self.get_player_by_id(unit_msg["target"]) == None else self.get_player_by_id(unit_msg["target"]).king, player_id=unit_msg["playerId"]) if not is_dead_unit: self.map.add_unit_in_cell(unit.cell.row, unit.cell.col, unit) @@ -398,9 +401,9 @@ def put_unit(self, type_id=None, path_id=None, base_unit=None, path=None): if base_unit is not None: type_id = base_unit.type_id if path is not None: - path_id = path.path_id + path_id = path.id if path_id is None or type_id is None: - return + return None message = Message(turn=self.get_current_turn(), type="putUnit", info={ @@ -581,9 +584,6 @@ def get_base_unit_by_id(self, type_id): def get_game_constants(self): return self.game_constants - def get_paths_from_player(self, player_id): - pass - def _get_paths_starting_with(self, first, paths): ret = [] for path in paths: