Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Game.py to fix an issue #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions diplomacy/engine/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ def get_orders(self, power_name=None):
power = self.get_power(power_name)

# Getting orders for a particular power
# Skipping VOID and WAIVE orders in Adjustment/Retreats phase
# Skipping WAIVE orders but preserving VOID in Adjustment/Retreats phase
if power_name is not None:
if self.get_current_phase()[-1] == 'M':
if 'NO_CHECK' in self.rules:
Expand All @@ -970,7 +970,7 @@ def get_orders(self, power_name=None):
power_orders = ['{} {}'.format(unit, unit_order) for unit, unit_order in power.orders.items()]
else:
power_orders = [order for order in power.adjust
if order and order != 'WAIVE' and order.split()[0] != 'VOID']
if order and order != 'WAIVE'] # and order.split()[0] != 'VOID']
return power_orders

# Recursively calling itself to get all powers
Expand Down Expand Up @@ -4248,6 +4248,8 @@ def _move_results(self):
power.units.remove(unit)

# Adding
# annotate_move_results
self.result[unit] = ["-> %s" % (new_unit[2:],)]
new_unit = unit[:2] + self.command[unit].split()[-1 - offset]
self.update_hash(power.name, unit_type=new_unit[0], loc=new_unit[2:])
power.units += [new_unit]
Expand All @@ -4262,6 +4264,7 @@ def _move_results(self):
if destroyed:
for unit, power in destroyed.items():
if unit in power.retreats:
self.result[unit] += ["disbanded"]
self.update_hash(power.name, unit_type=unit[0], loc=unit[2:], is_dislodged=True)
del power.retreats[unit]

Expand Down Expand Up @@ -4324,6 +4327,9 @@ def _other_results(self):
unit = ' '.join(word[:2])
if word[-1] == 'B':
diff += 1
if ("WAIVE" == unit):
self.result.setdefault(unit, []).append(power.name)
#else:
else:
self.result.setdefault(unit, []).append(VOID)
power.adjust.remove(order)
Expand All @@ -4334,6 +4340,8 @@ def _other_results(self):
unit = ' '.join(word[:2])
if word[-1] == 'D':
diff -= 1
self.result.setdefault(unit, []).append("chose disband")

disbanded_units.add(unit)
else:
self.result.setdefault(unit, []).append(VOID)
Expand Down Expand Up @@ -4376,7 +4384,7 @@ def _other_results(self):
else:
del armies[goner]
power.adjust += ['%s D' % goner]
self.result.setdefault(goner, [])
self.result.setdefault(goner, ["dislodged/disband"])

# Need to build units
else:
Expand All @@ -4394,13 +4402,17 @@ def _other_results(self):
for retreats in power.retreats:
self.result[retreats] = []

# Emptying void orders - And marking them as such
# Emptying void orders - And marking them as such
for power in self.powers.values():
for order in power.adjust[:]:
if order.split()[0] == 'VOID':
word = order.split()[1:]
unit = ' '.join(word[:2])
self.result[unit] = [VOID]
if ('B' == order[-1]):
whichAction = 'B'
else:
whichAction = 'D'
self.result[unit] = ["%s %s void" % (power.name, whichAction)]
if unit not in self.ordered_units[power.name]:
self.ordered_units[power.name] += [unit]
power.adjust.remove(order)
Expand Down Expand Up @@ -4443,9 +4455,9 @@ def _other_results(self):
self.update_hash(power.name, unit_type=unit[0], loc=unit[2:])
power.units += [' '.join(word[:2])]
diff += 1
self.result[unit] += [OK]
self.result[unit] += ["%s builds %s" % (power.name, unit)]
else:
self.result[unit] += [VOID]
self.result[unit] += ["%s B void" % (power.name,)]
if unit not in self.ordered_units[power.name]:
self.ordered_units[power.name] += [unit]

Expand All @@ -4455,9 +4467,9 @@ def _other_results(self):
self.update_hash(power.name, unit_type=unit[0], loc=unit[2:])
power.units.remove(' '.join(word[:2]))
diff -= 1
self.result[unit] += [OK]
self.result[unit] += ["%s disbands %s" % (power.name, unit)]
else:
self.result[unit] += [VOID]
self.result[unit] += ["%s D void" % (power.name,)]
if unit not in self.ordered_units[power.name]:
self.ordered_units[power.name] += [unit]

Expand All @@ -4474,19 +4486,25 @@ def _other_results(self):
if word[-1] in influence_power.influence:
influence_power.influence.remove(word[-1])
power.influence.append(word[-1])

self.result[unit] += [word[3]]
if unit not in self.ordered_units[power.name]:
self.ordered_units[power.name] += [unit]

elif word[-1] == 'D' and self.phase_type == 'R':
self.dislodged[unit] = word[2] # self.dislodged is one vector for the whole board
#debug print ("bef %s" % (self.result[unit],))
self.result[unit] += [DISBAND]
#debug print ("aft %s" % (self.result[unit],))
for dis_unit in power.retreats:
self.update_hash(power.name, unit_type=dis_unit[0], loc=dis_unit[2:], is_dislodged=True)
power.adjust, power.retreats, power.civil_disorder = [], {}, 0

# Disbanding
for unit in [u for u in self.dislodged]:
self.result.setdefault(unit, [])
if DISBAND not in self.result[unit]:
self.result[unit] += [DISBAND]
if DISBAND in self.result[unit]:
self.result[unit] = ["chose disband"]
else:
self.result[unit] += ["dislodged/disbanded"]
del self.dislodged[unit]
if unit not in self.popped:
self.popped += [unit]
Expand Down