From f809b43d34344ba859658469c58d0de1c2110c97 Mon Sep 17 00:00:00 2001 From: Philip Paquette Date: Fri, 2 Nov 2018 16:23:52 -0400 Subject: DATC 6.K.2 - Testing support of fleet in failed convoy --- diplomacy/engine/game.py | 14 ++++++++++---- diplomacy/tests/test_datc.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/diplomacy/engine/game.py b/diplomacy/engine/game.py index a71d486..f386c73 100644 --- a/diplomacy/engine/game.py +++ b/diplomacy/engine/game.py @@ -3801,12 +3801,18 @@ class Game(Jsonable): coord = self.command[guy].split() # 1) Void if support is for hold and guy is moving + if len(word) < 5 and coord[0] == '-': + self.result[unit] += ['void'] + continue + # 2) Void if support is for move and guy isn't going where support is given - # 3) Void if support is give, but move over convoy failed offset = 1 if coord[-1] == 'VIA' else 0 - if ((len(word) < 5 and coord[0] == '-') - or (len(word) > 4 and (coord[0], coord[-1 - offset]) != ('-', word[4])) - or 'no convoy' in self.result[guy]): + if len(word) > 4 and (coord[0], coord[-1 - offset]) != ('-', word[4]): + self.result[unit] += ['void'] + continue + + # 3) Void if support is giving for army moving via convoy, but move over convoy failed + if 'no convoy' in self.result[guy] and guy[0] == 'A': self.result[unit] += ['void'] continue diff --git a/diplomacy/tests/test_datc.py b/diplomacy/tests/test_datc.py index 469867e..02b1683 100644 --- a/diplomacy/tests/test_datc.py +++ b/diplomacy/tests/test_datc.py @@ -5417,6 +5417,46 @@ class TestDATC(): assert self.owner_name(game, 'F BOT') is None assert self.owner_name(game, 'F STP/NC') is None + def test_6_k_2(self): + """ 6.K.2. TEST CASE, SUPPORT OF A FAILED CONVOYING FLEET + The engine is supposed to not allow the support of an army moving via a convoy if the convoy fails. This + rule tests that a support of a fleet convoying is still valid even if the convoy fails. + + France has 4 units (Fleets in Mid-Atlantic, Irish Sea, Western Mediterranean, and army in Brest) + England has 2 units (Fleets in North Atlantic, and English Channel). + France: The army in Brest wants to move via convoy to Clyde. + France: The fleet in Mid-Atlantic convoys the army in Brest to Clyde. + France: The fleet in Irish Sea convoys the army in Brest to Clyde. + France: The fleet in Western Mediterranean supports the fleet in Mid-Atlantic. + England: The fleet in North Atlantic attacks the fleet in Mid-Atlantic. + England: The fleet in English Channel supports the attack of North Atlantic to Mid-Atlantic. + + The convoy fails because they are no valid path, but the support from Western Mediterranean is still valid + and the attack from North Atlantic should bounce. + """ + game = self.create_game() + self.clear_units(game) + self.clear_centers(game) + self.set_units(game, 'FRANCE', ['F MAO', 'F IRI', 'A BRE', 'F WES']) + self.set_units(game, 'ENGLAND', ['F NAO', 'F ENG']) + self.set_orders(game, 'FRANCE', ['F MAO C A BRE - CLY', 'F IRI C A BRE - CLY', 'A BRE - CLY VIA', + 'F WES S F MAO']) + self.set_orders(game, 'ENGLAND', ['F NAO - MAO', 'F ENG S F NAO - MAO']) + self.process(game) + assert self.check_results(game, 'F MAO', 'no convoy') + assert self.check_results(game, 'F IRI', 'no convoy') + assert self.check_results(game, 'A BRE', 'no convoy') + assert self.check_results(game, 'F WES', '') + assert self.check_results(game, 'F NAO', 'bounce') + assert self.check_results(game, 'F ENG', '') + assert self.owner_name(game, 'F MAO') == 'FRANCE' + assert self.owner_name(game, 'F IRI') == 'FRANCE' + assert self.owner_name(game, 'A BRE') == 'FRANCE' + assert self.owner_name(game, 'F WES') == 'FRANCE' + assert self.owner_name(game, 'A CLY') is None + assert self.owner_name(game, 'F NAO') == 'ENGLAND' + assert self.owner_name(game, 'F ENG') == 'ENGLAND' + def check_dislodged(game, unit, dislodger): """ Checks if a unit has been dislodged """ if not game: -- cgit v1.2.3