Fully implement the bearing based movement

Instant, and without limit, for now
This commit is contained in:
Marc Di Luzio 2020-06-04 21:59:00 +01:00
parent 0fbad15c01
commit 6461b51c5c
7 changed files with 105 additions and 82 deletions

View file

@ -3,44 +3,31 @@ package game
import (
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)
func TestCommand_Spawn(t *testing.T) {
world := NewWorld()
a := uuid.New()
spawnCommand := world.CommandSpawn(a)
assert.NoError(t, world.Execute(spawnCommand), "Failed to execute spawn command")
rover, ok := world.Rovers[a]
assert.True(t, ok, "No new rover in world")
assert.Equal(t, a, rover.Id, "New rover has incorrect id")
}
func TestCommand_Move(t *testing.T) {
world := NewWorld()
a := uuid.New()
assert.NoError(t, world.SpawnRover(a), "Failed to spawn")
a := world.SpawnRover()
pos := Vector{
X: 1.0,
Y: 2.0,
}
err := world.SetPosition(a, pos)
attribs, err := world.RoverAttributes(a)
assert.NoError(t, err, "Failed to get rover attribs")
err = world.WarpRover(a, pos)
assert.NoError(t, err, "Failed to set position for rover")
// TODO: Test the bearing/duration movement
/*
// Try the move command
moveCommand := world.CommandMove(a, move)
assert.NoError(t, world.Execute(moveCommand), "Failed to execute move command")
bearing := 0.0
duration := 1.0
// Try the move command
moveCommand := world.CommandMove(a, bearing, duration)
assert.NoError(t, world.Execute(moveCommand), "Failed to execute move command")
newpos, err := world.GetPosition(a)
assert.NoError(t, err, "Failed to set position for rover")
pos.Add(move)
assert.Equal(t, pos, newpos, "Failed to correctly set position for rover")
*/
newpos, err := world.RoverPosition(a)
assert.NoError(t, err, "Failed to set position for rover")
pos.Add(Vector{0.0, float64(duration) * attribs.Speed}) // We should have moved duration*speed north
assert.Equal(t, pos, newpos, "Failed to correctly set position for rover")
}