test: unknown and extict races for commands
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user