cazyundee commited on
Commit
79997ea
·
verified ·
1 Parent(s): c94f46f

fix: repetition feature lost in FEN round-trip (train/inference mismatch); greedy-health exp

Browse files
Files changed (1) hide show
  1. tinychess/batching.py +11 -7
tinychess/batching.py CHANGED
@@ -51,20 +51,24 @@ class PositionBatch:
51
 
52
  def encode_batch(boards: Sequence[chess.Board],
53
  last_moves: Sequence[chess.Move | None] | None = None,
54
- max_cand: int | None = None) -> PositionBatch:
 
55
  """Encode boards + their legal candidate sets into padded tensors."""
56
  n = len(boards)
57
  if last_moves is None:
58
  last_moves = [None] * n
59
 
60
  sq_l, ex_l, g_l, packed_l, real_l = [], [], [], [], []
61
- for b, lm in zip(boards, last_moves):
62
- rep = 0
63
- try:
64
- if b.is_repetition(2):
65
- rep = 2
66
- except Exception:
67
  rep = 0
 
 
 
 
 
68
  sq, ex, g, flipped = encode_position(b, lm, rep)
69
  cb = b.mirror() if flipped else b
70
  real, packed = [], []
 
51
 
52
  def encode_batch(boards: Sequence[chess.Board],
53
  last_moves: Sequence[chess.Move | None] | None = None,
54
+ max_cand: int | None = None,
55
+ reps: Sequence[int] | None = None) -> PositionBatch:
56
  """Encode boards + their legal candidate sets into padded tensors."""
57
  n = len(boards)
58
  if last_moves is None:
59
  last_moves = [None] * n
60
 
61
  sq_l, ex_l, g_l, packed_l, real_l = [], [], [], [], []
62
+ for bi, (b, lm) in enumerate(zip(boards, last_moves)):
63
+ if reps is not None:
64
+ rep = int(reps[bi]) # explicit: FEN-restored boards lack history
65
+ else:
 
 
66
  rep = 0
67
+ try:
68
+ if b.is_repetition(2):
69
+ rep = 2
70
+ except Exception:
71
+ rep = 0
72
  sq, ex, g, flipped = encode_position(b, lm, rep)
73
  cb = b.mirror() if flipped else b
74
  real, packed = [], []