feat(gamecli): implement pure Reward.Compute with unit tests

This commit is contained in:
meelstorm
2026-07-17 16:45:53 +00:00
committed by EugeneTes
parent 34fb901fe6
commit 3bca85bcc4
2 changed files with 85 additions and 0 deletions

29
GameCli/Reward.cs Normal file
View File

@@ -0,0 +1,29 @@
namespace GameCli;
/// <summary>
/// Reward = -distance_to_target
/// - λ_v · speed
/// - λ_θ · |angle|
/// - λ_fuel · engine_on
/// Coefficients are public so training scripts can log/inspect them.
/// </summary>
public static class Reward
{
public const float LambdaVelocity = 0.10f;
public const float LambdaAngle = 0.10f;
public const float LambdaFuel = 0.03f;
public static float Compute(ShipState s, (float X, float Y) target, int action)
{
float dx = target.X - s.X;
float dy = target.Y - s.Y;
float distance = MathF.Sqrt(dx * dx + dy * dy);
float speed = MathF.Sqrt(s.VX * s.VX + s.VY * s.VY);
float engineOn = action == Physics.ActionNoop ? 0f : 1f;
return -distance
- LambdaVelocity * speed
- LambdaAngle * MathF.Abs(s.Angle)
- LambdaFuel * engineOn;
}
}