@ -1,65 +1,12 @@ |
|||||
package constants |
package constants |
||||
|
|
||||
import ( |
|
||||
"github.com/arnaucube/gogame/models" |
|
||||
) |
|
||||
|
|
||||
// game constants
|
// game constants
|
||||
|
|
||||
const GALAXYSIZE = 50 |
const GALAXYSIZE = 50 |
||||
const SOLARSYSTEMSIZE = 15 |
const SOLARSYSTEMSIZE = 15 |
||||
|
|
||||
// MetalMineLevels contains the constants of productivity for each level, sorted from 0 to X levels
|
|
||||
var MetalMineLevels = []int64{ |
|
||||
0, |
|
||||
1, |
|
||||
5, |
|
||||
10, |
|
||||
// TODO this will be same strategy with all the buildings and research
|
|
||||
} |
|
||||
var CrystalMineLevels = []int64{ |
|
||||
0, |
|
||||
1, |
|
||||
5, |
|
||||
10, |
|
||||
} |
|
||||
var DeuteriumMineLevels = []int64{ |
|
||||
0, |
|
||||
1, |
|
||||
5, |
|
||||
10, |
|
||||
} |
|
||||
var EnergyMineLevels = []int64{ |
|
||||
0, |
|
||||
1, |
|
||||
5, |
|
||||
10, |
|
||||
} |
|
||||
|
|
||||
// BuildingsNeededResources hold
|
|
||||
// map with all the buildings, that each one is a map with the levels of the buildings with the needed ressources
|
|
||||
var BuildingsNeededResources = map[string]map[int64]models.Resources{ |
|
||||
"metalplant": map[int64]models.Resources{ |
|
||||
1: models.Resources{ |
|
||||
Metal: 50, |
|
||||
Crystal: 50, |
|
||||
Deuterium: 50, |
|
||||
Energy: 50, |
|
||||
}, |
|
||||
2: models.Resources{ |
|
||||
Metal: 70, |
|
||||
Crystal: 70, |
|
||||
Deuterium: 70, |
|
||||
Energy: 70, |
|
||||
}, |
|
||||
3: models.Resources{ |
|
||||
Metal: 90, |
|
||||
Crystal: 90, |
|
||||
Deuterium: 90, |
|
||||
Energy: 90, |
|
||||
}, |
|
||||
}, |
|
||||
} |
|
||||
|
const UniverseAcceleration = 1 |
||||
|
const MineVelocity = 1 |
||||
|
|
||||
// extra
|
// extra
|
||||
const JWTIdKey = "id" |
const JWTIdKey = "id" |
@ -0,0 +1,150 @@ |
|||||
|
package models |
||||
|
|
||||
|
import ( |
||||
|
"math" |
||||
|
|
||||
|
"github.com/arnaucube/gogame/constants" |
||||
|
) |
||||
|
|
||||
|
// formulas
|
||||
|
// https://ogame.fandom.com/wiki/Formulas
|
||||
|
// https://ogame.fandom.com/wiki/Research
|
||||
|
|
||||
|
// idelta is time in seconds units
|
||||
|
func MetalGrowth(ilvl int64, idelta int64) int64 { |
||||
|
lvl := float64(ilvl) |
||||
|
delta := float64(idelta) |
||||
|
|
||||
|
// 30 * L * 1.1^L
|
||||
|
perHour := constants.UniverseAcceleration * 30 * lvl * math.Pow(1.1, lvl) |
||||
|
r := (perHour / 60) * delta * constants.MineVelocity |
||||
|
return int64(r) |
||||
|
} |
||||
|
func CrystalGrowth(ilvl int64, idelta int64) int64 { |
||||
|
lvl := float64(ilvl) |
||||
|
delta := float64(idelta) |
||||
|
|
||||
|
// 20 * L * 1.1^L
|
||||
|
perHour := constants.UniverseAcceleration * 20 * lvl * math.Pow(1.1, lvl) |
||||
|
r := (perHour / 60) * delta * constants.MineVelocity |
||||
|
return int64(r) |
||||
|
} |
||||
|
func DeuteriumGrowth(ilvl int64, idelta int64) int64 { |
||||
|
lvl := float64(ilvl) |
||||
|
delta := float64(idelta) |
||||
|
|
||||
|
t := float64(240) // t: max temperature
|
||||
|
// 10 * L * 1.1^L * (−0.002 * T + 1.28))
|
||||
|
perHour := constants.UniverseAcceleration * 10 * lvl * math.Pow(1.1, lvl) * ((-0.002)*t + 1.28) |
||||
|
r := (perHour / 60) * delta * constants.MineVelocity |
||||
|
return int64(r) |
||||
|
} |
||||
|
func SolarGrowth(ilvl int64, idelta int64) int64 { |
||||
|
lvl := float64(ilvl) |
||||
|
delta := float64(idelta) |
||||
|
|
||||
|
// 20 * L * 1.1^L
|
||||
|
perHour := constants.UniverseAcceleration * 20 * lvl * math.Pow(1.1, lvl) |
||||
|
r := (perHour / 60) * delta * constants.MineVelocity |
||||
|
return int64(r) |
||||
|
} |
||||
|
func FusionGrowth(ilvl int64, ilvlTech int64, idelta int64) int64 { |
||||
|
lvl := float64(ilvl) |
||||
|
lvlTech := float64(ilvlTech) |
||||
|
delta := float64(idelta) |
||||
|
|
||||
|
// 30 * L * (1.05 + lvlTech * 0.01)^lvl
|
||||
|
perHour := constants.UniverseAcceleration * 30 * math.Pow((1.05+lvlTech*0.01), lvl) |
||||
|
r := (perHour / 60) * delta * constants.MineVelocity |
||||
|
return int64(r) |
||||
|
} |
||||
|
|
||||
|
// https://ogame.fandom.com/wiki/Buildings
|
||||
|
|
||||
|
// https://ogame.fandom.com/wiki/Metal_Mine
|
||||
|
func MetalMineCost(ilvl int64) Resources { |
||||
|
lvl := float64(ilvl) |
||||
|
base := Resources{ |
||||
|
Metal: 60, |
||||
|
Crystal: 15, |
||||
|
Deuterium: 0, |
||||
|
Energy: 0, |
||||
|
} |
||||
|
// cost = base * 1.5^(lvl-1)
|
||||
|
cost := Resources{} |
||||
|
cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1)) |
||||
|
cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1)) |
||||
|
cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1)) |
||||
|
cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1)) |
||||
|
return cost |
||||
|
} |
||||
|
|
||||
|
// https://ogame.fandom.com/wiki/Crystal_Mine
|
||||
|
func CrystalMineCost(ilvl int64) Resources { |
||||
|
lvl := float64(ilvl) |
||||
|
base := Resources{ |
||||
|
Metal: 48, |
||||
|
Crystal: 24, |
||||
|
Deuterium: 0, |
||||
|
Energy: 0, |
||||
|
} |
||||
|
// cost = base * 1.6^(lvl-1)
|
||||
|
cost := Resources{} |
||||
|
cost.Metal = int64(float64(base.Metal) * math.Pow(1.6, lvl-1)) |
||||
|
cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.6, lvl-1)) |
||||
|
cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.6, lvl-1)) |
||||
|
cost.Energy = int64(float64(base.Energy) * math.Pow(1.6, lvl-1)) |
||||
|
return cost |
||||
|
} |
||||
|
|
||||
|
// https://ogame.fandom.com/wiki/Deuterium_Synthesizer
|
||||
|
func DeuteriumMineCost(ilvl int64) Resources { |
||||
|
lvl := float64(ilvl) |
||||
|
base := Resources{ |
||||
|
Metal: 225, |
||||
|
Crystal: 75, |
||||
|
Deuterium: 0, |
||||
|
Energy: 0, |
||||
|
} |
||||
|
// cost = base * 1.5^(lvl-1)
|
||||
|
cost := Resources{} |
||||
|
cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1)) |
||||
|
cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1)) |
||||
|
cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1)) |
||||
|
cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1)) |
||||
|
return cost |
||||
|
} |
||||
|
|
||||
|
func EnergyMineCost(ilvl int64) Resources { |
||||
|
lvl := float64(ilvl) |
||||
|
base := Resources{ |
||||
|
Metal: 75, |
||||
|
Crystal: 30, |
||||
|
Deuterium: 0, |
||||
|
Energy: 0, |
||||
|
} |
||||
|
// cost = base * 1.5^(lvl-1)
|
||||
|
cost := Resources{} |
||||
|
cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1)) |
||||
|
cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1)) |
||||
|
cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1)) |
||||
|
cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1)) |
||||
|
return cost |
||||
|
} |
||||
|
|
||||
|
func RessearchLabCost(ilvl int64) Resources { |
||||
|
lvl := float64(ilvl) |
||||
|
base := Resources{ |
||||
|
Metal: 200, |
||||
|
Crystal: 400, |
||||
|
Deuterium: 200, |
||||
|
Energy: 0, |
||||
|
} |
||||
|
// cost = base * 1.5^(lvl-1)
|
||||
|
cost := Resources{} |
||||
|
cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1)) |
||||
|
cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1)) |
||||
|
cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1)) |
||||
|
cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1)) |
||||
|
return cost |
||||
|
} |
@ -0,0 +1,62 @@ |
|||||
|
package models |
||||
|
|
||||
|
import ( |
||||
|
"testing" |
||||
|
|
||||
|
"github.com/arnaucube/gogame/constants" |
||||
|
"github.com/stretchr/testify/assert" |
||||
|
) |
||||
|
|
||||
|
func TestGrowth(t *testing.T) { |
||||
|
// metal
|
||||
|
assert.Equal(t, int64(33), MetalGrowth(1, 60)/constants.MineVelocity) |
||||
|
assert.Equal(t, int64(66), MetalGrowth(1, 120)/constants.MineVelocity) |
||||
|
assert.Equal(t, int64(72), MetalGrowth(2, 60)/constants.MineVelocity) |
||||
|
|
||||
|
// crystal
|
||||
|
assert.Equal(t, int64(22), CrystalGrowth(1, 60)/constants.MineVelocity) |
||||
|
assert.Equal(t, int64(44), CrystalGrowth(1, 120)/constants.MineVelocity) |
||||
|
assert.Equal(t, int64(48), CrystalGrowth(2, 60)/constants.MineVelocity) |
||||
|
|
||||
|
// deuterium
|
||||
|
assert.Equal(t, int64(8), DeuteriumGrowth(1, 60)/constants.MineVelocity) |
||||
|
assert.Equal(t, int64(17), DeuteriumGrowth(1, 120)/constants.MineVelocity) |
||||
|
assert.Equal(t, int64(19), DeuteriumGrowth(2, 60)/constants.MineVelocity) |
||||
|
|
||||
|
// solar
|
||||
|
assert.Equal(t, int64(22), SolarGrowth(1, 60)/constants.MineVelocity) |
||||
|
assert.Equal(t, int64(44), SolarGrowth(1, 120)/constants.MineVelocity) |
||||
|
assert.Equal(t, int64(48), SolarGrowth(2, 60)/constants.MineVelocity) |
||||
|
|
||||
|
// fusion
|
||||
|
assert.Equal(t, int64(31), FusionGrowth(1, 1, 60)/constants.MineVelocity) |
||||
|
assert.Equal(t, int64(63), FusionGrowth(1, 1, 120)/constants.MineVelocity) |
||||
|
assert.Equal(t, int64(34), FusionGrowth(2, 2, 60)/constants.MineVelocity) |
||||
|
} |
||||
|
|
||||
|
func TestMineCost(t *testing.T) { |
||||
|
// metalmine
|
||||
|
assert.Equal(t, Resources{Metal: 60, Crystal: 15}, MetalMineCost(1)) |
||||
|
assert.Equal(t, Resources{Metal: 90, Crystal: 22}, MetalMineCost(2)) |
||||
|
assert.Equal(t, Resources{Metal: 17515, Crystal: 4378}, MetalMineCost(15)) |
||||
|
|
||||
|
// crystalmine
|
||||
|
assert.Equal(t, Resources{Metal: 48, Crystal: 24}, CrystalMineCost(1)) |
||||
|
assert.Equal(t, Resources{Metal: 76, Crystal: 38}, CrystalMineCost(2)) |
||||
|
assert.Equal(t, Resources{Metal: 34587, Crystal: 17293}, CrystalMineCost(15)) |
||||
|
|
||||
|
// deuteriummine
|
||||
|
assert.Equal(t, Resources{Metal: 225, Crystal: 75}, DeuteriumMineCost(1)) |
||||
|
assert.Equal(t, Resources{Metal: 337, Crystal: 112}, DeuteriumMineCost(2)) |
||||
|
assert.Equal(t, Resources{Metal: 65684, Crystal: 21894}, DeuteriumMineCost(15)) |
||||
|
|
||||
|
// energymine
|
||||
|
assert.Equal(t, Resources{Metal: 75, Crystal: 30}, EnergyMineCost(1)) |
||||
|
assert.Equal(t, Resources{Metal: 112, Crystal: 45}, EnergyMineCost(2)) |
||||
|
assert.Equal(t, Resources{Metal: 21894, Crystal: 8757}, EnergyMineCost(15)) |
||||
|
|
||||
|
// researchlab
|
||||
|
assert.Equal(t, Resources{Metal: 200, Crystal: 400, Deuterium: 200}, RessearchLabCost(1)) |
||||
|
assert.Equal(t, Resources{Metal: 400, Crystal: 800, Deuterium: 400}, RessearchLabCost(2)) |
||||
|
assert.Equal(t, Resources{Metal: 3276800, Crystal: 6553600, Deuterium: 3276800}, RessearchLabCost(15)) |
||||
|
} |