feat: order processing
feat: order commands result save/load
This commit is contained in:
@@ -277,17 +277,21 @@ func (c *Cache) listRoutedUnloadShipGroupIds(pn uint, routeType game.RouteType)
|
||||
}
|
||||
}
|
||||
|
||||
func MaxOrRandomLoadId(IDtoLoad map[int]float64) int {
|
||||
if len(IDtoLoad) < 2 {
|
||||
panic("IDtoLoad must contain at least 2 keys")
|
||||
func MaxOrRandomLoadId(loadByRace map[int]float64) int {
|
||||
if len(loadByRace) < 2 {
|
||||
panic("loadByRace must contain at least 2 keys")
|
||||
}
|
||||
IDs := slices.Collect(maps.Keys(IDtoLoad))
|
||||
slices.SortFunc(IDs, func(id1, id2 int) int { return cmp.Compare(IDtoLoad[id2], IDtoLoad[id1]) })
|
||||
IDs := slices.Collect(maps.Keys(loadByRace))
|
||||
slices.SortFunc(IDs, func(id1, id2 int) int {
|
||||
return cmp.Or(
|
||||
cmp.Compare(loadByRace[id2], loadByRace[id1]),
|
||||
)
|
||||
})
|
||||
|
||||
// no single winner with highest load
|
||||
if IDtoLoad[IDs[0]] == IDtoLoad[IDs[1]] {
|
||||
if loadByRace[IDs[0]] == loadByRace[IDs[1]] {
|
||||
// remove IDs which load less than maximum
|
||||
IDs = slices.DeleteFunc(IDs, func(v int) bool { return IDtoLoad[v] < IDtoLoad[IDs[0]] })
|
||||
IDs = slices.DeleteFunc(IDs, func(v int) bool { return loadByRace[v] < loadByRace[IDs[0]] })
|
||||
// IDs[0] will have random index
|
||||
rand.Shuffle(len(IDs), func(i, j int) { IDs[i], IDs[j] = IDs[j], IDs[i] })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user