use float64
This commit is contained in:
+11
-11
@@ -16,13 +16,13 @@ type Map struct {
|
||||
}
|
||||
|
||||
type Coordinate struct {
|
||||
X, Y float32
|
||||
X, Y float64
|
||||
}
|
||||
|
||||
type Planet struct {
|
||||
Position Coordinate
|
||||
Size float32
|
||||
Resources float32 // Сырьё
|
||||
Size float64
|
||||
Resources float64 // Сырьё
|
||||
}
|
||||
|
||||
type PlanetarySystem struct {
|
||||
@@ -43,7 +43,7 @@ func NewMap(width, height, players uint32) (*Map, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *Map) CreatePlanets(num int, deadZoneRadius float32, size, resources func() float32) error {
|
||||
func (m *Map) CreatePlanets(num int, deadZoneRadius float64, size, resources func() float64) error {
|
||||
for range num {
|
||||
coord, err := m.NewCoordinate(deadZoneRadius)
|
||||
if err != nil {
|
||||
@@ -59,7 +59,7 @@ func (m *Map) AddPlanet(planet Planet) {
|
||||
m.FreePlanets = append(m.FreePlanets, planet)
|
||||
}
|
||||
|
||||
func (m Map) NewCoordinate(deadZoneRaduis float32) (Coordinate, error) {
|
||||
func (m Map) NewCoordinate(deadZoneRaduis float64) (Coordinate, error) {
|
||||
if x, y, err := m.plotter.RandomFreePoint(deadZoneRaduis); err != nil {
|
||||
return Coordinate{}, fmt.Errorf("NewCoordinate: RandomFreePoint: %s", err)
|
||||
} else {
|
||||
@@ -67,7 +67,7 @@ func (m Map) NewCoordinate(deadZoneRaduis float32) (Coordinate, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func NewPlanet(c Coordinate, size, resources float32) Planet {
|
||||
func NewPlanet(c Coordinate, size, resources float64) Planet {
|
||||
return Planet{
|
||||
Position: c,
|
||||
Size: size,
|
||||
@@ -75,14 +75,14 @@ func NewPlanet(c Coordinate, size, resources float32) Planet {
|
||||
}
|
||||
}
|
||||
|
||||
// RandI returns a random float32 value between min and max
|
||||
func RandI(min, max float32) float32 {
|
||||
return min + rand.Float32()*(max-min)
|
||||
// RandI returns a random float64 value between min and max
|
||||
func RandI(min, max float64) float64 {
|
||||
return min + rand.Float64()*(max-min)
|
||||
}
|
||||
|
||||
// RandIFn is a wrapper for the [RandI] func
|
||||
func RandIFn(min, max float32) func() float32 {
|
||||
return func() float32 {
|
||||
func RandIFn(min, max float64) func() float64 {
|
||||
return func() float64 {
|
||||
return RandI(min, max)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user