Skip to content

Commit

Permalink
Merge pull request #258 from johnpooch/develop
Browse files Browse the repository at this point in the history
0.5.2
  • Loading branch information
johnpooch authored May 6, 2021
2 parents 613d284 + c2228c8 commit 7746215
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 91 deletions.
9 changes: 5 additions & 4 deletions adjudicator/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def process(state):
supports = [o for o in orders if o.is_support]
convoys = [o for o in orders if o.is_convoy]
builds = [o for o in orders if o.is_build]
disbands = [o for o in orders if o.is_disband]

illegal_retreats = [r for r in retreats if r.illegal]
# set illegal retreats to fail.
Expand Down Expand Up @@ -96,11 +97,11 @@ def process(state):
'Destroyed because piece cannot retreat to any neighboring '
'territories.'
)
for build in builds:
if build.legal:
build.outcome = Outcomes.SUCCEEDS
for o in [*builds, *disbands]:
if o.legal:
o.outcome = Outcomes.SUCCEEDS
else:
build.outcome = Outcomes.FAILS
o.outcome = Outcomes.FAILS

if state.phase == Phase.RETREAT:
for piece in state.pieces:
Expand Down
124 changes: 37 additions & 87 deletions core/tests/test_adjudicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ def setUp(self):
self.st_petersburg_south_coast = models.NamedCoast.objects.get(id='standard-st-petersburg-south-coast')
self.st_petersburg_north_coast = models.NamedCoast.objects.get(id='standard-st-petersburg-north-coast')

def test_move_st_petersburg_south_coast_to_gulf_of_bothnia(self):
piece = models.Piece.objects.create(
game=self.game,
type=PieceType.FLEET,
nation=self.russia,
)
gulf_of_bothnia = models.Territory.objects.get(id='standard-gulf-of-bothnia')
for nation in models.Nation.objects.all():
models.NationState.objects.create(
nation=nation,
Expand All @@ -51,6 +44,14 @@ def test_move_st_petersburg_south_coast_to_gulf_of_bothnia(self):
territory=territory,
turn=self.turn,
)

