예제 #1
0
def prepare_pieces(pieces_notations, color):
    """Prepare pieces for color."""
    iters = []
    for piece_cls, notations in pieces_notations.items():
        pieces = list(
            map(lambda n: piece_cls(Position.get_pos(n), color), notations))
        iters.append(pieces)

    return chain.from_iterable(iters)
예제 #2
0
def test_castle_piece_between(color, file_letter, grid_castle):  # noqa: D103
    rank = 1 if color is Color.White else 8

    side = Side.Queenside if file_letter in "bcd" else Side.Kingside

    pawn = piece_types.Pawn(Position.get_pos(f"{file_letter}{rank}"),
                            color=color.White)
    grid_castle.add_piece(pawn)

    assert not grid_castle.castle(color, side)
예제 #3
0
def test_revert_move(grid):  # noqa: D103
    grids = []
    p1 = piece_types.Pawn(Position.get_pos("a2"))
    p2 = piece_types.Pawn(Position.get_pos("b2"))
    grid.add_piece(p1)
    grid.add_piece(p2)

    assert not grid.revert_move()

    grid.move(p1.position, p1.position + Position(2, 0))
    grids.append(deepcopy(grid))
    grid.move(p2.position, p2.position + Position(1, 0))
    grids.append(deepcopy(grid))
    grid.move(p1.position, p1.position + Position(1, 0))
    grids.append(deepcopy(grid))
    grid.move(p2.position, p2.position + Position(1, 0))

    assert grids[-1] != grid

    while grids:
        snapshot = grids.pop()
        assert grid.revert_move()
        assert grid == snapshot
예제 #4
0
def grid_castle():  # noqa: D103
    grid = Grid()
    setup = {
        Color.White: {
            "a1": piece_types.Rook,
            "h1": piece_types.Rook,
            "e1": piece_types.King
        },
        Color.Black: {
            "a8": piece_types.Rook,
            "h8": piece_types.Rook,
            "e8": piece_types.King
        }
    }
    for color, notations in setup.items():
        for notation, piece_cls in notations.items():
            piece = piece_cls(Position.get_pos(notation), color)
            grid.add_piece(piece)

    return grid
예제 #5
0
def test_invalid_get_pos(notation):  # noqa: D103
    with pytest.raises(InvalidNotationError):
        Position.get_pos(notation)
예제 #6
0
def test_get_pos(notation, coords):  # noqa: D103
    assert Position.get_pos(notation) == Position(*coords)