Skip to content

Commit 5c05487

Browse files
committed
Applying suggestions
1 parent ec50de5 commit 5c05487

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

chess/__init__.py

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

12221222
return "".join(builder)
12231223

1224-
def unicode(self, *, invert_color: bool = False, borders: bool = False, empty_square: str = "⭘", flipped:bool = False) -> str:
1224+
def unicode(self, *, invert_color: bool = False, borders: bool = False, empty_square: str = "⭘", orientation:Color = WHITE) -> str:
12251225
"""
12261226
Returns a string representation of the board with Unicode pieces.
12271227
Useful for pretty-printing to a terminal.
@@ -1230,12 +1230,9 @@ def unicode(self, *, invert_color: bool = False, borders: bool = False, empty_sq
12301230
:param borders: Show borders and a coordinate margin.
12311231
"""
12321232
board = self.copy()
1233-
if flipped:
1234-
board.apply_transform(flip_vertical)
1235-
board.apply_transform(flip_horizontal)
1236-
12371233
builder = []
1238-
for rank_index in range(7, -1, -1):
1234+
indexes = range(7, -1, -1) if orientation else range(8)
1235+
for rank_index in indexes:
12391236
if borders:
12401237
builder.append(" ")
12411238
builder.append("-" * 17)
@@ -1262,14 +1259,15 @@ def unicode(self, *, invert_color: bool = False, borders: bool = False, empty_sq
12621259
if borders:
12631260
builder.append("|")
12641261

1265-
if borders or rank_index > 0:
1262+
if borders or (rank_index > 0 and orientation) or (rank_index < 7 and not orientation):
12661263
builder.append("\n")
12671264

12681265
if borders:
12691266
builder.append(" ")
12701267
builder.append("-" * 17)
12711268
builder.append("\n")
1272-
builder.append(" a b c d e f g h")
1269+
letters = "a b c d e f g h" if orientation else "h g f e d c b a"
1270+
builder.append(" " + letters)
12731271

12741272
return "".join(builder)
12751273

0 commit comments

Comments
 (0)