diff options
author | Philip Paquette <pcpaquette@gmail.com> | 2019-05-19 22:08:49 -0400 |
---|---|---|
committer | Philip Paquette <pcpaquette@gmail.com> | 2019-05-19 22:52:20 -0400 |
commit | 7d948fed1f9bfc40b17f9a057f75990cfd66c5f1 (patch) | |
tree | d7ffdb772e4a8cc223f3f19071cfed55e83edfd9 | |
parent | 33fc44659e8d61102c639e73a0c72a93485f1dc4 (diff) |
Prevent duplicate units and centers with set_units and set_centers
-rw-r--r-- | diplomacy/engine/game.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/diplomacy/engine/game.py b/diplomacy/engine/game.py index 7bf11a2..dd5b7a4 100644 --- a/diplomacy/engine/game.py +++ b/diplomacy/engine/game.py @@ -958,12 +958,12 @@ class Game(Jsonable): for power in self.powers.values(): for unit in regular_units: unit_loc = unit[2:5] - for unit_to_remove in [p_unit for p_unit in power.units if p_unit[2:5] == unit_loc]: + for unit_to_remove in {p_unit for p_unit in power.units if p_unit[2:5] == unit_loc}: self.update_hash(power.name, unit_type=unit_to_remove[0], loc=unit_to_remove[2:]) power.units.remove(unit_to_remove) for unit in dislodged_units: unit_loc = unit[2:5] - for unit_to_remove in [p_unit for p_unit in power.retreats if p_unit[2:5] == unit_loc]: + for unit_to_remove in {p_unit for p_unit in power.retreats if p_unit[2:5] == unit_loc}: self.update_hash(power.name, unit_type=unit_to_remove[0], loc=unit_to_remove[2:], is_dislodged=True) del power.retreats[unit_to_remove] for loc in influence: @@ -982,7 +982,7 @@ class Game(Jsonable): if unit_type in ('A', 'F') \ and unit_loc in [loc.upper() for loc in self.map.locs] \ and self.map.is_valid_unit(unit): - if power: + if power and unit not in power.units: self.update_hash(power_name, unit_type=unit_type, loc=unit_loc) power.units.append(unit) power.influence.append(unit[2:5]) @@ -998,7 +998,7 @@ class Game(Jsonable): if unit_type in ('A', 'F') and unit_loc in [loc.upper() for loc in self.map.locs]: abuts = [abut.upper() for abut in self.map.abut_list(unit_loc, incl_no_coast=True) if self._abuts(unit_type, unit_loc, '-', abut.upper())] - if power: + if power and unit not in power.retreats: self.update_hash(power_name, unit_type=unit_type, loc=unit_loc, is_dislodged=True) power.retreats[unit] = abuts @@ -1033,7 +1033,7 @@ class Game(Jsonable): power = self.get_power(power_name) if power: for center in centers: - if center in self.map.scs: + if center in self.map.scs and center not in power.centers: self.update_hash(power_name, loc=center, is_center=True) power.centers += [center] |