예제 #1
0
def load_board(board_dict):
    board = Board()
    for index, square_data in board_dict.items():
        board.owner[int(index)] = load_player(square_data['player'])
        board.piece_class[int(index)] = load_piece_class(square_data['class'])

    return board
예제 #2
0
def test_capture_ending_in_home_row_promotes():
    board = Board()
    board.add_piece(15, Player.WHITE, PieceClass.MAN)
    board.add_piece(10, Player.BLACK, PieceClass.MAN)
    move = CaptureMove(15, 4)
    new_board = move.apply(board)
    assert new_board.owner[4] == Player.WHITE
    assert new_board.piece_class[4] == PieceClass.KING
예제 #3
0
def multiple_equal_combo_captures_board():
    board = Board()
    board.add_piece(17, Player.BLACK, PieceClass.KING)
    board.add_piece(28, Player.WHITE, PieceClass.MAN)
    board.add_piece(29, Player.WHITE, PieceClass.MAN)
    board.add_piece(38, Player.WHITE, PieceClass.MAN)
    return board
예제 #4
0
def multiple_capture_options_men_board():
    board = Board()
    board.add_piece(23, Player.BLACK, PieceClass.MAN)
    board.add_piece(28, Player.WHITE, PieceClass.MAN)
    board.add_piece(37, Player.WHITE, PieceClass.MAN)
    board.add_piece(29, Player.WHITE, PieceClass.MAN)
    board.add_piece(40, Player.WHITE, PieceClass.MAN)
    board.add_piece(19, Player.WHITE, PieceClass.MAN)
    return board
예제 #5
0
def completely_filled_board():
    board = Board()
    for index in range(26, 51):
        board.add_piece(index, Player.WHITE, PieceClass.MAN)
    for index in range(1, 26):
        board.add_piece(index, Player.BLACK, PieceClass.MAN)
    return board
예제 #6
0
def test_man_when_finishing_move_in_home_row_gets_promoted():
    board_before = Board()
    board_before.add_piece(6, Player.WHITE, PieceClass.MAN)
    move = ForwardMove(6, 1)
    board_after = move.apply(board_before)
    assert board_after.owner[1] == Player.WHITE
    assert board_after.piece_class[1] == PieceClass.KING

    board_before = Board()
    board_before.add_piece(41, Player.BLACK, PieceClass.MAN)
    move = ForwardMove(41, 47)
    board_after = move.apply(board_before)
    assert board_after.owner[47] == Player.BLACK
    assert board_after.piece_class[47] == PieceClass.KING
예제 #7
0
def starting_board():
    board = Board()
    for index in range(31, 51):
        board.add_piece(index, Player.WHITE, PieceClass.MAN)
    for index in range(1, 21):
        board.add_piece(index, Player.BLACK, PieceClass.MAN)
    return board
예제 #8
0
def two_vs_two_protected_kings_board():
    board = Board()
    board.add_piece(29, Player.WHITE, PieceClass.KING)
    board.add_piece(33, Player.WHITE, PieceClass.KING)
    board.add_piece(24, Player.BLACK, PieceClass.KING)
    board.add_piece(20, Player.BLACK, PieceClass.KING)
    return board
예제 #9
0
def test_man_when_finishing_capture_in_home_row_gets_promoted():
    board_before = Board()
    board_before.add_piece(12, Player.WHITE, PieceClass.MAN)
    board_before.add_piece(7, Player.BLACK, PieceClass.MAN)
    move = CaptureMove(12, 1)
    board_after = move.apply(board_before)

    assert board_after.owner[1] == Player.WHITE
    assert board_after.piece_class[1] == PieceClass.KING
    assert board_after.owner[7] is None
    assert board_after.piece_class[7] is None

    board_before = Board()
    board_before.add_piece(42, Player.WHITE, PieceClass.MAN)
    board_before.add_piece(37, Player.BLACK, PieceClass.MAN)
    move = CaptureMove(37, 48)
    board_after = move.apply(board_before)

    assert board_after.owner[48] == Player.BLACK
    assert board_after.piece_class[48] == PieceClass.KING
    assert board_after.owner[42] is None
    assert board_after.piece_class[42] is None
예제 #10
0
def get_starting_board():
    """
    Get an instance of the checkers game board representing the initial
    layout of the game pieces.
    """

    board = Board()
    for index in range(31, 51):
        board.add_piece(index, Player.WHITE, PieceClass.MAN)
    for index in range(1, 21):
        board.add_piece(index, Player.BLACK, PieceClass.MAN)
    return board
예제 #11
0
def insane_king_combo_board():
    # From Wikipedia GIF: https://en.wikipedia.org/wiki/International_draughts
    board = Board()
    board.add_piece(1, Player.WHITE, PieceClass.KING)
    board.add_piece(40, Player.WHITE, PieceClass.MAN)
    board.add_piece(48, Player.WHITE, PieceClass.MAN)
    board.add_piece(7, Player.BLACK, PieceClass.MAN)
    board.add_piece(13, Player.BLACK, PieceClass.MAN)
    board.add_piece(20, Player.BLACK, PieceClass.MAN)
    board.add_piece(35, Player.BLACK, PieceClass.MAN)
    board.add_piece(39, Player.BLACK, PieceClass.MAN)
    board.add_piece(41, Player.BLACK, PieceClass.MAN)
    board.add_piece(42, Player.BLACK, PieceClass.MAN)
    return board
