feat(ui): Phase 30 ship-class calculator with goal-seek and reach circles
Tests · UI / test (push) Successful in 2m14s
Tests · Go / test (push) Successful in 2m25s

Fuse the standalone ship-class designer (Phases 17/18) into a sidebar calculator: live mass/speed/attack/defence/bombing results, a planet build-rate readout, single-target goal-seek, a modernization-cost mode, and auto reach circles on the map for the selected planet.

pkg/calc becomes the single source for the new math (no mirroring): extract BombingPower from the engine model and the per-turn ship-production loop from controller.ProduceShip into pkg/calc (engine now delegates), and add inverse goal-seek solvers in pkg/calc/solve.go. Thin-bridge the combat, planet-build, and solver functions through ui/core/calc + ui/wasm and rebuild core.wasm.

Remove the standalone designer view/route; the ship-classes table and the view/bottom menus open the calculator via a shared request store.

Docs: rewrite ui/PLAN.md Phase 30, adjust Phase 34 (realistic forecast + CAP/COL ownership), add ui/docs/calculator-ux.md, extend calc-bridge.md, fix navigation.md; remove ui/CALCULATOR.md.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilia Denisov
2026-05-21 19:52:08 +02:00
parent 00159ddf7c
commit 9ae7b88b89
53 changed files with 3748 additions and 1298 deletions
+49
View File
@@ -61,3 +61,52 @@ func TestShipBuildCost(t *testing.T) {
})
}
}
func TestProduceShipsInTurn(t *testing.T) {
cases := []struct {
name string
productionAvailable, material, resources, shipMass float64
wantShips uint
wantMaterialLeft, wantProductionUsed, wantProgress float64
}{
{
name: "ample material: ten ships, no farming",
productionAvailable: 100, material: 100, resources: 10, shipMass: 1,
wantShips: 10, wantMaterialLeft: 90, wantProductionUsed: 0, wantProgress: 0,
},
{
name: "no material: partial progress on a farmed ship",
productionAvailable: 114, material: 0, resources: 0.5, shipMass: 10,
// ShipBuildCost(10,0,0.5) = 100 + 10/0.5 = 120; 114/120 = 0.95.
wantShips: 0, wantMaterialLeft: 0, wantProductionUsed: 114, wantProgress: 0.95,
},
{
name: "no production available leaves the stockpile",
productionAvailable: 0, material: 50, resources: 10, shipMass: 5,
wantShips: 0, wantMaterialLeft: 50, wantProductionUsed: 0, wantProgress: 0,
},
{
name: "zero ship mass is guarded against an endless loop",
productionAvailable: 100, material: 50, resources: 10, shipMass: 0,
wantShips: 0, wantMaterialLeft: 50, wantProductionUsed: 0, wantProgress: 0,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
ships, materialLeft, productionUsed, progress := calc.ProduceShipsInTurn(
tc.productionAvailable, tc.material, tc.resources, tc.shipMass)
if ships != tc.wantShips {
t.Errorf("ships = %d, want %d", ships, tc.wantShips)
}
if math.Abs(materialLeft-tc.wantMaterialLeft) > 1e-9 {
t.Errorf("materialLeft = %v, want %v", materialLeft, tc.wantMaterialLeft)
}
if math.Abs(productionUsed-tc.wantProductionUsed) > 1e-9 {
t.Errorf("productionUsed = %v, want %v", productionUsed, tc.wantProductionUsed)
}
if math.Abs(progress-tc.wantProgress) > 1e-9 {
t.Errorf("progress = %v, want %v", progress, tc.wantProgress)
}
})
}
}