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
+13
View File
@@ -2,6 +2,7 @@ package generator
import (
"fmt"
"math"
"math/rand"
"github.com/iliadenisov/galaxy/pkg/generator/plotter"
@@ -67,6 +68,18 @@ func (m Map) NewCoordinate(deadZoneRaduis float64) (Coordinate, error) {
}
}
func (m Map) ShortDistance(from, to Coordinate) float64 {
dx := math.Abs(to.X - from.X)
dy := math.Abs(to.Y - from.Y)
if dx > float64(m.Width/2) {
dx = float64(m.Width) - dx
}
if dy > float64(m.Height/2) {
dy = float64(m.Height) - dy
}
return math.Sqrt(math.Pow(dx, 2) + math.Pow(dy, 2))
}
func NewPlanet(c Coordinate, size, resources float64) Planet {
return Planet{
Position: c,