Add salvage command
Slight refactor to re-use command variables Also fixes the cmdline client turn command
This commit is contained in:
parent
41cd93e986
commit
2c1bb80779
5 changed files with 306 additions and 225 deletions
|
@ -39,7 +39,7 @@ func TestCommand_Turn(t *testing.T) {
|
|||
a, err := w.SpawnRover()
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = w.Enqueue(a, &roveapi.Command{Command: roveapi.CommandType_turn, Turn: roveapi.Bearing_NorthWest})
|
||||
err = w.Enqueue(a, &roveapi.Command{Command: roveapi.CommandType_turn, Bearing: roveapi.Bearing_NorthWest})
|
||||
assert.NoError(t, err)
|
||||
w.Tick()
|
||||
|
||||
|
@ -122,7 +122,7 @@ func TestCommand_Broadcast(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
// Enqueue the broadcast and tick
|
||||
err = w.Enqueue(name, &roveapi.Command{Command: roveapi.CommandType_broadcast, Broadcast: []byte("ABC")})
|
||||
err = w.Enqueue(name, &roveapi.Command{Command: roveapi.CommandType_broadcast, Data: []byte("ABC")})
|
||||
assert.NoError(t, err)
|
||||
w.Tick()
|
||||
|
||||
|
|
|
@ -435,16 +435,16 @@ func (w *World) Enqueue(rover string, commands ...*roveapi.Command) error {
|
|||
for _, c := range commands {
|
||||
switch c.Command {
|
||||
case roveapi.CommandType_broadcast:
|
||||
if len(c.GetBroadcast()) > 3 {
|
||||
return fmt.Errorf("too many characters in message (limit 3): %d", len(c.GetBroadcast()))
|
||||
if len(c.GetData()) > 3 {
|
||||
return fmt.Errorf("too many characters in message (limit 3): %d", len(c.GetData()))
|
||||
}
|
||||
for _, b := range c.GetBroadcast() {
|
||||
for _, b := range c.GetData() {
|
||||
if b < 37 || b > 126 {
|
||||
return fmt.Errorf("invalid message character: %c", b)
|
||||
}
|
||||
}
|
||||
case roveapi.CommandType_turn:
|
||||
if c.GetTurn() == roveapi.Bearing_BearingUnknown {
|
||||
if c.GetBearing() == roveapi.Bearing_BearingUnknown {
|
||||
return fmt.Errorf("turn command given unknown bearing")
|
||||
}
|
||||
case roveapi.CommandType_toggle:
|
||||
|
@ -569,12 +569,12 @@ func (w *World) ExecuteCommand(c *roveapi.Command, rover string) (err error) {
|
|||
}
|
||||
|
||||
case roveapi.CommandType_broadcast:
|
||||
if err := w.RoverBroadcast(rover, c.GetBroadcast()); err != nil {
|
||||
if err := w.RoverBroadcast(rover, c.GetData()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case roveapi.CommandType_turn:
|
||||
if _, err := w.RoverTurn(rover, c.GetTurn()); err != nil {
|
||||
if _, err := w.RoverTurn(rover, c.GetBearing()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue