test dw distances

This commit is contained in:
Ilia Denisov
2025-09-23 23:33:47 +03:00
parent 7d93176031
commit ab822a1abf
7 changed files with 75 additions and 35 deletions
+6 -16
View File
@@ -1,6 +1,10 @@
package game
import "math"
import (
"math"
"github.com/iliadenisov/galaxy/pkg/number"
)
type Ship struct {
TypeName string
@@ -103,7 +107,7 @@ func (sg ShipGroup) BombingPower() float64 {
sg.Weapons *
float64(sg.Type.Armament) *
float64(sg.Number)
return toFixed3(result)
return number.Fixed3(result)
}
// TODO: test this
@@ -116,17 +120,3 @@ func (fl Fleet) Speed() float64 {
}
return result
}
func toFixed3(num float64) float64 {
return toFixed(num, 3)
}
// TODO: move to more common place
func toFixed(num float64, precision int) float64 {
output := math.Pow(10, float64(precision))
return float64(round(num*output)) / output
}
func round(num float64) int {
return int(num + math.Copysign(0.5, num))
}