def test_move_st_petersburg_south_coast_to_gulf_of_bothnia(self):
piece = models.Piece.objects.create(
game=self.game,
type=PieceType.FLEET,
nation=self.russia,
)
gulf_of_bothnia = models.Territory.objects.get(id='standard-gulf-of-bothnia')
models.PieceState.objects.create(
named_coast=self.st_petersburg_south_coast,
piece=piece,
Expand Down Expand Up @@ -81,16 +82,6 @@ def test_move_st_petersburg_north_coast_to_norway(self):
type=PieceType.FLEET,
nation=self.russia,
)
for nation in models.Nation.objects.all():
models.NationState.objects.create(
nation=nation,
turn=self.turn,
)
for territory in models.Territory.objects.all():
models.TerritoryState.objects.create(
territory=territory,
turn=self.turn,
)
models.PieceState.objects.create(
named_coast=self.st_petersburg_north_coast,
piece=piece,
Expand All @@ -116,16 +107,6 @@ def test_move_from_liverpool_to_london(self):
)
liverpool = models.Territory.objects.get(id='standard-liverpool')
london = models.Territory.objects.get(id='standard-london')
for nation in models.Nation.objects.all():
models.NationState.objects.create(
nation=nation,
turn=self.turn,
)
for territory in models.Territory.objects.all():
models.TerritoryState.objects.create(
territory=territory,
turn=self.turn,
)
models.PieceState.objects.create(
piece=piece,
territory=liverpool,
Expand Down Expand Up @@ -154,16 +135,6 @@ def test_turkey_does_not_take_bulgaria(self):
)
bulgaria = models.Territory.objects.get(id='standard-bulgaria')
greece = models.Territory.objects.get(id='standard-greece')
for nation in models.Nation.objects.all():
models.NationState.objects.create(
nation=nation,
turn=self.turn,
)
for territory in models.Territory.objects.all():
models.TerritoryState.objects.create(
territory=territory,
turn=self.turn,
)
models.PieceState.objects.create(
piece=piece,
territory=bulgaria,
Expand All @@ -188,21 +159,11 @@ def test_build_fleet_st_petersburg_north_coast(self):
self.turn.season = Season.FALL
self.turn.phase = Phase.BUILD
self.turn.save()
for nation in models.Nation.objects.all():
models.NationState.objects.create(
nation=nation,
turn=self.turn,
)
models.TerritoryState.objects.create(
controlled_by=self.russia,
territory=self.st_petersburg,
turn=self.turn,
)
for territory in models.Territory.objects.exclude(id=self.st_petersburg.id):
models.TerritoryState.objects.create(
territory=territory,
turn=self.turn,
)
order = models.Order.objects.create(
nation=self.russia,
source=self.st_petersburg,
Expand All @@ -223,16 +184,6 @@ def test_build_fleet_st_petersburg_north_coast(self):
def test_illegal_retreat_removes_piece(self):
self.turn.phase = Phase.RETREAT
self.turn.save()
for nation in models.Nation.objects.all():
models.NationState.objects.create(
nation=nation,
turn=self.turn,
)
for territory in models.Territory.objects.all():
models.TerritoryState.objects.create(
territory=territory,
turn=self.turn,
)
piece = models.Piece.objects.create(
game=self.game,
type=PieceType.ARMY,
Expand Down Expand Up @@ -264,16 +215,6 @@ def test_illegal_retreat_removes_piece(self):
def test_contested_retreat_removes_piece(self):
self.turn.phase = Phase.RETREAT
self.turn.save()
for nation in models.Nation.objects.all():
models.NationState.objects.create(
nation=nation,
turn=self.turn,
)
for territory in models.Territory.objects.all():
models.TerritoryState.objects.create(
territory=territory,
turn=self.turn,
)
st_petersburg_state = models.TerritoryState.objects.get(territory=self.st_petersburg)
st_petersburg_state.contested = True
st_petersburg_state.save()
Expand Down Expand Up @@ -309,16 +250,6 @@ def test_contested_retreat_removes_piece(self):
def test_failed_retreat_removes_piece(self):
self.turn.phase = Phase.RETREAT
self.turn.save()
for nation in models.Nation.objects.all():
models.NationState.objects.create(
nation=nation,
turn=self.turn,
)
for territory in models.Territory.objects.all():
models.TerritoryState.objects.create(
territory=territory,
turn=self.turn,
)
piece_norway = models.Piece.objects.create(
game=self.game,
type=PieceType.ARMY,
Expand Down Expand Up @@ -376,16 +307,6 @@ def test_failed_retreat_removes_piece(self):
def test_no_order_removes_piece(self):
self.turn.phase = Phase.RETREAT
self.turn.save()
for nation in models.Nation.objects.all():
models.NationState.objects.create(
nation=nation,
turn=self.turn,
)
for territory in models.Territory.objects.all():
models.TerritoryState.objects.create(
territory=territory,
turn=self.turn,
)
st_petersburg_state = models.TerritoryState.objects.get(territory=self.st_petersburg)
st_petersburg_state.contested = True
st_petersburg_state.save()
Expand All @@ -407,3 +328,32 @@ def test_no_order_removes_piece(self):
self.assertTrue(piece_state.destroyed)
self.assertTrue(piece.turn_destroyed, self.turn)
self.assertEqual(new_turn.piecestates.count(), 0)

def test_disband(self):
self.turn.phase = Phase.BUILD
self.turn.save()
piece = models.Piece.objects.create(
game=self.game,
type=PieceType.ARMY,
nation=self.russia,
)
piece_state = models.PieceState.objects.create(
piece=piece,
territory=self.st_petersburg,
turn=self.turn,
must_retreat=True,
)
order_st_petersburg = models.Order.objects.create(
nation=self.russia,
source=self.st_petersburg,
turn=self.turn,
type=OrderType.DISBAND,
)
new_turn = process_turn(self.turn)
order_st_petersburg.refresh_from_db()
piece.refresh_from_db()
piece_state.refresh_from_db()

self.assertEqual(order_st_petersburg.outcome, OutcomeType.SUCCEEDS)
self.assertTrue(piece.turn_disbanded, self.turn)
self.assertEqual(new_turn.piecestates.count(), 0)

0 comments on commit 7746215

Please sign in to comment.