コード例 #1
0
def test_illegal_capture_raises_exception():
    game = Draughts({
        '00': Counter(Color.WHITE),
    })
    game.playing_color = Color.WHITE

    with pytest.raises(IllegalMoveError, match=game.ILLEGAL_CAPTURE):
        game.move(Coords(x=0, y=0), Coords(x=2, y=2))
コード例 #2
0
def test_draughts_piece_can_move():
    game = Draughts()
    game.playing_color = Color.WHITE
    assert game.board[5][3] is None

    game.move(Coords(x=4, y=2), Coords(x=5, y=3))
    assert game.board[4][2] is None
    assert game.board[5][3] == Counter(Color.WHITE)
コード例 #3
0
def test_draughts_piece_can_capture():
    game = Draughts({
        '00': Counter(Color.WHITE),
        '11': Counter(Color.BLACK),
    })
    game.playing_color = Color.WHITE

    game.move(Coords(x=0, y=0), Coords(x=2, y=2))
    assert game.board[1][1] is None
    assert game.board[2][2] == Counter(Color.WHITE)
コード例 #4
0
def test_crowned_white_piece_can_capture_backwards():
    game = Draughts({
        '22': Counter(Color.WHITE),
        '11': Counter(Color.BLACK),
    })
    game.playing_color = Color.WHITE
    game.board[2][2].crowned = True

    game.move(Coords(x=2, y=2), Coords(x=0, y=0))
    assert game.board[1][1] is None
    assert game.board[0][0] == Counter(Color.WHITE)
コード例 #5
0
def test_can_capture_two_pieces_in_multiple_direction():
    game = Draughts({
        '00': Counter(Color.WHITE),
        '11': Counter(Color.BLACK),
        '13': Counter(Color.BLACK),
    })
    game.playing_color = Color.WHITE

    game.move(Coords(x=0, y=0), Coords(x=0, y=4))
    assert game.board[1][1] is None
    assert game.board[1][3] is None
    assert game.board[0][4] == Counter(Color.WHITE)
コード例 #6
0
def test_can_capture_two_pieces_in_straight_line():
    game = Draughts({
        '00': Counter(Color.WHITE),
        '11': Counter(Color.BLACK),
        '33': Counter(Color.BLACK),
    })
    game.playing_color = Color.WHITE

    game.move(Coords(x=0, y=0), Coords(x=4, y=4))
    assert game.board[1][1] is None
    assert game.board[3][3] is None
    assert game.board[4][4] == Counter(Color.WHITE)
コード例 #7
0
def test_white_can_capture_three_pieces_in_multiple_directions_s_shape():
    game = Draughts({
        '60': Counter(Color.WHITE),
        '51': Counter(Color.BLACK),
        '53': Counter(Color.BLACK),
        '55': Counter(Color.BLACK),
    })
    game.playing_color = Color.WHITE

    game.move(Coords(x=6, y=0), Coords(x=4, y=6))
    assert game.board[5][1] is None
    assert game.board[5][3] is None
    assert game.board[5][5] is None
    assert game.board[4][6] == Counter(Color.WHITE)
コード例 #8
0
def test_illegal_move_raises_exception():
    game = Draughts()
    game.playing_color = Color.WHITE

    with pytest.raises(IllegalMoveError, match=game.ILLEGAL_MOVE):
        game.move(Coords(x=4, y=2), Coords(x=4, y=3))