tests: produce on planets, unload on routes

This commit is contained in:
Ilia Denisov
2026-01-23 00:28:23 +02:00
parent 9825e05c0e
commit 812e0d4afd
15 changed files with 522 additions and 103 deletions
+22 -25
View File
@@ -56,7 +56,7 @@ func PlanetProduction(industry, population float64) float64 {
// [x] ind = (res * prod) / (5 * res + 1)
// ind = 10 * 1000 / (5 * 10 + 1) = 10000 / 55 = 181.(81)
// int = 10 * 500 / 55 = 5000 / 55
func (p *Planet) IncreaseIndustry() {
func (p *Planet) ProduceIndustry() {
production := p.ProductionCapacity()
var ind float64
if p.Material > 0 {
@@ -72,27 +72,13 @@ func (p *Planet) IncreaseIndustry() {
}
}
func (p *Planet) UnpackCAPtoIND() {
if p.Capital == 0 {
return
}
cap := p.Population - p.Industry
if cap > p.Capital {
cap = p.Capital
}
p.Capital -= cap
p.Industry += cap
}
// Производство материалов
// TODO: test on real values
func (p *Planet) IncreaseMaterial() {
func (p *Planet) ProduceMaterial() {
p.Material += p.ProductionCapacity() * p.Resources
}
// Автоматическое увеличение населения на каждом ходу
// TODO: test - whether POP is busy on production or not?
func (p *Planet) IncreasePopulation() {
func (p *Planet) ProducePopulation() {
p.Population *= 1.08
if p.Population > p.Size {
p.Colonists += (p.Population - p.Size) / 8.
@@ -100,17 +86,28 @@ func (p *Planet) IncreasePopulation() {
}
}
func (p *Planet) UnpackCOLtoPOP() {
if p.Colonists < 1 {
func (p *Planet) UnpackCapital() {
if p.Capital == 0 {
return
}
maxCOL := uint((p.Size - p.Population) / 8.)
if float64(maxCOL) > p.Colonists {
maxCOL = uint(p.Colonists)
deficit := p.Population - p.Industry
if deficit > p.Capital {
deficit = p.Capital
}
maxCOL = uint(float64(maxCOL) - math.Mod(float64(maxCOL), 8.))
p.Colonists -= float64(maxCOL)
p.Population += float64(maxCOL) * 8
p.Capital -= deficit
p.Industry += deficit
}
func (p *Planet) UnpackColonists() {
if p.Colonists == 0 {
return
}
deficit := (p.Size - p.Population) / 8
if deficit > p.Colonists {
deficit = p.Colonists
}
p.Colonists -= deficit
p.Population += deficit * 8
}
func UnloadColonists(p Planet, v float64) Planet {
+123 -5
View File
@@ -14,7 +14,7 @@ func TestPlanetProduction(t *testing.T) {
assert.Equal(t, 250., game.PlanetProduction(0., 1000.))
}
func TestIncreaseIndustry(t *testing.T) {
func TestProduceIndustry(t *testing.T) {
HW := &game.Planet{
PlanetReport: game.PlanetReport{
UninhabitedPlanet: game.UninhabitedPlanet{
@@ -35,23 +35,141 @@ func TestIncreaseIndustry(t *testing.T) {
Industry: 500,
},
}
HW.IncreaseIndustry()
HW.ProduceIndustry()
assert.InDelta(t, 196.078, HW.Capital, 0.0005)
HW.Capital = 0
HW.Material = 200
HW.IncreaseIndustry()
HW.ProduceIndustry()
assert.Equal(t, 200., HW.Capital)
assert.Equal(t, 0., HW.Material)
DW.IncreaseIndustry()
DW.ProduceIndustry()
assert.InDelta(t, 98.039, DW.Capital, 0.0003)
DW.Capital = 0
DW.Material = 100
DW.IncreaseIndustry()
DW.ProduceIndustry()
assert.Equal(t, 100., DW.Capital)
assert.Equal(t, 0., DW.Material)
}
func TestProduceMaterial(t *testing.T) {
HW := &game.Planet{
PlanetReport: game.PlanetReport{
UninhabitedPlanet: game.UninhabitedPlanet{
Size: 1000,
Resources: 10,
},
Population: 1000,
Industry: 1000,
},
}
assert.Equal(t, 0., HW.Material)
HW.ProduceMaterial()
assert.Equal(t, 10000., HW.Material)
HW.Industry = 500
HW.Population = 500
HW.ProduceMaterial()
assert.Equal(t, 15000., HW.Material)
HW.Population = 1000
HW.ProduceMaterial()
assert.Equal(t, 21250., HW.Material)
}
func TestUnpackCapital(t *testing.T) {
HW := &game.Planet{
PlanetReport: game.PlanetReport{
UninhabitedPlanet: game.UninhabitedPlanet{
Size: 1000,
Resources: 10,
},
Population: 1000,
Industry: 1000,
},
}
assert.Equal(t, 0., HW.Capital)
HW.UnpackCapital()
assert.Equal(t, 1000., HW.Industry)
assert.Equal(t, 0., HW.Capital)
HW.Capital = 123.
HW.UnpackCapital()
assert.Equal(t, 1000., HW.Industry)
assert.Equal(t, 123., HW.Capital)
HW.Industry = 987.
HW.UnpackCapital()
assert.Equal(t, 1000., HW.Industry)
assert.Equal(t, 110., HW.Capital)
HW.Population = 876.
HW.Industry = 800.
HW.UnpackCapital()
assert.Equal(t, 876., HW.Population)
assert.Equal(t, 876., HW.Industry)
assert.Equal(t, 34., HW.Capital)
}
func TestUnpackColonists(t *testing.T) {
HW := &game.Planet{
PlanetReport: game.PlanetReport{
UninhabitedPlanet: game.UninhabitedPlanet{
Size: 1000,
Resources: 10,
},
Population: 1000,
Industry: 1000,
},
}
assert.Equal(t, 0., HW.Colonists)
HW.UnpackColonists()
assert.Equal(t, 1000., HW.Population)
assert.Equal(t, 0., HW.Colonists)
HW.Colonists = 1.05
HW.UnpackColonists()
assert.Equal(t, 1000., HW.Population)
assert.Equal(t, 1.05, HW.Colonists)
HW.Population = 996.0
HW.UnpackColonists()
assert.Equal(t, 1000., HW.Population)
assert.Equal(t, 0.55, HW.Colonists)
HW.Population = 0.0
HW.UnpackColonists()
assert.Equal(t, 4.4, HW.Population)
assert.Equal(t, 0., HW.Colonists)
}
func TestProducePopulation(t *testing.T) {
HW := &game.Planet{
PlanetReport: game.PlanetReport{
UninhabitedPlanet: game.UninhabitedPlanet{
Size: 1000,
Resources: 10,
},
Population: 500,
Industry: 1000,
},
}
assert.Equal(t, 500., HW.Population)
assert.Equal(t, 0., HW.Colonists)
HW.ProducePopulation()
assert.Equal(t, 540., HW.Population)
assert.Equal(t, 0., HW.Colonists)
HW.Population = 1000.
HW.ProducePopulation()
assert.Equal(t, 1000., HW.Population)
assert.Equal(t, 10., HW.Colonists)
}
+5
View File
@@ -16,6 +16,11 @@ var (
RouteColonist.String(): RouteColonist,
RouteEmpty.String(): RouteEmpty,
}
RouteToCargo map[RouteType]CargoType = map[RouteType]CargoType{
RouteColonist: CargoColonist,
RouteCapital: CargoCapital,
RouteMaterial: CargoMaterial,
}
)
func (rt RouteType) Ref() *RouteType {