Skip to content

Commit

Permalink
path bug equals and path to friend fixed!
Browse files Browse the repository at this point in the history
  • Loading branch information
HamidrezaKmK committed Feb 4, 2020
1 parent 4552bfb commit f82ef02
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
19 changes: 12 additions & 7 deletions AI.py
Original file line number Diff line number Diff line change
@@ -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")
1 change: 1 addition & 0 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


class Controller:

def __init__(self):
self.sending_flag = True
self.conf = {}
Expand Down
15 changes: 12 additions & 3 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<Path | " \
"path id : {} | " \
"cells: {}>".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):
Expand Down
15 changes: 10 additions & 5 deletions world.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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=[],
Expand All @@ -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):
Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit f82ef02

Please sign in to comment.