Rename charge command to recharge
This commit is contained in:
parent
7272749614
commit
87af905bc8
7 changed files with 14 additions and 13 deletions
|
@ -10,8 +10,8 @@ const (
|
||||||
// CommandRepair Will attempt to repair the rover with an inventory object
|
// CommandRepair Will attempt to repair the rover with an inventory object
|
||||||
CommandRepair = "repair"
|
CommandRepair = "repair"
|
||||||
|
|
||||||
// CommandCharge Will use one tick to charge the rover
|
// CommandRecharge Will use one tick to charge the rover
|
||||||
CommandCharge = "charge"
|
CommandRecharge = "recharge"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command represends a single command to execute
|
// Command represends a single command to execute
|
||||||
|
|
|
@ -33,7 +33,7 @@ func TestCommand_Move(t *testing.T) {
|
||||||
assert.Equal(t, pos, newPos, "Failed to correctly set position for rover")
|
assert.Equal(t, pos, newPos, "Failed to correctly set position for rover")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommand_Charge(t *testing.T) {
|
func TestCommand_Recharge(t *testing.T) {
|
||||||
world := NewWorld(8)
|
world := NewWorld(8)
|
||||||
a, err := world.SpawnRover()
|
a, err := world.SpawnRover()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -56,8 +56,8 @@ func TestCommand_Charge(t *testing.T) {
|
||||||
rover, _ := world.GetRover(a)
|
rover, _ := world.GetRover(a)
|
||||||
assert.Equal(t, rover.MaximumCharge-1, rover.Charge)
|
assert.Equal(t, rover.MaximumCharge-1, rover.Charge)
|
||||||
|
|
||||||
chargeCommand := Command{Command: CommandCharge}
|
chargeCommand := Command{Command: CommandRecharge}
|
||||||
assert.NoError(t, world.Enqueue(a, chargeCommand), "Failed to queue charge command")
|
assert.NoError(t, world.Enqueue(a, chargeCommand), "Failed to queue recharge command")
|
||||||
|
|
||||||
// Tick the world
|
// Tick the world
|
||||||
world.EnqueueAllIncoming()
|
world.EnqueueAllIncoming()
|
||||||
|
|
|
@ -134,8 +134,8 @@ func (w *World) GetRover(rover string) (Rover, error) {
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChargeRover charges up a rover
|
// RoverRecharge charges up a rover
|
||||||
func (w *World) ChargeRover(rover string) (int, error) {
|
func (w *World) RoverRecharge(rover string) (int, error) {
|
||||||
w.worldMutex.Lock()
|
w.worldMutex.Lock()
|
||||||
defer w.worldMutex.Unlock()
|
defer w.worldMutex.Unlock()
|
||||||
|
|
||||||
|
@ -371,7 +371,7 @@ func (w *World) Enqueue(rover string, commands ...Command) error {
|
||||||
}
|
}
|
||||||
case CommandStash:
|
case CommandStash:
|
||||||
case CommandRepair:
|
case CommandRepair:
|
||||||
case CommandCharge:
|
case CommandRecharge:
|
||||||
// Nothing to verify
|
// Nothing to verify
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown command: %s", c.Command)
|
return fmt.Errorf("unknown command: %s", c.Command)
|
||||||
|
@ -459,8 +459,8 @@ func (w *World) ExecuteCommand(c *Command, rover string) (err error) {
|
||||||
r.Integrity = r.Integrity + 1
|
r.Integrity = r.Integrity + 1
|
||||||
w.Rovers[rover] = r
|
w.Rovers[rover] = r
|
||||||
}
|
}
|
||||||
case CommandCharge:
|
case CommandRecharge:
|
||||||
_, err := w.ChargeRover(rover)
|
_, err := w.RoverRecharge(rover)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ func TestWorld_RoverStash(t *testing.T) {
|
||||||
|
|
||||||
// Recharge the rover
|
// Recharge the rover
|
||||||
for i := 0; i < rover.MaximumCharge; i++ {
|
for i := 0; i < rover.MaximumCharge; i++ {
|
||||||
world.ChargeRover(a)
|
world.RoverRecharge(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Place an object
|
// Place an object
|
||||||
|
|
|
@ -43,6 +43,7 @@ type Command struct {
|
||||||
// "move" - Move the rover in a direction, requires bearing
|
// "move" - Move the rover in a direction, requires bearing
|
||||||
// "stash" - Stashes item at current location in rover inventory
|
// "stash" - Stashes item at current location in rover inventory
|
||||||
// "repair" - Repairs the rover using an inventory object
|
// "repair" - Repairs the rover using an inventory object
|
||||||
|
// "recharge" - Waits a tick to add more charge to the rover
|
||||||
Command string `protobuf:"bytes,1,opt,name=command,proto3" json:"command,omitempty"`
|
Command string `protobuf:"bytes,1,opt,name=command,proto3" json:"command,omitempty"`
|
||||||
// The bearing, example: NE
|
// The bearing, example: NE
|
||||||
Bearing string `protobuf:"bytes,2,opt,name=bearing,proto3" json:"bearing,omitempty"`
|
Bearing string `protobuf:"bytes,2,opt,name=bearing,proto3" json:"bearing,omitempty"`
|
||||||
|
|
|
@ -212,7 +212,7 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"command": {
|
"command": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"title": "The command to execute\n\"move\" - Move the rover in a direction, requires bearing\n\"stash\" - Stashes item at current location in rover inventory\n\"repair\" - Repairs the rover using an inventory object"
|
"title": "The command to execute\n\"move\" - Move the rover in a direction, requires bearing\n\"stash\" - Stashes item at current location in rover inventory\n\"repair\" - Repairs the rover using an inventory object\n\"recharge\" - Waits a tick to add more charge to the rover"
|
||||||
},
|
},
|
||||||
"bearing": {
|
"bearing": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|
|
@ -65,7 +65,7 @@ message Command {
|
||||||
// "move" - Move the rover in a direction, requires bearing
|
// "move" - Move the rover in a direction, requires bearing
|
||||||
// "stash" - Stashes item at current location in rover inventory
|
// "stash" - Stashes item at current location in rover inventory
|
||||||
// "repair" - Repairs the rover using an inventory object
|
// "repair" - Repairs the rover using an inventory object
|
||||||
// "charge" - Waits a tick to add more charge to the rover
|
// "recharge" - Waits a tick to add more charge to the rover
|
||||||
string command = 1;
|
string command = 1;
|
||||||
|
|
||||||
// The bearing, example: NE
|
// The bearing, example: NE
|
||||||
|
|
Loading…
Add table
Reference in a new issue