test: unknown and extict races for commands

This commit is contained in:
Ilia Denisov
2026-02-08 14:57:38 +02:00
parent c36857e702
commit 175fb98c3a
17 changed files with 292 additions and 63 deletions
+11 -4
View File
@@ -1,6 +1,7 @@
package controller
import (
"cmp"
"fmt"
"iter"
"maps"
@@ -551,15 +552,21 @@ func (c *Cache) listShipGroups(ri int) iter.Seq[*game.ShipGroup] {
}
}
// TODO: order upgradable groups by cost descending, describe in Rules
func (c *Cache) shipGroupsInUpgrade(planetNumber uint) iter.Seq[*game.ShipGroup] {
return func(yield func(*game.ShipGroup) bool) {
result := make([]int, 0)
for sg := range c.g.ShipGroups {
// number checked for further sanity after battles
if c.g.ShipGroups[sg].Number > 0 && c.g.ShipGroups[sg].Destination == planetNumber && c.g.ShipGroups[sg].State() == game.StateUpgrade {
if !yield(&c.g.ShipGroups[sg]) {
break
}
result = append(result, sg)
}
}
slices.SortFunc(result, func(a, b int) int {
return cmp.Compare(c.g.ShipGroups[b].StateUpgrade.Cost(), c.g.ShipGroups[a].StateUpgrade.Cost())
})
for i := range result {
if !yield(&c.g.ShipGroups[result[i]]) {
return
}
}
}