De-scope, remove rover speed
This commit is contained in:
parent
a84709564c
commit
db3c2c2c2e
9 changed files with 51 additions and 86 deletions
|
@ -16,9 +16,6 @@ func TestCommand_Move(t *testing.T) {
|
|||
Y: 2.0,
|
||||
}
|
||||
|
||||
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")
|
||||
|
||||
|
@ -33,6 +30,6 @@ func TestCommand_Move(t *testing.T) {
|
|||
|
||||
newPos, err := world.RoverPosition(a)
|
||||
assert.NoError(t, err, "Failed to set position for rover")
|
||||
pos.Add(vector.Vector{X: 0.0, Y: int(duration) * int(attribs.Speed)}) // We should have moved duration*speed north
|
||||
pos.Add(vector.Vector{X: 0.0, Y: int(duration)})
|
||||
assert.Equal(t, pos, newPos, "Failed to correctly set position for rover")
|
||||
}
|
||||
|
|
|
@ -10,9 +10,6 @@ type RoverAttributes struct {
|
|||
// Name of this rover
|
||||
Name string `json:"name"`
|
||||
|
||||
// Speed represents the Speed that the rover will move per second
|
||||
Speed int `json:"speed"`
|
||||
|
||||
// Range represents the distance the unit's radar can see
|
||||
Range int `json:"range"`
|
||||
|
||||
|
|
|
@ -88,7 +88,6 @@ func (w *World) SpawnRover() (uuid.UUID, error) {
|
|||
rover := Rover{
|
||||
Id: uuid.New(),
|
||||
Attributes: RoverAttributes{
|
||||
Speed: 1.0,
|
||||
Range: 5.0,
|
||||
Capacity: 5,
|
||||
Name: "rover",
|
||||
|
@ -229,14 +228,8 @@ func (w *World) MoveRover(id uuid.UUID, b bearing.Bearing) (vector.Vector, error
|
|||
defer w.worldMutex.Unlock()
|
||||
|
||||
if i, ok := w.Rovers[id]; ok {
|
||||
// Calculate the distance
|
||||
distance := i.Attributes.Speed
|
||||
|
||||
// Calculate the full movement based on the bearing
|
||||
move := b.Vector().Multiplied(distance)
|
||||
|
||||
// Try the new move position
|
||||
newPos := i.Pos.Added(move)
|
||||
newPos := i.Pos.Added(b.Vector())
|
||||
|
||||
// Get the tile and verify it's empty
|
||||
if tile, err := w.Atlas.GetTile(newPos); err != nil {
|
||||
|
@ -402,7 +395,7 @@ func (w *World) ExecuteCommand(c *Command, rover uuid.UUID) (finished bool, err
|
|||
log.Printf("Executing command: %+v\n", *c)
|
||||
|
||||
switch c.Command {
|
||||
case "move":
|
||||
case CommandMove:
|
||||
if dir, err := bearing.FromString(c.Bearing); err != nil {
|
||||
return true, fmt.Errorf("unknown bearing in command %+v, skipping: %s\n", c, err)
|
||||
|
||||
|
@ -418,6 +411,7 @@ func (w *World) ExecuteCommand(c *Command, rover uuid.UUID) (finished bool, err
|
|||
finished = true
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return true, fmt.Errorf("unknown command: %s", c.Command)
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ func TestWorld_RoverAttributes(t *testing.T) {
|
|||
attribs, err := world.RoverAttributes(a)
|
||||
assert.NoError(t, err, "Failed to get rover attribs")
|
||||
assert.NotZero(t, attribs.Range, "Rover should not be spawned blind")
|
||||
assert.NotZero(t, attribs.Speed, "Rover should not be spawned unable to move")
|
||||
}
|
||||
|
||||
func TestWorld_DestroyRover(t *testing.T) {
|
||||
|
@ -65,8 +64,6 @@ func TestWorld_GetSetMovePosition(t *testing.T) {
|
|||
world := NewWorld(4, 4)
|
||||
a, err := world.SpawnRover()
|
||||
assert.NoError(t, err)
|
||||
attribs, err := world.RoverAttributes(a)
|
||||
assert.NoError(t, err, "Failed to get rover attribs")
|
||||
|
||||
pos := vector.Vector{
|
||||
X: 0.0,
|
||||
|
@ -84,7 +81,7 @@ func TestWorld_GetSetMovePosition(t *testing.T) {
|
|||
duration := 1
|
||||
newPos, err = world.MoveRover(a, b)
|
||||
assert.NoError(t, err, "Failed to set position for rover")
|
||||
pos.Add(vector.Vector{X: 0, Y: attribs.Speed * duration}) // We should have move one unit of the speed north
|
||||
pos.Add(vector.Vector{X: 0, Y: duration})
|
||||
assert.Equal(t, pos, newPos, "Failed to correctly move position for rover")
|
||||
|
||||
// Place a tile in front of the rover
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue