diff --git a/SAC_LSTM_Bot/sac_train.sh b/SAC_LSTM_Bot/sac_train.sh index 83f7331..a3096ca 100755 --- a/SAC_LSTM_Bot/sac_train.sh +++ b/SAC_LSTM_Bot/sac_train.sh @@ -119,8 +119,16 @@ eval_checkpoint() { wr=$(( 100 * wins / rounds )) echo ">>> [eval] win rate: $wins/$rounds ($wr%) vs $opp" cat "$otmp" >> "$tmp"; rm -f "$otmp" - # Per-opponent history: append this cycle's win rate, keep last MA_WINDOW. - printf '%s\n' "$(cat "$(ma_hist_file "$opp")" 2>/dev/null)" "$wr" \ + # Per-opponent history: append this cycle's win rate, keep last MA_WINDOW + # values on one line. Read FIRST, separately: `$(cat f)` inside a command + # redirected `> f` executes against the already-truncated file (bash sets + # up the redirect before running the substitution) — every cycle wiped the + # history back to a single leading-space value (#60). $hist is UNQUOTED on + # purpose: word-splitting turns the stored line into one value per line so + # tail keeps the last MA_WINDOW values. + local hist + hist="$(cat "$(ma_hist_file "$opp")" 2>/dev/null)" + printf '%s\n' $hist "$wr" \ | tail -n "$MA_WINDOW" | tr '\n' ' ' > "$(ma_hist_file "$opp")" done mv "$tmp" "$EVAL_LOG_FILE"