def test_first_layer(tg, player): """Test computing the first layer in open field.""" mm = MiniMax(tg, player) mm.compute_next_layer() assert len(mm.layers) == 1 assert len(mm.layers[0]) == 4 assert {state.moves[0].direction for state in mm.layers[0]} ==\ set(tg.DIRECTIONS.keys()) for state in mm.layers[0]: assert len(state.moves) == 1 move = state.moves[0] assert move.player_number == 1 assert move.is_mine is True assert mm.my_pos + tg.DIRECTIONS[move.direction] == state.player2pos[1]
def test_second_layer(tg, player): """Test computing two layers in open field with opponent next to wall.""" mm = MiniMax(tg, player) mm.compute_next_layer() mm.compute_next_layer() assert len(mm.layers) == 2 assert len(mm.layers[0]) == 4 assert len(mm.layers[1]) == 12 for state in mm.layers[0]: assert state.next_player == 2 assert len(state.next_states) == 3 assert {nstate.moves[1].direction for nstate in state.next_states} ==\ set(tg.DIRECTIONS.keys()) - {'LEFT'} for nstate in state.next_states: assert nstate.player_number == 2 assert nstate.prev_state == state assert len(nstate.moves) == 2 move = nstate.moves[1] assert move.is_mine == False assert move.player_number == 2 assert mm.opponents[2] + tg.DIRECTIONS[move.direction] ==\ nstate.player2pos[2]