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)
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
def queen(): # noqa: D103 grid = Grid() queen = pieces.Queen(Position(1, 1)) grid.add_piece(queen) return queen
def knight(): # noqa: D103 grid = Grid() knight = pieces.Knight(Position(1, 1)) grid.add_piece(knight) return knight
def rook(): # noqa: D103 grid = Grid() rook = Rook(Position(1, 1)) grid.add_piece(rook) return rook
def king(): # noqa: D103 grid = Grid() king = pieces.King(Position(1, 1)) grid.add_piece(king) return king
def pawn(): # noqa: D103 grid = Grid() pawn = pieces.Pawn(Position(1, 1)) grid.add_piece(pawn) return pawn
def bishop(): # noqa: D103 grid = Grid() bishop = pieces.Bishop(Position(1, 1)) grid.add_piece(bishop) return bishop
def piece(): # noqa: D103 grid = Grid() piece = Piece((4, 4)) grid.add_piece(piece) return piece