valentin urena commited on
Commit
8e138a8
·
verified ·
1 Parent(s): d16e146

Update chess_board.py

Browse files
Files changed (1) hide show
  1. chess_board.py +4 -1
chess_board.py CHANGED
@@ -15,6 +15,8 @@ class Game:
15
  self.board = chess.Board()
16
  self.sequence = []
17
  self.counter = 0
 
 
18
  self.model_id = 'kaggle://valentinbaltazar/gemma-chess/keras/gemma_2b_en_chess'
19
  self.sampler = keras_nlp.samplers.TopKSampler(k=50, temperature=0.7)
20
  self.model = keras_nlp.models.GemmaCausalLM.from_preset(self.model_id)
@@ -61,7 +63,7 @@ class Game:
61
  def display_board(self):
62
  # clear_output(wait=True)
63
  # display(SVG(chess.svg.board(board=self.board)))
64
- board_svg = chess.svg.board(board=self.board)
65
  # return svg2png(bytestring=board_svg)
66
  return board_svg
67
 
@@ -72,6 +74,7 @@ class Game:
72
  self.board.push(update)
73
  # self.display_board()
74
  self.sequence.append(move)
 
75
  return True
76
  except:
77
  print(f"Invalid move '{move}'. Use algebraic notation (e.g., 'e4', 'Nf3', 'Bxc4') or ask Gemma for help.")
 
15
  self.board = chess.Board()
16
  self.sequence = []
17
  self.counter = 0
18
+ self.arrow= None
19
+
20
  self.model_id = 'kaggle://valentinbaltazar/gemma-chess/keras/gemma_2b_en_chess'
21
  self.sampler = keras_nlp.samplers.TopKSampler(k=50, temperature=0.7)
22
  self.model = keras_nlp.models.GemmaCausalLM.from_preset(self.model_id)
 
63
  def display_board(self):
64
  # clear_output(wait=True)
65
  # display(SVG(chess.svg.board(board=self.board)))
66
+ board_svg = chess.svg.board(board=self.board, arrows=[self.arrow])
67
  # return svg2png(bytestring=board_svg)
68
  return board_svg
69
 
 
74
  self.board.push(update)
75
  # self.display_board()
76
  self.sequence.append(move)
77
+ self.arrow = chess.svg.Arrow(move.from_square, move.to_square, color="#0000cccc")
78
  return True
79
  except:
80
  print(f"Invalid move '{move}'. Use algebraic notation (e.g., 'e4', 'Nf3', 'Bxc4') or ask Gemma for help.")