Fix tests after rover change
This commit is contained in:
parent
f0f5a6b2e0
commit
93b99b7989
4 changed files with 23 additions and 7 deletions
|
@ -42,8 +42,12 @@ func NewAtlas(size, chunkSize int) Atlas {
|
|||
|
||||
// Initialise all the chunks
|
||||
for i := range a.Chunks {
|
||||
tiles := make([]byte, chunkSize*chunkSize)
|
||||
for i := 0; i < len(tiles); i++ {
|
||||
tiles[i] = TileEmpty
|
||||
}
|
||||
a.Chunks[i] = Chunk{
|
||||
Tiles: make([]byte, chunkSize*chunkSize),
|
||||
Tiles: tiles,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ func (w *World) SpawnRover() (uuid.UUID, error) {
|
|||
if tile, err := w.Atlas.GetTile(rover.Attributes.Pos); err != nil {
|
||||
return uuid.Nil, err
|
||||
} else {
|
||||
if tile == atlas.TileEmpty {
|
||||
if !atlas.IsBlocking(tile) {
|
||||
break
|
||||
} else {
|
||||
// Try and spawn to the east of the blockage
|
||||
|
@ -278,7 +278,10 @@ func (w *World) RadarFromRover(id uuid.UUID) ([]byte, error) {
|
|||
// Add all rovers to the radar
|
||||
for _, r := range w.Rovers {
|
||||
// If the rover is in range
|
||||
if r.Attributes.Pos.Distance(roverPos) < float64(radarSpan) {
|
||||
dist := r.Attributes.Pos.Added(roverPos.Negated())
|
||||
dist = dist.Abs()
|
||||
|
||||
if dist.X <= r.Attributes.Range && dist.Y <= r.Attributes.Range {
|
||||
relative := r.Attributes.Pos.Added(radarMin.Negated())
|
||||
index := relative.X + relative.Y*radarSpan
|
||||
radar[index] = atlas.TileRover
|
||||
|
@ -400,7 +403,7 @@ func PrintTiles(tiles []byte) {
|
|||
num := int(math.Sqrt(float64(len(tiles))))
|
||||
for j := num - 1; j >= 0; j-- {
|
||||
for i := 0; i < num; i++ {
|
||||
fmt.Printf("%d", tiles[i+num*j])
|
||||
fmt.Printf("%c", tiles[i+num*j])
|
||||
}
|
||||
fmt.Print("\n")
|
||||
}
|
||||
|
|
|
@ -135,8 +135,8 @@ func TestWorld_RadarFromRover(t *testing.T) {
|
|||
PrintTiles(radar)
|
||||
|
||||
// Test all expected values
|
||||
//assert.Equal(t, atlas.TileRover, radar[1+fullRange])
|
||||
//assert.Equal(t, atlas.TileRover, radar[4+4*fullRange])
|
||||
assert.Equal(t, atlas.TileRover, radar[1+fullRange])
|
||||
assert.Equal(t, atlas.TileRover, radar[4+4*fullRange])
|
||||
for i := 0; i < 8; i++ {
|
||||
assert.Equal(t, atlas.TileLargeRock, radar[i])
|
||||
assert.Equal(t, atlas.TileLargeRock, radar[i+(7*9)])
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package vector
|
||||
|
||||
import "math"
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/mdiluz/rove/pkg/maths"
|
||||
)
|
||||
|
||||
// Vector desribes a 3D vector
|
||||
type Vector struct {
|
||||
|
@ -45,3 +49,8 @@ func (v Vector) Multiplied(val int) Vector {
|
|||
func (v Vector) Divided(val int) Vector {
|
||||
return Vector{v.X / val, v.Y / val}
|
||||
}
|
||||
|
||||
// Abs returns an absolute version of the vector
|
||||
func (v Vector) Abs() Vector {
|
||||
return Vector{maths.Abs(v.X), maths.Abs(v.Y)}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue