fix: repetition feature lost in FEN round-trip (train/inference mismatch); greedy-health exp
Browse files- tinychess/selfplay.py +8 -0
tinychess/selfplay.py
CHANGED
|
@@ -98,6 +98,7 @@ class GameRecord:
|
|
| 98 |
plies: int = 0
|
| 99 |
termination: str = ""
|
| 100 |
player: list = field(default_factory=list) # which agent moved (0/1)
|
|
|
|
| 101 |
|
| 102 |
|
| 103 |
def _temperature(ply: int, cfg: SelfPlayConfig) -> float:
|
|
@@ -200,6 +201,13 @@ def play_games(model_a, model_b=None, cfg: SelfPlayConfig = SelfPlayConfig(),
|
|
| 200 |
rec.values.append(float(values[j]))
|
| 201 |
rec.turns.append(boards[gi].turn)
|
| 202 |
rec.n_legal.append(int(pb.n_legal[j]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
rec.steps_used.append(float(nsteps[j]))
|
| 204 |
rec.player.append(who)
|
| 205 |
boards[gi].push(mv)
|
|
|
|
| 98 |
plies: int = 0
|
| 99 |
termination: str = ""
|
| 100 |
player: list = field(default_factory=list) # which agent moved (0/1)
|
| 101 |
+
reps: list = field(default_factory=list) # repetition count at that position
|
| 102 |
|
| 103 |
|
| 104 |
def _temperature(ply: int, cfg: SelfPlayConfig) -> float:
|
|
|
|
| 201 |
rec.values.append(float(values[j]))
|
| 202 |
rec.turns.append(boards[gi].turn)
|
| 203 |
rec.n_legal.append(int(pb.n_legal[j]))
|
| 204 |
+
# the repetition feature depends on the MOVE STACK, which a
|
| 205 |
+
# bare FEN cannot carry. Record it so training sees the same
|
| 206 |
+
# value self-play saw (otherwise it is always 0 at train time).
|
| 207 |
+
try:
|
| 208 |
+
rec.reps.append(2 if boards[gi].is_repetition(2) else 0)
|
| 209 |
+
except Exception:
|
| 210 |
+
rec.reps.append(0)
|
| 211 |
rec.steps_used.append(float(nsteps[j]))
|
| 212 |
rec.player.append(who)
|
| 213 |
boards[gi].push(mv)
|