test: battle multiple non-crossing enemies
This commit is contained in:
@@ -13,8 +13,8 @@ import (
|
||||
type Battle struct {
|
||||
ID uuid.UUID
|
||||
Planet uint
|
||||
observerGroups map[int]bool // True = In_Battle, False = Out_Battle
|
||||
initialNumbers map[int]uint // Initial number of ships in the group
|
||||
ObserverGroups map[int]bool // True = In_Battle, False = Out_Battle
|
||||
InitialNumbers map[int]uint // Initial number of ships in the group
|
||||
Protocol []BattleAction
|
||||
|
||||
shipAmmo map[int]uint
|
||||
@@ -95,21 +95,21 @@ func ProduceBattles(c *Cache) []*Battle {
|
||||
|
||||
result := make([]*Battle, 0)
|
||||
|
||||
// TODO: check this behavior:
|
||||
// Multiple battles on single planet shoul be produced as single battle too:
|
||||
// Multiple battles on single planet shoul be produced as single battle:
|
||||
// A <--> B
|
||||
// C <--> D
|
||||
// where: A in peace with [C, D], B in peace with [C, D], and so on.
|
||||
// where: [A] and [B] are mutual enemies, as well [C] and [D]
|
||||
for pl, observerGroups := range planetGroups {
|
||||
battleGroups := FilterBattleGroups(c, observerGroups)
|
||||
b := &Battle{
|
||||
Planet: pl,
|
||||
observerGroups: observerGroups,
|
||||
ObserverGroups: observerGroups,
|
||||
InitialNumbers: make(map[int]uint),
|
||||
attacker: make(map[int]map[int]float64),
|
||||
shipAmmo: make(map[int]uint),
|
||||
}
|
||||
for sgi := range observerGroups {
|
||||
b.initialNumbers[sgi] = c.ShipGroup(sgi).Number
|
||||
b.InitialNumbers[sgi] = c.ShipGroup(sgi).Number
|
||||
}
|
||||
|
||||
for i := range battleGroups {
|
||||
@@ -125,10 +125,13 @@ func ProduceBattles(c *Cache) []*Battle {
|
||||
})
|
||||
if len(opponents) > 0 {
|
||||
b.shipAmmo[attIdx] = c.ShipGroupShipClass(attIdx).Armament
|
||||
b.observerGroups[attIdx] = true
|
||||
b.ObserverGroups[attIdx] = true
|
||||
for _, defIdx := range opponents {
|
||||
if _, ok := b.attacker[attIdx][defIdx]; !ok {
|
||||
b.attacker[attIdx] = make(map[int]float64)
|
||||
}
|
||||
b.attacker[attIdx][defIdx] = cacheProbability[attIdx][defIdx]
|
||||
b.observerGroups[defIdx] = true
|
||||
b.ObserverGroups[defIdx] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,13 +181,13 @@ func SingleBattle(c *Cache, b *Battle) {
|
||||
if c.ShipGroup(defIdx).Number == 0 {
|
||||
delete(b.attacker, defIdx) // Eliminated group cant attack anyone
|
||||
for attIdx := range b.attacker {
|
||||
delete(b.attacker[attIdx], defIdx) // Attackers can't attack eliminated group anymore
|
||||
delete(b.attacker[attIdx], defIdx) // Other attackers can't attack eliminated group anymore
|
||||
if len(b.attacker[attIdx]) == 0 {
|
||||
delete(b.attacker, attIdx) // Remove attacker if he lost all opponents
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(b.attacker) == 0 {
|
||||
if len(b.attacker[attIdx]) == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user