Convert number to repeat to avoid confusion

This commit is contained in:
Marc Di Luzio 2020-07-26 18:02:06 +01:00
parent c0d4a809c9
commit 74e1cd4564
6 changed files with 25 additions and 30 deletions

View file

@ -229,10 +229,10 @@ func TestCommand_Wait(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, roveapi.SailPosition_SolarCharging, r.SailPosition)
err = w.Enqueue(a, &roveapi.Command{Command: roveapi.CommandType_wait, Number: 5}, &roveapi.Command{Command: roveapi.CommandType_toggle})
err = w.Enqueue(a, &roveapi.Command{Command: roveapi.CommandType_wait, Repeat: 4}, &roveapi.Command{Command: roveapi.CommandType_toggle})
assert.NoError(t, err)
// Tick 5 times during the wait
// Tick 5 times during the wait (1 normal execute + 4)
for i := 0; i < 5; i++ {
w.Tick()

View file

@ -583,9 +583,6 @@ func (w *World) Enqueue(rover string, commands ...*roveapi.Command) error {
return fmt.Errorf("turn command given unknown bearing")
}
case roveapi.CommandType_wait:
if c.GetNumber() <= 0 {
return fmt.Errorf("wait command must be given positie number of ticks to wait")
}
case roveapi.CommandType_toggle:
case roveapi.CommandType_stash:
case roveapi.CommandType_repair:
@ -717,9 +714,6 @@ func (w *World) Tick() {
func (w *World) ExecuteCommand(c *roveapi.Command, rover string) (done bool, err error) {
log.Printf("Executing command: %+v for %s\n", c.Command, rover)
// Decrement the number of the command
c.Number--
switch c.Command {
case roveapi.CommandType_toggle:
_, err = w.RoverToggle(rover)
@ -741,7 +735,9 @@ func (w *World) ExecuteCommand(c *roveapi.Command, rover string) (done bool, err
return true, fmt.Errorf("unknown command: %s", c.Command)
}
return c.Number <= 0, err
// Decrement the repeat number
c.Repeat--
return c.Repeat < 0, err
}
// Daytime returns if it's currently daytime