Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds support for displaying NAGs in the chess.svg.board AND other optimizations chess.svg.board function #1062

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
dc31630
feat: adds visualization of NAGs on the SVG board.
Vikasg7 Jan 21, 2024
a75d028
fix: refactored to remove unneccessary if statements without changing…
Vikasg7 Jan 21, 2024
9c1d7f6
fix: separated rendering of X marked Squares from Piece rendering
Vikasg7 Jan 22, 2024
4a32115
fixed the order in which ascii board appeared in the svg
Vikasg7 Jan 23, 2024
eb13080
fix: added a check where a valid nag was passed but there is no Glyph…
Vikasg7 Jan 23, 2024
b872884
fix: Updated the ?! Glyph background color for it to be more visible
Vikasg7 Jan 23, 2024
368eb5b
adds basic tests for the squares and NAGs
Vikasg7 Jan 23, 2024
43367fb
fixed the background color of inaccuracy glypha again to match mistak…
Vikasg7 Jan 23, 2024
7e330b5
fix: bringing global constants in local scope for lil perf boost
Vikasg7 Jan 24, 2024
1f9977a
chores: updates docs to show which nags are supported by nag param in…
Vikasg7 Feb 7, 2024
549529c
Merge branch 'niklasf:master' into master
Vikasg7 Apr 5, 2024
33341e2
Removes border crap and adds coordinates inside the squares
Vikasg7 May 12, 2024
d8b7160
Fixed the z-order of coords so that they don't overlap glyphs or othe…
Vikasg7 May 12, 2024
8d808ce
Fixed type errors
Vikasg7 May 12, 2024
88171b7
Fixed the bug where glyphs weren't placed correctly in flipped board
Vikasg7 May 12, 2024
f86269d
Decouple the rendering of lastmove rects from rendering of board for …
Vikasg7 May 25, 2024
5eba38f
feat: adds parser and svg print support for Novelty nag
Vikasg7 Nov 26, 2024
5809ef1
fix: taken care all the linter warnings
Vikasg7 Nov 26, 2024
98a1a38
fix: Updated Novelty nag's color and reduced the size of letter N
Vikasg7 Nov 27, 2024
bf7f632
fixes placement of the nag, made it more dynamic and also respects th…
Vikasg7 Nov 27, 2024
c70fe85
Reduces size of arrow
Vikasg7 Nov 28, 2024
473d657
bumped size of nags and fix their colors
Vikasg7 Nov 28, 2024
97eac2c
fixed nag color of inaccuracy and mistake
Vikasg7 Dec 16, 2024
1aff931
fix: updated the inaccuracy nag color to be same as mistake
Vikasg7 Jan 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ data/syzygy/giveaway/*.[gs]tb[wz]
fuzz/corpus

release-v*.txt
.venv
13 changes: 7 additions & 6 deletions chess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ def transform(self: BaseBoardT, f: Callable[[Bitboard], Bitboard]) -> BaseBoardT
board.apply_transform(f)
return board

def apply_mirror(self: BaseBoardT) -> None:
def apply_mirror(self: BaseBoard) -> None:
self.apply_transform(flip_vertical)
self.occupied_co[WHITE], self.occupied_co[BLACK] = self.occupied_co[BLACK], self.occupied_co[WHITE]

Expand Down Expand Up @@ -1561,14 +1561,14 @@ class Board(BaseBoard):
manipulation.
"""

def __init__(self: BoardT, fen: Optional[str] = STARTING_FEN, *, chess960: bool = False) -> None:
def __init__(self: Board, fen: Optional[str] = STARTING_FEN, *, chess960: bool = False) -> None:
BaseBoard.__init__(self, None)

self.chess960 = chess960

self.ep_square = None
self.move_stack = []
self._stack: List[_BoardState[BoardT]] = []
self._stack: List[_BoardState[Board]] = []

if fen is None:
self.clear()
Expand Down Expand Up @@ -2177,7 +2177,7 @@ def _board_state(self: BoardT) -> _BoardState[BoardT]:
def _push_capture(self, move: Move, capture_square: Square, piece_type: PieceType, was_promoted: bool) -> None:
pass

def push(self: BoardT, move: Move) -> None:
def push(self: Board, move: Move) -> None:
"""
Updates the position with the given *move* and puts it onto the
move stack.
Expand Down Expand Up @@ -2262,6 +2262,7 @@ def push(self: BoardT, move: Move) -> None:
elif diff == -16 and square_rank(move.from_square) == 6:
self.ep_square = move.from_square - 8
elif move.to_square == ep_square and abs(diff) in [7, 9] and not captured_piece_type:
assert ep_square is not None
# Remove pawns captured en passant.
down = -8 if self.turn == WHITE else 8
capture_square = ep_square + down
Expand Down Expand Up @@ -2298,7 +2299,7 @@ def push(self: BoardT, move: Move) -> None:
# Swap turn.
self.turn = not self.turn

def pop(self: BoardT) -> Move:
def pop(self: Board) -> Move:
"""
Restores the previous position and returns the last move from the stack.

Expand Down Expand Up @@ -3696,7 +3697,7 @@ def transform(self: BoardT, f: Callable[[Bitboard], Bitboard]) -> BoardT:
board.apply_transform(f)
return board

def apply_mirror(self: BoardT) -> None:
def apply_mirror(self: Board) -> None:
super().apply_mirror()
self.turn = not self.turn

Expand Down
12 changes: 8 additions & 4 deletions chess/pgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@
|(\()
|(\))
|(\*|1-0|0-1|1/2-1/2)
|(\!N)
|([\?!]{1,2})
|(TN)
""", re.DOTALL | re.VERBOSE)

SKIP_MOVETEXT_REGEX = re.compile(r""";|\{|\}""")
Expand Down Expand Up @@ -922,7 +924,7 @@ def without_tag_roster(cls: Type[GameT]) -> GameT:
return cls(headers={})

@classmethod
def builder(cls: Type[GameT]) -> GameBuilder[GameT]:
def builder(cls: Type[GameT]) -> GameBuilder[Game]:
return GameBuilder(Game=cls)

def __repr__(self) -> str:
Expand Down Expand Up @@ -1026,7 +1028,7 @@ def __repr__(self) -> str:
", ".join("{}={!r}".format(key, value) for key, value in self.items()))

@classmethod
def builder(cls: Type[HeadersT]) -> HeadersBuilder[HeadersT]:
def builder(cls: Type[HeadersT]) -> HeadersBuilder[Headers]:
return HeadersBuilder(Headers=cls)


Expand Down Expand Up @@ -1180,7 +1182,7 @@ class GameBuilder(BaseVisitor[GameT]):
@typing.overload
def __init__(self: GameBuilder[Game]) -> None: ...
@typing.overload
def __init__(self: GameBuilder[GameT], *, Game: Type[GameT]) -> None: ...
def __init__(self: GameBuilder[Game], *, Game: Type[GameT]) -> None: ...
def __init__(self, *, Game: Any = Game) -> None:
self.Game = Game

Expand Down Expand Up @@ -1277,7 +1279,7 @@ class HeadersBuilder(BaseVisitor[HeadersT]):
@typing.overload
def __init__(self: HeadersBuilder[Headers]) -> None: ...
@typing.overload
def __init__(self: HeadersBuilder[HeadersT], *, Headers: Type[Headers]) -> None: ...
def __init__(self: HeadersBuilder[Headers], *, Headers: Type[Headers]) -> None: ...
def __init__(self, *, Headers: Any = Headers) -> None:
self.Headers = Headers

Expand Down Expand Up @@ -1736,6 +1738,8 @@ def read_game(handle: TextIO, *, Visitor: Any = GameBuilder) -> Any:
visitor.visit_nag(NAG_SPECULATIVE_MOVE)
elif token == "?!":
visitor.visit_nag(NAG_DUBIOUS_MOVE)
elif token == "TN" or token == "!N":
visitor.visit_nag(NAG_NOVELTY)
elif token in ["1-0", "0-1", "1/2-1/2", "*"] and len(board_stack) == 1:
visitor.visit_result(token)
else:
Expand Down
Loading