예제 #12
0
def multiple_capture_options_complex_board():
    board = Board()
    board.add_piece(23, Player.BLACK, PieceClass.KING)
    board.add_piece(28, Player.BLACK, PieceClass.MAN)
    board.add_piece(18, Player.WHITE, PieceClass.MAN)
    board.add_piece(7, Player.WHITE, PieceClass.MAN)
    board.add_piece(19, Player.WHITE, PieceClass.MAN)
    board.add_piece(14, Player.WHITE, PieceClass.MAN)
    board.add_piece(37, Player.WHITE, PieceClass.MAN)
    board.add_piece(29, Player.WHITE, PieceClass.MAN)
    return board
예제 #13
0
def test_game_over_one_king_each_draw():
    board = Board()
    board.add_piece(13, Player.WHITE, PieceClass.KING)
    board.add_piece(32, Player.BLACK, PieceClass.KING)
    assert board.check_game_over(Player.WHITE) == GameOverReason.DRAW
    assert board.check_game_over(Player.BLACK) == GameOverReason.DRAW
예제 #14
0
def test_game_over_one_king_each_adjacent_not_draw():
    board = Board()
    board.add_piece(28, Player.WHITE, PieceClass.KING)
    board.add_piece(32, Player.BLACK, PieceClass.KING)
    assert board.check_game_over(Player.WHITE) is None
    assert board.check_game_over(Player.BLACK) is None
예제 #15
0
def test_game_over_still_playable():
    board = Board()
    board.add_piece(13, Player.BLACK, PieceClass.MAN)
    board.add_piece(32, Player.WHITE, PieceClass.MAN)
    assert board.check_game_over(Player.WHITE) is None
    assert board.check_game_over(Player.BLACK) is None
예제 #16
0
def test_game_over_no_black_pieces():
    board = Board()
    board.add_piece(32, Player.WHITE, PieceClass.MAN)
    assert board.check_game_over(Player.BLACK) == GameOverReason.WHITE_WON
예제 #17
0
def test_man_when_jumping_across_the_edge_does_not_get_promoted():
    board_before = Board()
    board_before.add_piece(11, Player.WHITE, PieceClass.MAN)
    board_before.add_piece(7, Player.BLACK, PieceClass.MAN)
    board_before.add_piece(8, Player.BLACK, PieceClass.MAN)
    move = ComboCaptureMove([CaptureMove(11, 2), CaptureMove(2, 13)])
    board_after = move.apply(board_before)

    assert board_after.owner[13] == Player.WHITE
    assert board_after.piece_class[13] == PieceClass.MAN
    assert board_after.owner[7] is None
    assert board_after.piece_class[7] is None
    assert board_after.owner[8] is None
    assert board_after.piece_class[8] is None

    board_before = Board()
    board_before.add_piece(41, Player.WHITE, PieceClass.MAN)
    board_before.add_piece(42, Player.WHITE, PieceClass.MAN)
    board_before.add_piece(36, Player.BLACK, PieceClass.MAN)
    move = ComboCaptureMove([CaptureMove(36, 47), CaptureMove(47, 38)])
    board_after = move.apply(board_before)

    assert board_after.owner[38] == Player.BLACK
    assert board_after.piece_class[38] == PieceClass.MAN
    assert board_after.owner[41] is None
    assert board_after.piece_class[41] is None
    assert board_after.owner[42] is None
    assert board_after.piece_class[42] is None
예제 #18
0
def test_get_available_moves_no_pieces():
    board = Board()
    assert board.get_available_moves(Player.WHITE) == []
    assert board.get_available_moves(Player.BLACK) == []
예제 #19
0
def one_vs_one_kings_capture_board():
    board = Board()
    board.add_piece(28, Player.WHITE, PieceClass.KING)
    board.add_piece(23, Player.BLACK, PieceClass.KING)
    return board
예제 #20
0
def one_vs_one_men_backwards_capture_board():
    board = Board()
    board.add_piece(23, Player.WHITE, PieceClass.MAN)
    board.add_piece(28, Player.BLACK, PieceClass.MAN)
    return board
예제 #21
0
def one_vs_one_men_surrender_board():
    board = Board()
    board.add_piece(28, Player.WHITE, PieceClass.MAN)
    board.add_piece(18, Player.BLACK, PieceClass.MAN)
    return board
예제 #22
0
def one_vs_one_men_cornered_board():
    board = Board()
    board.add_piece(50, Player.WHITE, PieceClass.MAN)
    board.add_piece(45, Player.BLACK, PieceClass.MAN)
    return board
예제 #23
0
def two_vs_one_kings_board():
    board = Board()
    board.add_piece(31, Player.WHITE, PieceClass.KING)
    board.add_piece(34, Player.WHITE, PieceClass.KING)
    board.add_piece(18, Player.BLACK, PieceClass.KING)
    return board
예제 #24
0
def one_vs_one_kings_cornered_board():
    board = Board()
    board.add_piece(46, Player.WHITE, PieceClass.KING)
    board.add_piece(5, Player.BLACK, PieceClass.KING)
    return board
예제 #25
0
def combo_via_home_row_board():
    board = Board()
    board.add_piece(15, Player.WHITE, PieceClass.MAN)
    board.add_piece(10, Player.BLACK, PieceClass.MAN)
    board.add_piece(22, Player.BLACK, PieceClass.MAN)
    return board