Remove move and recharge commands in favor of toggle command for the sails
This commit is contained in:
parent
89123394cd
commit
6c75f07aff
8 changed files with 169 additions and 280 deletions
|
@ -6,9 +6,6 @@ import "github.com/mdiluz/rove/proto/roveapi"
|
|||
type Command struct {
|
||||
Command roveapi.CommandType `json:"command"`
|
||||
|
||||
// Used in the move command
|
||||
Bearing roveapi.Bearing `json:"bearing,omitempty"`
|
||||
|
||||
// Used in the broadcast command
|
||||
Message []byte `json:"message,omitempty"`
|
||||
}
|
||||
|
|
|
@ -2,69 +2,28 @@ package rove
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mdiluz/rove/pkg/maths"
|
||||
"github.com/mdiluz/rove/proto/roveapi"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCommand_Move(t *testing.T) {
|
||||
world := NewWorld(8)
|
||||
a, err := world.SpawnRover()
|
||||
assert.NoError(t, err)
|
||||
pos := maths.Vector{
|
||||
X: 1.0,
|
||||
Y: 2.0,
|
||||
}
|
||||
|
||||
err = world.WarpRover(a, pos)
|
||||
assert.NoError(t, err, "Failed to set position for rover")
|
||||
|
||||
// Try the move command
|
||||
moveCommand := Command{Command: roveapi.CommandType_move, Bearing: roveapi.Bearing_North}
|
||||
assert.NoError(t, world.Enqueue(a, moveCommand), "Failed to execute move command")
|
||||
|
||||
// Tick the world
|
||||
world.EnqueueAllIncoming()
|
||||
world.ExecuteCommandQueues()
|
||||
|
||||
newPos, err := world.RoverPosition(a)
|
||||
assert.NoError(t, err, "Failed to set position for rover")
|
||||
pos.Add(maths.Vector{X: 0.0, Y: 1})
|
||||
assert.Equal(t, pos, newPos, "Failed to correctly set position for rover")
|
||||
func TestCommand_Raise(t *testing.T) {
|
||||
// TODO: Test the raise command
|
||||
}
|
||||
|
||||
func TestCommand_Recharge(t *testing.T) {
|
||||
world := NewWorld(8)
|
||||
a, err := world.SpawnRover()
|
||||
assert.NoError(t, err)
|
||||
pos := maths.Vector{
|
||||
X: 1.0,
|
||||
Y: 2.0,
|
||||
}
|
||||
|
||||
err = world.WarpRover(a, pos)
|
||||
assert.NoError(t, err, "Failed to set position for rover")
|
||||
|
||||
// Move to use up some charge
|
||||
moveCommand := Command{Command: roveapi.CommandType_move, Bearing: roveapi.Bearing_North}
|
||||
assert.NoError(t, world.Enqueue(a, moveCommand), "Failed to queue move command")
|
||||
|
||||
// Tick the world
|
||||
world.EnqueueAllIncoming()
|
||||
world.ExecuteCommandQueues()
|
||||
|
||||
rover, _ := world.GetRover(a)
|
||||
assert.Equal(t, rover.MaximumCharge-1, rover.Charge)
|
||||
|
||||
chargeCommand := Command{Command: roveapi.CommandType_recharge}
|
||||
assert.NoError(t, world.Enqueue(a, chargeCommand), "Failed to queue recharge command")
|
||||
|
||||
// Tick the world
|
||||
world.EnqueueAllIncoming()
|
||||
world.ExecuteCommandQueues()
|
||||
|
||||
rover, _ = world.GetRover(a)
|
||||
assert.Equal(t, rover.MaximumCharge, rover.Charge)
|
||||
|
||||
func TestCommand_Lower(t *testing.T) {
|
||||
// TODO: Test the lower command
|
||||
}
|
||||
|
||||
func TestCommand_Stash(t *testing.T) {
|
||||
// TODO: Test the stash command
|
||||
}
|
||||
|
||||
func TestCommand_Repair(t *testing.T) {
|
||||
// TODO: Test the repair command
|
||||
}
|
||||
|
||||
func TestCommand_Broadcast(t *testing.T) {
|
||||
// TODO: Test the stash command
|
||||
}
|
||||
|
||||
func TestCommand_Invalid(t *testing.T) {
|
||||
// TODO: Test the invalid command
|
||||
}
|
||||
|
|
|
@ -380,10 +380,6 @@ func (w *World) Enqueue(rover string, commands ...Command) error {
|
|||
// First validate the commands
|
||||
for _, c := range commands {
|
||||
switch c.Command {
|
||||
case roveapi.CommandType_move:
|
||||
if c.Bearing == roveapi.Bearing_BearingUnknown {
|
||||
return fmt.Errorf("bearing must be valid")
|
||||
}
|
||||
case roveapi.CommandType_broadcast:
|
||||
if len(c.Message) > 3 {
|
||||
return fmt.Errorf("too many characters in message (limit 3): %d", len(c.Message))
|
||||
|
@ -393,9 +389,9 @@ func (w *World) Enqueue(rover string, commands ...Command) error {
|
|||
return fmt.Errorf("invalid message character: %c", b)
|
||||
}
|
||||
}
|
||||
case roveapi.CommandType_toggle:
|
||||
case roveapi.CommandType_stash:
|
||||
case roveapi.CommandType_repair:
|
||||
case roveapi.CommandType_recharge:
|
||||
// Nothing to verify
|
||||
default:
|
||||
return fmt.Errorf("unknown command: %s", c.Command)
|
||||
|
@ -459,10 +455,8 @@ func (w *World) ExecuteCommand(c *Command, rover string) (err error) {
|
|||
log.Printf("Executing command: %+v for %s\n", *c, rover)
|
||||
|
||||
switch c.Command {
|
||||
case roveapi.CommandType_move:
|
||||
if _, err := w.MoveRover(rover, c.Bearing); err != nil {
|
||||
return err
|
||||
}
|
||||
case roveapi.CommandType_toggle:
|
||||
// TODO: Toggle the sails
|
||||
|
||||
case roveapi.CommandType_stash:
|
||||
if _, err := w.RoverStash(rover); err != nil {
|
||||
|
@ -481,15 +475,12 @@ func (w *World) ExecuteCommand(c *Command, rover string) (err error) {
|
|||
r.AddLogEntryf("repaired self to %d", r.Integrity)
|
||||
w.Rovers[rover] = r
|
||||
}
|
||||
case roveapi.CommandType_recharge:
|
||||
_, err := w.RoverRecharge(rover)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case roveapi.CommandType_broadcast:
|
||||
if err := w.RoverBroadcast(rover, c.Message); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown command: %s", c.Command)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue