Skip to content

Commit ec50de5

Browse files
committed
Adding flipped option to unicode representation
1 parent 835c520 commit ec50de5

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

chess/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,14 +1221,19 @@ def __str__(self) -> str:
12211221

12221222
return "".join(builder)
12231223

1224-
def unicode(self, *, invert_color: bool = False, borders: bool = False, empty_square: str = "⭘") -> str:
1224+
def unicode(self, *, invert_color: bool = False, borders: bool = False, empty_square: str = "⭘", flipped:bool = False) -> str:
12251225
"""
12261226
Returns a string representation of the board with Unicode pieces.
12271227
Useful for pretty-printing to a terminal.
12281228
12291229
:param invert_color: Invert color of the Unicode pieces.
12301230
:param borders: Show borders and a coordinate margin.
12311231
"""
1232+
board = self.copy()
1233+
if flipped:
1234+
board.apply_transform(flip_vertical)
1235+
board.apply_transform(flip_horizontal)
1236+
12321237
builder = []
12331238
for rank_index in range(7, -1, -1):
12341239
if borders:
@@ -1247,7 +1252,7 @@ def unicode(self, *, invert_color: bool = False, borders: bool = False, empty_sq
12471252
elif file_index > 0:
12481253
builder.append(" ")
12491254

1250-
piece = self.piece_at(square_index)
1255+
piece = board.piece_at(square_index)
12511256

12521257
if piece:
12531258
builder.append(piece.unicode_symbol(invert_color=invert_color))

0 commit comments

Comments
 (0)