Skip to content

Commit

Permalink
Merge branch 'pgn' of github.com:VincentAuriau/pyalapin into pgn
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentAuriau committed Nov 1, 2023
2 parents bc029e3 + 03c964b commit 96629a6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion pyalapin/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,9 @@ class Game:

game_status = []

def __init__(self, player1=None, player2=None, automatic_draw=True, ai=False, save_pgn=False):
def __init__(
self, player1=None, player2=None, automatic_draw=True, ai=False, save_pgn=False
):
"""Initialization of the cell.
Parameters
Expand Down
14 changes: 11 additions & 3 deletions pyalapin/engine/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,20 @@ def to_pgn(self):
if self.killed_piece is not None:
start = "x"
elif self.is_castling:
if (self.moved_piece.is_white() and self.end.y == 1) or (not self.moved_piece.is_white() and self.end.y == 6):
if (self.moved_piece.is_white() and self.end.y == 1) or (
not self.moved_piece.is_white() and self.end.y == 6
):
piece = "O-O-O"
start = ""
end = ""
king = self.board.white_king if not self.player.white_side else self.board.black_king
if self.board.get_cell(king.x, king.y).is_threatened(board=self.board, threaten_color=not self.player.white_side):
king = (
self.board.white_king
if not self.player.white_side
else self.board.black_king
)
if self.board.get_cell(king.x, king.y).is_threatened(
board=self.board, threaten_color=not self.player.white_side
):
end += "+"

print(piece, start, end)
Expand Down
3 changes: 1 addition & 2 deletions tests/unit_test/engine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,5 @@ def test_pgn():
game.move_from_coordinates(game.player2, 6, 5, 4, 5)
game.move_from_coordinates(game.player1, 0, 3, 4, 7)
game.move_from_coordinates(game.player2, 6, 6, 5, 6)

assert game.to_pgn() == "1.e4 f5 2.Qh5+ g6"

assert game.to_pgn() == "1.e4 f5 2.Qh5+ g6"

0 comments on commit 96629a6

Please sign in to comment.