Skip to content

Commit

Permalink
Nones handled
Browse files Browse the repository at this point in the history
  • Loading branch information
HamidrezaKmK committed Feb 4, 2020
1 parent a861dfd commit 76e8de9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 2 additions & 4 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def __init__(self, row_num, column_num, paths, units, kings, cells):
self.row_num = row_num
self.column_num = column_num
self.paths = paths
self.paths_dict = dict([(path.id, path) for path in paths])
self.units = units
self.kings = kings
self.cells = cells
Expand All @@ -19,10 +20,7 @@ def clear_units(self):
cell.clear_units()

def get_path_by_id(self, path_id):
for path in self.paths:
if path.path_id == path_id:
return path
return None
return self.paths_dict[path_id]

def add_unit_in_cell(self, row, column, unit):
self.cells[row][column].add_unit(unit)
Expand Down
6 changes: 6 additions & 0 deletions world.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,17 @@ def get_current_turn(self):

# put unit_id in path_id in position 'index' all spells of one kind have the same id
def cast_unit_spell(self, unit_id, path_id, index, spell=None, spell_id=None):
if spell is None and spell_id is None:
return None
path = None
for p in self.map.paths:
if p.path_id == path_id:
path = p
break
if path is None:
return None
if index < len(path.cells):
return None
cell = path.cells[index]
if spell is None:
spell = self.get_spell_by_type_id(spell_id)
Expand Down

0 comments on commit 76e8de9

Please sign in to comment.