feat: CSV加player列+#RESULT汇总 — 训练中直接看胜率进化

This commit is contained in:
2026-07-13 08:40:14 +08:00
parent 15b9ccb22b
commit 22acc3b2ca
3 changed files with 73 additions and 4 deletions

View File

@ -499,7 +499,7 @@ namespace PdkFriendServer.Logic
float s = GamePack.Info.Score[i];
rewards[i] = s > 0 ? 1f : s < 0 ? -1f : 0f;
}
TrainingCollector.FlushGame(_flushGameCounter++, rewards);
TrainingCollector.FlushGame(_flushGameCounter++, rewards, GamePack.Info.OverPos, BotTypes);
}
if (DeskGameDo != null)

View File

@ -39,19 +39,21 @@ namespace PdkFriendServer.Logic
/// 游戏结束,输出本轮训练数据到文件。
/// rewards: 每个玩家的奖励 (1=赢, 0=第二, -1=第三)
/// </summary>
public static void FlushGame(int gameId, float[] rewards)
public static void FlushGame(int gameId, float[] rewards, int winnerPos, string[] botTypes)
{
if (!Enabled || _records.Count == 0) return;
var path = $"training_data/game_{gameId:D5}.csv";
System.IO.Directory.CreateDirectory("training_data");
using var w = new System.IO.StreamWriter(path);
w.WriteLine("state,action,reward");
w.WriteLine("state,action,reward,player");
foreach (var r in _records)
{
float reward = r.Player >= 0 && r.Player < rewards.Length ? rewards[r.Player] : 0;
var stateStr = string.Join(",", r.State.Select(f => f.ToString("F6")));
w.WriteLine($"\"{stateStr}\",{r.Action},{reward:F3}");
w.WriteLine($"\"{stateStr}\",{r.Action},{reward:F3},{r.Player}");
}
// 游戏结果摘要 — 方便不中断训练即可评估模型进化
w.WriteLine($"#RESULT,winner={winnerPos},bots={string.Join(",", botTypes ?? new[]{"ISMCTS","ISMCTS","ISMCTS"})}");
_records.Clear();
}