Skip to content

Commit

Permalink
path to friend bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
HamidrezaKmK committed Feb 4, 2020
1 parent 8622e3c commit ed79dc3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
10 changes: 6 additions & 4 deletions AI.py
Original file line number Diff line number Diff line change
@@ -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("----------")
Expand All @@ -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])

4 changes: 2 additions & 2 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -210,7 +210,7 @@ def __init__(self, type_id, max_hp, base_attack, base_range, target_type, is_fly

def __str__(self):
return "<BaseUnit | " \
"type id : {}".format(self.type_id)
"type id : {}>".format(self.type_id)


class King:
Expand Down
12 changes: 6 additions & 6 deletions world.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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={
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ed79dc3

Please sign in to comment.