compile ok but diverge

This commit is contained in:
Henri Bourcereau 2025-08-12 21:56:52 +02:00
parent ec6ae26d38
commit cfc19e6064
6 changed files with 38 additions and 22 deletions

View file

@ -17,7 +17,7 @@ train() {
} }
plot() { plot() {
NAME=$(ls "$LOGS_DIR" | tail -n 1) NAME=$(ls -rt "$LOGS_DIR" | tail -n 1)
LOGS="$LOGS_DIR/$NAME" LOGS="$LOGS_DIR/$NAME"
cfgs=$(head -n $CFG_SIZE "$LOGS") cfgs=$(head -n $CFG_SIZE "$LOGS")
for cfg in $cfgs; do for cfg in $cfgs; do

View file

@ -17,7 +17,7 @@ train() {
} }
plot() { plot() {
NAME=$(ls "$LOGS_DIR" | tail -n 1) NAME=$(ls -rt "$LOGS_DIR" | tail -n 1)
LOGS="$LOGS_DIR/$NAME" LOGS="$LOGS_DIR/$NAME"
cfgs=$(head -n $CFG_SIZE "$LOGS") cfgs=$(head -n $CFG_SIZE "$LOGS")
for cfg in $cfgs; do for cfg in $cfgs; do

View file

@ -17,7 +17,7 @@ fn main() {
// defaults // defaults
num_episodes: 40, // 40 num_episodes: 40, // 40
min_steps: 500.0, // 1000 min of max steps by episode (mise à jour par la fonction) min_steps: 500.0, // 1000 min of max steps by episode (mise à jour par la fonction)
max_steps: 3000, // 1000 max steps by episode max_steps: 1000, // 1000 max steps by episode
dense_size: 256, // 128 neural network complexity (default 128) dense_size: 256, // 128 neural network complexity (default 128)
eps_start: 0.9, // 0.9 epsilon initial value (0.9 => more exploration) eps_start: 0.9, // 0.9 epsilon initial value (0.9 => more exploration)
eps_end: 0.05, // 0.05 eps_end: 0.05, // 0.05

View file

@ -71,7 +71,7 @@ impl TrictracAction {
encoded -= 256 encoded -= 256
} }
let checker1 = encoded / 16; let checker1 = encoded / 16;
let checker2 = 1 + encoded % 16; let checker2 = encoded % 16;
(dice_order, checker1, checker2) (dice_order, checker1, checker2)
} }
@ -251,7 +251,7 @@ mod tests {
}; };
let index = action.to_action_index(); let index = action.to_action_index();
assert_eq!(Some(action), TrictracAction::from_action_index(index)); assert_eq!(Some(action), TrictracAction::from_action_index(index));
assert_eq!(81, index); assert_eq!(54, index);
} }
#[test] #[test]
@ -261,6 +261,6 @@ mod tests {
checker1: 3, checker1: 3,
checker2: 4, checker2: 4,
}; };
assert_eq!(Some(action), TrictracAction::from_action_index(81)); assert_eq!(Some(action), TrictracAction::from_action_index(54));
} }
} }

View file

@ -128,6 +128,7 @@ impl BotStrategy for DqnBurnStrategy {
(dicevals.1, dicevals.0) (dicevals.1, dicevals.0)
}; };
assert_eq!(self.color, Color::White);
let from1 = self let from1 = self
.game .game
.board .board
@ -138,14 +139,16 @@ impl BotStrategy for DqnBurnStrategy {
// empty move // empty move
dice1 = 0; dice1 = 0;
} }
let mut to1 = if self.color == Color::White { let mut to1 = from1;
from1 + dice1 as usize if self.color == Color::White {
to1 += dice1 as usize;
if 24 < to1 {
// sortie
to1 = 0;
}
} else { } else {
from1 - dice1 as usize let fto1 = to1 as i16 - dice1 as i16;
}; to1 = if fto1 < 0 { 0 } else { fto1 as usize };
if 24 < to1 || to1 < 0 {
// sortie
to1 = 0;
} }
let checker_move1 = store::CheckerMove::new(from1, to1).unwrap_or_default(); let checker_move1 = store::CheckerMove::new(from1, to1).unwrap_or_default();
@ -159,17 +162,28 @@ impl BotStrategy for DqnBurnStrategy {
// empty move // empty move
dice2 = 0; dice2 = 0;
} }
let mut to2 = from2 + dice2 as usize; let mut to2 = from2;
if 24 < to2 { if self.color == Color::White {
// sortie to2 += dice2 as usize;
to2 = 0; if 24 < to2 {
// sortie
to2 = 0;
}
} else {
let fto2 = to2 as i16 - dice2 as i16;
to2 = if fto2 < 0 { 0 } else { fto2 as usize };
} }
// Gestion prise de coin par puissance // Gestion prise de coin par puissance
let opp_rest_field = 13; let opp_rest_field = if self.color == Color::White { 13 } else { 12 };
if to1 == opp_rest_field && to2 == opp_rest_field { if to1 == opp_rest_field && to2 == opp_rest_field {
to1 -= 1; if self.color == Color::White {
to2 -= 1; to1 -= 1;
to2 -= 1;
} else {
to1 += 1;
to2 += 1;
}
} }
let checker_move1 = CheckerMove::new(from1, to1).unwrap_or_default(); let checker_move1 = CheckerMove::new(from1, to1).unwrap_or_default();
@ -178,6 +192,7 @@ impl BotStrategy for DqnBurnStrategy {
let chosen_move = if self.color == Color::White { let chosen_move = if self.color == Color::White {
(checker_move1, checker_move2) (checker_move1, checker_move2)
} else { } else {
// XXX : really ?
(checker_move1.mirror(), checker_move2.mirror()) (checker_move1.mirror(), checker_move2.mirror())
}; };

View file

@ -28,9 +28,10 @@ trainsimple:
trainbot: trainbot:
#python ./store/python/trainModel.py #python ./store/python/trainModel.py
# cargo run --bin=train_dqn # ok # cargo run --bin=train_dqn # ok
./bot/scripts/trainValid.sh # ./bot/scripts/trainValid.sh
./bot/scripts/train.sh
plottrainbot: plottrainbot:
./bot/scripts/trainValid.sh plot ./bot/scripts/train.sh plot
debugtrainbot: debugtrainbot:
cargo build --bin=train_dqn_burn cargo build --bin=train_dqn_burn
RUST_BACKTRACE=1 LD_LIBRARY_PATH=./target/debug ./target/debug/train_dqn_burn RUST_BACKTRACE=1 LD_LIBRARY_PATH=./target/debug ./target/debug/train_dqn_burn