Skip to content

Commit

Permalink
fix two engines phase inconsistency
Browse files Browse the repository at this point in the history
solved r phase in dipcc issue

AMR device 0

fix empty order in dipcc R phase

fix arg for dipcc R phase
  • Loading branch information
Wichayaporn Wongkamjan authored and wwongkam committed May 15, 2023
1 parent 3aa5a9e commit b3676cc
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions fairdiplomacy_external/mila_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,19 @@ async def play_mila(

while not (self.game.is_game_done or self.game.get_current_phase() == "S1915M"):
self.phase_start_time = time.time()
self.dipcc_current_phase = self.game.get_current_phase()
self.dipcc_current_phase = self.dipcc_game.get_current_phase()

# fix issue that there is a chance where retreat phase appears in dipcc but not mila
while self.has_phase_changed():
await self.send_log(f'process dipcc game {self.dipcc_current_phase} to catch up with a current phase in mila {self.game.get_current_phase()}')
agent_orders = self.player.get_orders(self.dipcc_game)
if not agent_orders:
agent_orders = []
else:
agent_orders = [order for order in agent_orders]
self.dipcc_game.set_orders(power_name, agent_orders)
self.dipcc_game.process()
self.dipcc_current_phase = self.dipcc_game.get_current_phase()

# While agent is not eliminated
if not self.game.powers[power_name].is_eliminated():
Expand Down Expand Up @@ -270,9 +282,30 @@ async def play_mila(
await asyncio.sleep(0.25)

# ORDER

if not self.has_phase_changed():
print(f"Submit orders in {self.dipcc_current_phase}")
agent_orders = self.player.get_orders(self.dipcc_game)
incorrect_order = True
possible_orders = self.dipcc_game.get_all_possible_orders()

while incorrect_order:
all_correct = True
for order in agent_orders:
order_token = order.split(' ')
unit_loc = order_token[1]
is_correct = order in possible_orders[unit_loc]
all_correct = all_correct and is_correct
print(f'{order} is correct: {is_correct}')

if (self.game.get_current_phase().endswith('M') and len(agent_orders)>0 and all_correct) or \
(self.game.get_current_phase().endswith('R') and len(agent_orders)>=0 and all_correct) or \
(self.game.get_current_phase().endswith('A') and len(agent_orders)>=0 and all_correct):
incorrect_order = False
else:
print(f'submitting impossible orders: {agent_orders} to {self.dipcc_current_phase}')
await self.send_log(f'submitting impossible orders: {agent_orders} to {self.dipcc_current_phase}')
agent_orders = self.player.get_orders(self.dipcc_game)

# keep track of our final order
self.set_comm_intent('final', agent_orders)
Expand Down Expand Up @@ -554,7 +587,7 @@ def has_phase_changed(self)->bool:
"""
check game phase
"""
return self.dipcc_current_phase != self.game.get_current_phase()
return self.dipcc_game.get_current_phase() != self.game.get_current_phase()

def has_state_changed(self, power_name)->bool:
"""
Expand Down Expand Up @@ -596,7 +629,7 @@ def get_should_stop(self)->bool:
current_time = time.time()

# PRESS allows in movement phase (ONLY)
if not self.game.get_current_phase().endswith("M"):
if not self.dipcc_game.get_current_phase().endswith("M"):
return True
if self.has_phase_changed():
return True
Expand Down

0 comments on commit b3676cc

Please sign in to comment.