Ejemplo n.º 1
0
def get_starting_grid():
    """Create grid with starting chess position."""
    grid = Grid()

    for color, pieces_notations in STARTING_NOTATIONS.items():
        pieces = prepare_pieces(pieces_notations, color)
        add_pieces(grid, pieces)

    return grid
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def queen():  # noqa: D103
    grid = Grid()
    queen = pieces.Queen(Position(1, 1))
    grid.add_piece(queen)
    return queen
Ejemplo n.º 4
0
def knight():  # noqa: D103
    grid = Grid()
    knight = pieces.Knight(Position(1, 1))
    grid.add_piece(knight)
    return knight
Ejemplo n.º 5
0
def rook():  # noqa: D103
    grid = Grid()
    rook = Rook(Position(1, 1))
    grid.add_piece(rook)
    return rook
Ejemplo n.º 6
0
def king():  # noqa: D103
    grid = Grid()
    king = pieces.King(Position(1, 1))
    grid.add_piece(king)
    return king
Ejemplo n.º 7
0
def pawn():  # noqa: D103
    grid = Grid()
    pawn = pieces.Pawn(Position(1, 1))
    grid.add_piece(pawn)
    return pawn
Ejemplo n.º 8
0
def bishop():  # noqa: D103
    grid = Grid()
    bishop = pieces.Bishop(Position(1, 1))
    grid.add_piece(bishop)
    return bishop
Ejemplo n.º 9
0
def piece():  # noqa: D103
    grid = Grid()
    piece = Piece((4, 4))
    grid.add_piece(piece)
    return piece
Ejemplo n.º 10
0
def test_move_in_check():  # noqa: D103
    grid = Grid()
    r, f = 1, 1
    king = piece_types.King(Position(r, f - 1))
    rook = piece_types.Rook(Position(r, f + 1), color=Color.Black)
    p1 = piece_types.Pawn(Position(r - 1, f))
    p2 = piece_types.Pawn(Position(r - 1, f + 2))

    for piece in (king, rook, p1, p2):
        grid.add_piece(piece)

    assert grid.own_king_in_check(king)

    assert not grid.move(p2.position, p2.position + Position(1, 0))

    assert grid.move(p1.position, p1.position + Position(1, 0))
    assert not grid.own_king_in_check(king)

    p1.position += Position(-1, 0)

    print(king, p2, rook)
    assert grid.own_king_in_check(king)
    assert grid.move(p2.position, rook.position)

    assert not grid.own_king_in_check(king)
Ejemplo n.º 11
0
def grid():  # noqa: D103
    return Grid()