Exemple #1
0
def test_select_first_child():
    start_state = TicTacToeState()
    expected_leaf_board = start_state.make_move(0)
    expected_leaf = SearchNode(expected_leaf_board)

    node = SearchNode(start_state)
    node.record_value(1)

    leaf = node.select_leaf()

    assert leaf == expected_leaf
    assert node.average_value == -1.0
Exemple #2
0
def test_search_manager_reuses_node():
    start_state = TicTacToeState()
    manager = SearchManager(start_state, Playout())
    manager.search(start_state, iterations=10)
    move = manager.get_best_move()
    state2 = start_state.make_move(move)
    node = manager.current_node

    first_value_count = node.value_count
    manager.search(state2, iterations=10)
    second_value_count = node.value_count

    assert first_value_count > 0
    assert first_value_count + 10 == second_value_count
Exemple #3
0
def test_search_manager_with_opponent():
    """ Like when opponent is not sharing the SearchManager. """
    start_state = TicTacToeState()
    manager = SearchManager(start_state, Playout())
    manager.search(start_state, iterations=10)
    node = manager.current_node.children[0]  # Didn't call get_best_move().
    move = 0
    state2 = start_state.make_move(move)

    first_value_count = node.value_count
    manager.search(state2, iterations=10)
    second_value_count = node.value_count

    assert first_value_count > 0
    assert first_value_count + 10 == second_value_count
def test_make_move_o():
    text = """\
XX.
.O.
...
"""
    move = 3
    expected_display = """\
XX.
OO.
...
"""
    board1 = TicTacToeState(text)
    board2 = board1.make_move(move)
    display = board2.display()

    assert display == expected_display