test dw distances
This commit is contained in:
+6
-16
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user