Falguni commited on
Commit
c0f1a1d
·
1 Parent(s): 51778ef

Update rendering

Browse files
Files changed (1) hide show
  1. src/thinksqure_engine.py +16 -15
src/thinksqure_engine.py CHANGED
@@ -275,13 +275,15 @@ class ThinkSquareEngine:
275
 
276
  board = chess.Board(fen)
277
 
278
- display_board = board.copy()
279
- if board.turn == chess.BLACK:
280
- display_board = display_board.mirror()
281
 
282
- ascii_representation = str(display_board)
283
 
284
- return ascii_representation
 
 
 
 
285
 
286
  @staticmethod
287
  def render_board_svg(fen: Optional[str] = None):
@@ -289,12 +291,12 @@ class ThinkSquareEngine:
289
  fen = chess.STARTING_FEN
290
 
291
  board = chess.Board(fen)
292
-
293
- display_board = board.copy()
294
- if board.turn == chess.BLACK:
295
- display_board = display_board.mirror()
296
 
297
- svg = chess.svg.board(board=display_board, size=400, coordinates=True)
 
 
 
 
298
 
299
  return svg
300
 
@@ -304,11 +306,10 @@ class ThinkSquareEngine:
304
  fen = chess.STARTING_FEN
305
 
306
  board = chess.Board(fen)
 
307
 
308
- display_board = board.copy()
309
- if board.turn == chess.BLACK:
310
- display_board = display_board.mirror()
311
-
312
- unicode_representation = display_board.unicode(invert_color=False)
313
 
314
  return unicode_representation
 
275
 
276
  board = chess.Board(fen)
277
 
278
+ orientation = chess.WHITE if board.turn == chess.WHITE else chess.BLACK
 
 
279
 
280
+ ascii_board = str(board).split("\n")
281
 
282
+ if orientation == chess.BLACK:
283
+ # Flip both vertically and horizontally
284
+ ascii_board = [row[::-1] for row in ascii_board[::-1]]
285
+
286
+ return "\n".join(ascii_board)
287
 
288
  @staticmethod
289
  def render_board_svg(fen: Optional[str] = None):
 
291
  fen = chess.STARTING_FEN
292
 
293
  board = chess.Board(fen)
 
 
 
 
294
 
295
+ orientation = chess.WHITE if board.turn == chess.WHITE else chess.BLACK
296
+
297
+ svg = chess.svg.board(
298
+ board=board, orientation=orientation, size=400, coordinates=True
299
+ )
300
 
301
  return svg
302
 
 
306
  fen = chess.STARTING_FEN
307
 
308
  board = chess.Board(fen)
309
+ orientation = chess.WHITE if board.turn == chess.WHITE else chess.BLACK
310
 
311
+ unicode_representation = board.unicode(
312
+ invert_color=False, borders=True, empty_square=".", orientation=orientation
313
+ )
 
 
314
 
315
  return unicode_representation