fix: to_tensor() normalization

This commit is contained in:
Henri Bourcereau 2026-03-07 20:10:49 +01:00
parent 85ccca4741
commit a6644e3c9d

View file

@ -225,22 +225,26 @@ impl GameState {
let mut t = Vec::with_capacity(217);
let pos: Vec<i8> = self.board.to_vec(); // 24 elements, positive=White, negative=Black
// [0..95] own (White) checkers, TD-Gammon encoding
// [0..95] own (White) checkers, TD-Gammon encoding.
// Each field contributes 4 values:
// (count==1), (count==2), (count==3), (count-3)/12 ← all in [0,1]
// The overflow term is divided by 12 because the maximum excess is
// 15 (all checkers) 3 = 12.
for &c in &pos {
let own = c.max(0) as u8;
t.push((own == 1) as u8 as f32);
t.push((own == 2) as u8 as f32);
t.push((own == 3) as u8 as f32);
t.push(own.saturating_sub(3) as f32);
t.push(own.saturating_sub(3) as f32 / 12.0);
}
// [96..191] opp (Black) checkers, TD-Gammon encoding
// [96..191] opp (Black) checkers, same encoding.
for &c in &pos {
let opp = (-c).max(0) as u8;
t.push((opp == 1) as u8 as f32);
t.push((opp == 2) as u8 as f32);
t.push((opp == 3) as u8 as f32);
t.push(opp.saturating_sub(3) as f32);
t.push(opp.saturating_sub(3) as f32 / 12.0);
}
// [192..193] dice