-
Notifications
You must be signed in to change notification settings - Fork 63
Commands Cheat Sheet
| Syntax | Type | Capability | Description |
|---|---|---|---|
noop |
cmd () |
Do nothing. | |
wait |
int -> cmd () |
Wait for a number of time steps. | |
selfdestruct |
cmd () |
selfdestruct | Self-destruct the robot. |
move |
cmd () |
move | Move forward one step. |
turn |
dir -> cmd () |
turn | Turn in some direction. |
grab |
cmd string |
grab | Grab an item from the current location. |
harvest |
cmd string |
harvest | Harvest an item from the current location. |
place |
string -> cmd () |
place | Place an item at the current location. |
give |
robot -> string -> cmd () |
give | Give an item to another robot nearby. |
install |
robot -> string -> cmd () |
install | Install a device from inventory on a robot. |
make |
string -> cmd () |
make | Make an item using a recipe. |
has |
string -> cmd bool |
Sense whether the robot has a given item in its inventory. | |
count |
string -> cmd int |
count | Get the count of a given item in a robot's inventory. |
drill |
dir -> cmd () |
drill | Drill through an entity. |
build |
∀ a. {cmd a} -> cmd robot |
build | Construct a new robot. |
salvage |
cmd () |
salvage | Deconstruct an old robot. |
reprogram |
∀ a. robot -> {cmd a} -> cmd () |
reprogram | Reprogram another robot with a new command. |
say |
string -> cmd () |
Emit a message. | |
log |
string -> cmd () |
log | Log the string in the robot's logger. |
view |
robot -> cmd () |
View the given robot. | |
appear |
string -> cmd () |
appear | Set how the robot is displayed. |
create |
string -> cmd () |
god | Create an item out of thin air. |
whereami |
cmd (int * int) |
senseloc | Get the current x and y coordinates. |
blocked |
cmd bool |
sensefront | See if the robot can move forward. |
scan |
dir -> cmd (() + string) |
scan | Scan a nearby location for entities. |
upload |
robot -> cmd () |
scan | Upload a robot's known entities and log to another robot. |
ishere |
string -> cmd bool |
sensehere | See if a specific entity is in the current location. |
whoami |
cmd string |
whoami | Get the robot's display name. |
setname |
string -> cmd () |
Set the robot's display name. | |
random |
int -> cmd int |
random | Get a uniformly random integer. |
run |
string -> cmd () |
Run a program loaded from a file. | |
return |
∀ a. a -> cmd a |
Make the value a result in cmd. |
|
try |
∀ a. {cmd a} -> {cmd a} -> cmd a |
Execute a command, catching errors. | |
teleport |
robot -> int * int -> cmd () |
teleport | Teleport a robot to the given location. |
as |
∀ a. robot -> {cmd a} -> cmd a |
god | Hypothetically run a command as if you were another robot. |
robotnamed |
string -> cmd robot |
god | Find a robot by name. |
robotnumbered |
int -> cmd robot |
god | Find a robot by number. |
knows |
string -> cmd bool |
Check if the robot knows about an entity. |
These functions are evaluated immediately once they have enough arguments.
| Syntax | Type | Capability | Description |
|---|---|---|---|
self |
robot |
whoami | Get a reference to the current robot. |
parent |
robot |
Get a reference to the robot's parent. | |
base |
robot |
Get a reference to the base. | |
if |
∀ a. bool -> {a} -> {a} -> a |
cond | If-Then-Else function. |
inl |
∀ a b. a -> a + b |
Put the value into the left component of a sum type. | |
inr |
∀ a b. b -> a + b |
Put the value into the right component of a sum type. | |
case |
∀ a b c. a + b -> (a -> c) -> (b -> c) -> c |
Evaluate one of the given functions on a value of sum type. | |
fst |
∀ a b. a * b -> a |
Get the first value of a pair. | |
snd |
∀ a b. a * b -> b |
Get the second value of a pair. | |
force |
∀ a. {a} -> a |
Force the evaluation of a delayed value. | |
undefined |
∀ a. a |
A value of any type, that is evaluated as error. | |
fail |
∀ a. string -> a |
A value of any type, that is evaluated as error with message. | |
not |
bool -> bool |
Negate the boolean value. | |
format |
∀ a. a -> string |
log | Turn an arbitrary value into a string. |
| Syntax | Type | Capability | Description |
|---|---|---|---|
- |
int -> int |
arith | Negate the given integer value. |
== |
∀ a. a -> a -> bool |
compare | Check that the left value is equal to the right one. |
!= |
∀ a. a -> a -> bool |
compare | Check that the left value is not equal to the right one. |
< |
∀ a. a -> a -> bool |
compare | Check that the left value is lesser than the right one. |
> |
∀ a. a -> a -> bool |
compare | Check that the left value is greater than the right one. |
<= |
∀ a. a -> a -> bool |
compare | Check that the left value is lesser or equal to the right one. |
>= |
∀ a. a -> a -> bool |
compare | Check that the left value is greater or equal to the right one. |
|| |
bool -> bool -> bool |
Logical or (true if either value is true). | |
&& |
bool -> bool -> bool |
Logical and (true if both values are true). | |
+ |
int -> int -> int |
arith | Add the given integer values. |
- |
int -> int -> int |
arith | Subtract the given integer values. |
* |
int -> int -> int |
arith | Multiply the given integer values. |
/ |
int -> int -> int |
arith | Divide the left integer value by the right one, rounding down. |
^ |
int -> int -> int |
arith | Raise the left integer value to the power of the right one. |
++ |
string -> string -> string |
log | Concatenate the given strings. |
$ |
∀ a b. (a -> b) -> a -> b |
Apply the function on the left to the value on the right. |
- syntax:
noop - type:
cmd ()
Do nothing.
This is different than Wait in that it does not take up a time step.
It is useful for commands like if, which requires you to provide both branches.
Usually it is automatically inserted where needed, so you do not have to worry about it.
- syntax:
wait - type:
int -> cmd ()
Wait for a number of time steps.
- syntax:
selfdestruct - type:
cmd () - required capabilities: selfdestruct
Self-destruct the robot.
Useful to not clutter the world.
This destroys the robot's inventory, so consider salvage as an alternative.
- syntax:
move - type:
cmd () - required capabilities: move
Move forward one step.
- syntax:
turn - type:
dir -> cmd () - required capabilities: turn
Turn in some direction.
- syntax:
grab - type:
cmd string - required capabilities: grab
Grab an item from the current location.
- syntax:
harvest - type:
cmd string - required capabilities: harvest
Harvest an item from the current location.
Leaves behind a growing seed if the harvested item is growable.
Otherwise it works exactly like grab.
- syntax:
place - type:
string -> cmd () - required capabilities: place
Place an item at the current location.
The current location has to be empty for this to work.
- syntax:
give - type:
robot -> string -> cmd () - required capabilities: give
Give an item to another robot nearby.
- syntax:
install - type:
robot -> string -> cmd () - required capabilities: install
Install a device from inventory on a robot.
- syntax:
make - type:
string -> cmd () - required capabilities: make
Make an item using a recipe.
- syntax:
has - type:
string -> cmd bool
Sense whether the robot has a given item in its inventory.
- syntax:
count - type:
string -> cmd int - required capabilities: count
Get the count of a given item in a robot's inventory.
- syntax:
drill - type:
dir -> cmd () - required capabilities: drill
Drill through an entity.
Usually you want to drill forward when exploring to clear out obstacles.
When you have found a source to drill, you can stand on it and drill down.
See what recipes with drill you have available.
- syntax:
build - type:
∀ a. {cmd a} -> cmd robot - required capabilities: build
Construct a new robot.
You can specify a command for the robot to execute. If the command requires devices they will be installed from your inventory.
- syntax:
salvage - type:
cmd () - required capabilities: salvage
Deconstruct an old robot.
Salvaging a robot will give you its inventory, installed devices and log.
- syntax:
reprogram - type:
∀ a. robot -> {cmd a} -> cmd () - required capabilities: reprogram
Reprogram another robot with a new command.
The other robot has to be nearby and idle.
- syntax:
say - type:
string -> cmd ()
Emit a message.
The message will be in a global log, which you can not currently view. https://github.com/swarm-game/swarm/issues/513
- syntax:
log - type:
string -> cmd () - required capabilities: log
Log the string in the robot's logger.
- syntax:
view - type:
robot -> cmd ()
View the given robot.
- syntax:
appear - type:
string -> cmd () - required capabilities: appear
Set how the robot is displayed.
You can either specify one character or five (for each direction). The default is "X^>v<".
- syntax:
create - type:
string -> cmd () - required capabilities: god
Create an item out of thin air.
Only available in creative mode.
- syntax:
whereami - type:
cmd (int * int) - required capabilities: senseloc
Get the current x and y coordinates.
- syntax:
blocked - type:
cmd bool - required capabilities: sensefront
See if the robot can move forward.
- syntax:
scan - type:
dir -> cmd (() + string) - required capabilities: scan
Scan a nearby location for entities.
Adds the entity (not robot) to your inventory with count 0 if there is any. If you can use sum types, you can also inspect the result directly.
- syntax:
upload - type:
robot -> cmd () - required capabilities: scan
Upload a robot's known entities and log to another robot.
- syntax:
ishere - type:
string -> cmd bool - required capabilities: sensehere
See if a specific entity is in the current location.
- syntax:
whoami - type:
cmd string - required capabilities: whoami
Get the robot's display name.
- syntax:
setname - type:
string -> cmd ()
Set the robot's display name.
- syntax:
random - type:
int -> cmd int - required capabilities: random
Get a uniformly random integer.
The random integer will be chosen from the range 0 to n-1, exclusive of the argument.
- syntax:
run - type:
string -> cmd ()
Run a program loaded from a file.
- syntax:
return - type:
∀ a. a -> cmd a
Make the value a result in cmd.
- syntax:
try - type:
∀ a. {cmd a} -> {cmd a} -> cmd a
Execute a command, catching errors.
- syntax:
teleport - type:
robot -> int * int -> cmd () - required capabilities: teleport
Teleport a robot to the given location.
- syntax:
as - type:
∀ a. robot -> {cmd a} -> cmd a - required capabilities: god
Hypothetically run a command as if you were another robot.
- syntax:
robotnamed - type:
string -> cmd robot - required capabilities: god
Find a robot by name.
- syntax:
robotnumbered - type:
int -> cmd robot - required capabilities: god
Find a robot by number.
- syntax:
knows - type:
string -> cmd bool
Check if the robot knows about an entity.
- syntax:
self - type:
robot - required capabilities: whoami
Get a reference to the current robot.
- syntax:
parent - type:
robot
Get a reference to the robot's parent.
- syntax:
base - type:
robot
Get a reference to the base.
- syntax:
if - type:
∀ a. bool -> {a} -> {a} -> a - required capabilities: cond
If-Then-Else function.
If the bool predicate is true then evaluate the first expression, otherwise the second.
- syntax:
inl - type:
∀ a b. a -> a + b
Put the value into the left component of a sum type.
- syntax:
inr - type:
∀ a b. b -> a + b
Put the value into the right component of a sum type.
- syntax:
case - type:
∀ a b c. a + b -> (a -> c) -> (b -> c) -> c
Evaluate one of the given functions on a value of sum type.
- syntax:
fst - type:
∀ a b. a * b -> a
Get the first value of a pair.
- syntax:
snd - type:
∀ a b. a * b -> b
Get the second value of a pair.
- syntax:
force - type:
∀ a. {a} -> a
Force the evaluation of a delayed value.
- syntax:
undefined - type:
∀ a. a
A value of any type, that is evaluated as error.
- syntax:
fail - type:
∀ a. string -> a
A value of any type, that is evaluated as error with message.
- syntax:
not - type:
bool -> bool
Negate the boolean value.
- syntax:
format - type:
∀ a. a -> string - required capabilities: log
Turn an arbitrary value into a string.
- syntax:
- - type:
int -> int - required capabilities: arith
Negate the given integer value.
- syntax:
== - type:
∀ a. a -> a -> bool - required capabilities: compare
Check that the left value is equal to the right one.
- syntax:
!= - type:
∀ a. a -> a -> bool - required capabilities: compare
Check that the left value is not equal to the right one.
- syntax:
< - type:
∀ a. a -> a -> bool - required capabilities: compare
Check that the left value is lesser than the right one.
- syntax:
> - type:
∀ a. a -> a -> bool - required capabilities: compare
Check that the left value is greater than the right one.
- syntax:
<= - type:
∀ a. a -> a -> bool - required capabilities: compare
Check that the left value is lesser or equal to the right one.
- syntax:
>= - type:
∀ a. a -> a -> bool - required capabilities: compare
Check that the left value is greater or equal to the right one.
- syntax:
|| - type:
bool -> bool -> bool
Logical or (true if either value is true).
- syntax:
&& - type:
bool -> bool -> bool
Logical and (true if both values are true).
- syntax:
+ - type:
int -> int -> int - required capabilities: arith
Add the given integer values.
- syntax:
- - type:
int -> int -> int - required capabilities: arith
Subtract the given integer values.
- syntax:
* - type:
int -> int -> int - required capabilities: arith
Multiply the given integer values.
- syntax:
/ - type:
int -> int -> int - required capabilities: arith
Divide the left integer value by the right one, rounding down.
- syntax:
^ - type:
int -> int -> int - required capabilities: arith
Raise the left integer value to the power of the right one.
- syntax:
++ - type:
string -> string -> string - required capabilities: log
Concatenate the given strings.
- syntax:
$ - type:
∀ a b. (a -> b) -> a -> b
Apply the function on the left to the value on the right.
This operator is useful to avoid nesting parentheses.
For exaple:
f $ g $ h x = f (g (h x))