StarOS: robot
Every robot script has robot. See the overview.
Attributes
| name | type | meaning |
|---|---|---|
robot.id |
string | uuid |
robot.name |
string | unique name |
robot.field |
string | the field it is on |
robot.x, robot.y |
int | cell; x grows east, y grows south |
robot.facing |
string | north, east, south or west |
robot.turn |
int | current turn |
robot.last |
string | outcome of the previous turn, see troubleshooting |
robot.base |
string | base_mk1 to base_mk5 |
robot.ports, robot.ports_used |
int | I/O ports of the base, and those taken |
robot.parts |
list | kinds of the attached parts |
robot.health, robot.max_health |
int | at 0 the robot is destroyed and leaves a wreck |
Functions
robot.move(direction): record a move of one cell. A second call replaces the first. The attempt turns the robot even when it is blocked.robot.log(message): keep a message with the turn. At most 10 a turn, 200 bytes each.robot.swap_battery(): trade depleted cells for the charged spares of your power station, before this turn's power is settled. The robot must stand just outside the station's dock side.
mobility
With wheels or tracks attached, the script also has mobility.move_cost_w(): what one move draws, in watts. A bare base draws 4 W, wheels 3 W, tracks 2 W. A move is still one cell a turn.
def tick():
if robot.last.startswith("blocked"):
robot.log("blocked at " + str(robot.x) + "," + str(robot.y))
robot.move("north")
else:
robot.move("east")