Skip to content

Commit

Permalink
Make test_finished_game_state work regardless of movegen order
Browse files Browse the repository at this point in the history
  • Loading branch information
nhamil committed Nov 21, 2023
1 parent c06db29 commit ac927a2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tilewe/tests/test_gameplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ def test_no_moves_is_finished(self):
def test_finished_game_state(self):
random.seed(0)
board = tilewe.Board(4)
engine = RandomEngine()

# play a game until the state is marked finished
tracked_ply = 0
while not board.finished:
board.push(engine.search(board))
board.push(random.choice(sorted(board.generate_legal_moves(), key=lambda m: str(m))))

# assert that the game finishes before 84 moves (i.e. no infinite loop)
tracked_ply += 1
Expand All @@ -63,20 +62,21 @@ def test_finished_game_state(self):
self.assertEqual(board.n_player_corners(i), 0)

expected_game = [
'T5e-c3t20', 'P5sf-a3a20', 'P5sf-b1t1', 'Z5e-a1a1', 'Z4n-c1q18', 'I4n-a4c17', 'N5nf-b1r4', 'L5e-a1d4',
'L4wf-c1n18', 'L4s-b1d18', 'I2n-a1s7', 'F5w-c2c6', 'F5wf-c3k17', 'Y5nf-a4d13', 'L5ef-d2p5', 'I3e-a1d7',
'Y5w-d2k20', 'Z5n-c1c9', 'V5n-c1p8', 'U5n-a2e3', 'W5w-a3k14', 'T4w-a1e14', 'F5ef-c2l4', 'I2e-a1b8',
'O1n-a1n20', 'U5n-a2e9', 'U5n-a2i2', 'Y5n-a3h6', 'T4n-a2n14', 'V5w-a3f13', 'O1n-a1o11', 'N5e-a2j8',
'P5w-c1h18', 'I2e-a1i14', 'Y5sf-a2q11', 'L3e-b2i9', 'V5n-c3k12', 'O1n-a1h15', 'L3s-b1q14', 'V5n-c1g10',
'L3e-a2r17', 'L5n-b1b13', 'L4nf-b3q3', 'O1n-a1k6', 'I3n-a3s15', 'L3e-a1g16', 'T4w-b2o2', 'W5e-b1m9',
'I2e-b1e17', 'F5s-a1k15', 'Z4nf-b1o16', 'T4w-a1n11', 'I4n-a4t12', 'Z4nf-a1i18', 'I3n-a3t6', 'Z4nf-a1n6',
'T5e-c1h3', 'T5w-a1q8', 'I4e-d1g6', 'L4e-a1m14', 'Z5e-c3c5']
'Z4e-a1a1', 'P5n-a3a20', 'W5n-c3t20', 'Z5ef-c1t1', 'T5e-c1c4', 'F5n-b3b17', 'L4w-c1q19', 'T4w-a1s4',
'Y5wf-a2d7', 'X5n-a2d16', 'Y5wf-d2n18', 'Y5nf-b3q4', 'O1n-a1h6', 'Z5ef-c1f18', 'O4n-a2n16', 'P5wf-c1r7',
'L5e-a2d3', 'V5n-c3c14', 'I3e-a1p14', 'L5sf-b4o8', 'I2e-a1i7', 'L3w-b2g15', 'T4s-b2m14', 'V5w-c1m9',
'L4e-a1h8', 'Y5w-b1h16', 'X5n-c2k14', 'I5e-e1m4', 'P5sf-b1g10', 'I3n-a3h13', 'Z4e-b2j19', 'F5sf-b3h3',
'N5wf-c2k6', 'T5s-a1i10', 'U5w-a3s15', 'I3n-a3n3', 'L3w-a1k8', 'W5e-a3d11', 'O1n-a1h15', 'O1n-a1j2',
'U5w-b1c8', 'L4ef-a2k16', 'N5w-a2o12', 'W5w-b2s9', 'W5w-c1e13', 'O1n-a1i15', 'I2n-a2i12', 'I2e-b1h5',
'T4w-b2b14', 'Z4nf-a1n17', 'F5e-b3o10', 'L3n-b1f1', 'U5n-a2q17', 'Z5ef-a3o7', 'T5s-c1f4', 'I2e-a1g20',
'T5e-c3m8', 'L4nf-b3c3', 'L5wf-d1n19', 'N5w-a2n14', 'T4n-a2r12'
]
all_moves = [str(move) for move in board.moves]

# assert that the expected game was played
unexpected_game_msg = "Expected game not played, was generate_legal_moves() changed intentionally?"
self.assertEqual(all_moves, expected_game, unexpected_game_msg)
self.assertEqual(board.winners, [2], unexpected_game_msg)
self.assertEqual(board.winners, [1], unexpected_game_msg)

def test_open_corners_first_moves(self):
engine = RandomEngine()
Expand Down

0 comments on commit ac927a2

Please sign in to comment.