@@ -54,7 +54,7 @@ def get_legal_moves_from_square(fen, square):
5454 legal_moves .append (to_square )
5555 return legal_moves
5656
57- def render_board (fen , selected_square = None , legal_moves = None , theme = 'classic' , flip_board = False ):
57+ def render_board (fen , selected_square = None , legal_moves = None , theme = 'classic' , flip_board = False , premove = None ):
5858 board = chess .Board (fen )
5959 squares_to_highlight = {}
6060 if selected_square :
@@ -66,15 +66,29 @@ def render_board(fen, selected_square=None, legal_moves=None, theme='classic', f
6666 sq = chess .parse_square (move_square )
6767 squares_to_highlight [sq ] = "#f5a9a9"
6868
69- light_color , dark_color = {
70- 'blue' : ('#DBEAF9' , '#70A3D9' ),
71- 'green' : ('#E0F0D9' , '#4C8B5F' ),
72- }.get (theme , ('#F3D9B2' , '#B78959' ))
69+ if premove :
70+ try :
71+ premove_from = chess .parse_square (premove [0 ])
72+ premove_to = chess .parse_square (premove [1 ])
73+ # Use a red tint color (adjust as desired)
74+ squares_to_highlight [premove_from ] = "#ffcccc"
75+ squares_to_highlight [premove_to ] = "#ffcccc"
76+ except Exception as e :
77+ print ("Error parsing premove squares:" , e )
78+
79+ # Choose colors based on theme
80+ if theme == 'blue' :
81+ light_color , dark_color = '#DBEAF9' , '#70A3D9'
82+ elif theme == 'green' :
83+ light_color , dark_color = '#E0F0D9' , '#4C8B5F'
84+ else :
85+ light_color , dark_color = '#F3D9B2' , '#B78959'
7386
7487 svg_data = chess .svg .board (
7588 board ,
89+ size = 400 ,
7690 squares = squares_to_highlight ,
77- orientation = chess .BLACK if flip_board else chess .WHITE , # ← KEY LINE
91+ orientation = chess .BLACK if flip_board else chess .WHITE ,
7892 colors = {
7993 'square light' : light_color ,
8094 'square dark' : dark_color
0 commit comments