예제 #1
0
def test_build_move_map():
    """Check that the move map is being built correctly.
    """
    board = Board()

    # Player 0
    moves = board.get_legal_moves(player=0)
    assert len(board.move_map_player_0) == len(moves)
    assert all([type(v) == int for v in board.move_map_player_0.values()])
    assert all([type(k) == tuple for k in board.move_map_player_0.keys()])

    # Player 1
    moves = board.get_legal_moves(player=1)
    assert len(board.move_map_player_1) == len(moves)
    assert all([type(v) == int for v in board.move_map_player_1.values()])
    assert all([type(k) == tuple for k in board.move_map_player_1.keys()])
예제 #2
0
def test_get_legal_moves():
    """Check that the function generates all possible moves when the board is
    empty.
    """
    board = Board()

    empty_spaces = board.get_empty_spaces()
    legal_moves = board.get_legal_moves(player=0)

    for space in empty_spaces:
        q, r = space
        assert ((q, r, 1), ()) in legal_moves
        assert ((q, r, 2), ()) in legal_moves

    for (space1, space2) in permutations(empty_spaces, r=2):
        assert ((space1[0], space1[1], 1), (space2[0], space2[1],
                                            2)) in legal_moves