def test_move_returns_False_if_move_string_is_not_a_move(self): game = Game() game.reset() assert not game.move("invalid move") assert not game.move("5.5-4.4") assert not game.move("18 14") assert not game.move("18_14")
def test_valid_moves_do_not_include_backwards_moves(self): game = Game() game.reset() game.move("26-23") game.move("7-11") assert "23-26" not in game.valid_moves("white") assert "11-7" not in game.valid_moves("black")
def test_black_wins_if_white_has_no_pieces(self): game = Game() game.reset() game.change_turn() for _ in range(8): game._remove_piece() assert game.game_over() assert game.result == "black"
def test_game_is_over_if_no_pieces_remaining(self): game = Game() game.reset() assert not game.game_over() for _ in range(8): game._remove_piece() assert game.game_over() assert game.result == "white"
def test_other_play_wins_if_no_valid_moves(self): game = Game() game.reset() game.valid_moves = mock.Mock(return_value=[]) assert game.game_over() assert game.result == "black" game.turn = "black" assert game.game_over() assert game.result == "white"
def test_that_reset_resets_game(self): game = Game() game._board._board[5, 4] = Piece("white", None) game._move_list = [1, 2, 3, 4] game.turn = "black" game._pieces_remaining = {"white": 5, "black": 6} game.reset() assert np.array_equal(game._board._board, new_board) assert game._move_list == [] assert game.turn == "white" assert game._pieces_remaining == {"white": 8, "black": 8}
def test_valid_moves_include_backwards_moves_for_kings(self): game = Game() game.reset() game._board._board[4, 3] = King("white", None) game._board._board[4, 5] = King("black", None) white_moves = game.valid_moves("white") for move in ["18-14", "18-15", "18-22", "18-23"]: assert move in white_moves black_moves = game.valid_moves("black") for move in ["19-15", "19-16", "19-23", "19-24"]: assert move in black_moves
def test_that_move_removes_piece_if_white_takes_black(self): game = Game() game.reset() game.move("25-22") game.move("5-9") game.move("22-18") game.move("9-14") # White takes black in this move game.move("18-9") assert game.turn == "white" assert game._pieces_remaining["black"] == 7
def test_that_move_removes_piece_if_black_takes_white(self): game = Game() game.reset() game.move("25-22") game.move("5-9") game.move("22-18") game.move("9-14") game.move("29-25") # Black takes white in this move game.move("14-23") assert game.turn == "black" assert game._pieces_remaining["white"] == 7
def test_result_is_draw_if_forty_moves_without_take(self): game = Game() game.reset() assert not game.game_over() game.reset() game._moves_since_take = 39 assert not game.game_over() game.reset() game._moves_since_take = 40 assert game.game_over() game.reset() game._moves_since_take = 92 assert game.game_over()