def test_create_board(): expected_spaces = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) board = TicTacToeState() assert np.array_equal(board.get_spaces(), expected_spaces)
def test_create_board_from_text(): text = """\ X.. .O. ... """ expected_spaces = np.array([[1, 0, 0], [0, -1, 0], [0, 0, 0]]) board = TicTacToeState(text) assert np.array_equal(board.get_spaces(), expected_spaces)
def test_create_board_with_coordinates(): text = """\ ABC 1 X.. 2 .O. 3 ... """ expected_spaces = np.array([[1, 0, 0], [0, -1, 0], [0, 0, 0]]) board = TicTacToeState(text) assert np.array_equal(board.get_spaces(), expected_spaces)
def test_create_training_data(): start_state = TicTacToeState() manager = SearchManager(start_state, FirstChoiceHeuristic()) expected_boards, expected_outputs = zip( *[[ start_state.get_spaces(), np.array([1., 0., 0., 0., 0., 0., 0., 0., 0., -1.]) ], [ TicTacToeState("""\ X.. ... ... """).get_spaces(), np.array([0., 1., 0., 0., 0., 0., 0., 0., 0., 1.]) ], [ TicTacToeState("""\ XO. ... ... """).get_spaces(), np.array([0., 0., 1., 0., 0., 0., 0., 0., 0., -1.]) ], [ TicTacToeState("""\ XOX ... ... """).get_spaces(), np.array([0., 0., 0., 1., 0., 0., 0., 0., 0., 1.]) ], [ TicTacToeState("""\ XOX O.. ... """).get_spaces(), np.array([0., 0., 0., 0., 1., 0., 0., 0., 0., -1.]) ], [ TicTacToeState("""\ XOX OX. ... """).get_spaces(), np.array([0., 0., 0., 0., 0., 1., 0., 0., 0., 1.]) ], [ TicTacToeState("""\ XOX OXO ... """).get_spaces(), np.array([0., 0., 0., 0., 0., 0., 1., 0., 0., -1.]) ]]) expected_boards = np.stack(expected_boards) expected_outputs = np.stack(expected_outputs) boards, outputs = manager.create_training_data(iterations=1, data_size=7) assert repr(boards) == repr(expected_boards) assert repr(outputs) == repr(expected_outputs)