def test_init_game() -> None: game = Game.init_game(8) assert game.current_disk == Disk.DARK assert game.board == init_board(8) assert game.get_legal_actions() == obtain_legal_actions( init_board(8), Disk.DARK) assert game.is_game_over() is False
def test_execute_action() -> None: board = init_board(4) new_board = execute_action(board, Disk.LIGHT, Position(1, 3)) config = np.array( [ [0, 0, 0, 0], [0, -1, -1, -1], [0, 1, -1, 0], [0, 0, 0, 0], ] ) assert new_board == Board(config) config = np.array( [ [0, -1, -1, 1], [-1, -1, -1, 1], [1, -1, -1, 1], [0, -1, -1, 1], ], dtype=np.int8, ) board = Board(config) new_board = execute_action(board, Disk.DARK, Position(0, 0)) after_config = np.array( [ [1, 1, 1, 1], [1, 1, -1, 1], [1, -1, 1, 1], [0, -1, -1, 1], ], dtype=np.int8, ) assert new_board == Board(after_config)
def test_obtain_legal_actions() -> None: board = init_board(4) assert obtain_legal_actions(board, Disk.LIGHT) == frozenset( [Position(0, 2), Position(1, 3), Position(2, 0), Position(3, 1)] ) board = Board(np.zeros((4, 4), dtype=np.int8)) assert obtain_legal_actions(board, Disk.LIGHT) == frozenset()
def test_init_board() -> None: config = np.array( [ [0, 0, 0, 0], [0, -1, 1, 0], [0, 1, -1, 0], [0, 0, 0, 0], ], np.int8, ) assert Board(config) == init_board(4)
def test_is_legal_action() -> None: board = init_board(4) assert not _is_legal_action(board, Disk.LIGHT, Position(0, 0)) assert not _is_legal_action(board, Disk.LIGHT, Position(0, 1)) assert _is_legal_action(board, Disk.LIGHT, Position(0, 2))
def init_game(length: int) -> Game: board = logic.init_board(length) return Game(board, Disk.DARK)