Reject move commands in non-cardinal directions
This commit is contained in:
parent
0e731df1a3
commit
c2e3c9f090
4 changed files with 23 additions and 9 deletions
|
@ -426,8 +426,10 @@ func (w *World) Enqueue(rover string, commands ...Command) error {
|
|||
for _, c := range commands {
|
||||
switch c.Command {
|
||||
case roveapi.CommandType_move:
|
||||
if _, err := maths.FromString(c.Bearing); err != nil {
|
||||
if b, err := maths.BearingFromString(c.Bearing); err != nil {
|
||||
return fmt.Errorf("unknown bearing: %s", c.Bearing)
|
||||
} else if !b.IsCardinal() {
|
||||
return fmt.Errorf("bearing must be cardinal")
|
||||
}
|
||||
case roveapi.CommandType_broadcast:
|
||||
if len(c.Message) > 3 {
|
||||
|
@ -505,7 +507,7 @@ func (w *World) ExecuteCommand(c *Command, rover string) (err error) {
|
|||
|
||||
switch c.Command {
|
||||
case roveapi.CommandType_move:
|
||||
if dir, err := maths.FromString(c.Bearing); err != nil {
|
||||
if dir, err := maths.BearingFromString(c.Bearing); err != nil {
|
||||
return err
|
||||
} else if _, err := w.MoveRover(rover, dir); err != nil {
|
||||
return err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue