Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Iron #383

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Pretty much the only thing you can do at this point is build robots. Let's buil
one! Tab back to the REPL (or hit the <kbd>Meta</kbd>+<kbd>R</kbd>
shortcut) and type
```
build {turn north; move}
build {move}
```
then hit Enter. You should see a robot appear and travel to the
north one step before stopping. It should look something like this:
Expand Down Expand Up @@ -187,9 +187,12 @@ def m2 = m; m end; def m4 = m2; m2 end; def m8 = m4; m4 end
Great, now we have commands that will execute `move` multiple times.
Now let's use them:
```
build { turn west; m4; m }
build { turn left; m4; m }
```
This should build a robot that moves toward the green mass to the west.
The base is still turned north, so the robot needs to turn left
to be oriented to the west. Once you have a compass to install on
the robot, you will be able to `turn west` directly.

You might wonder at this point if it is possible to create a function
that takes a number as input and moves that many steps forward, like
Expand All @@ -213,7 +216,7 @@ Let's build another robot, but this time we will capture it in a
variable using the above syntax. Then we can use the `view` command
to focus on it instead of the base:
```
r <- build { turn west; m4; m }; view r
r <- build { turn left; m4; m }; view r
```
Note that `base` executes the `view r` command as soon as it
finishes executing the `build` command, which is about the same time
Expand Down Expand Up @@ -250,18 +253,19 @@ You can `scan` items in the world to learn about them, and later

Let's build a robot to learn about those green `?` things to the west:
```
build {turn west; m4; move; scan west; turn back; m4; upload base}
build {turn left; m4; move; scan forward; turn back; m4; upload base}
```
The `turn` command we used to turn the robot takes a direction as an
argument, which can be either an absolute direction
(`north`, `south`, `east`, or `west`) or a relative direction
(`forward`, `back`, `left`, `right`, or `down`). Instead of `upload
base` we could have also written `upload parent`; every robot has a
special variable `parent` which refers to the robot that built it.
argument, which can be either a relative direction (`forward`, `back`,
`left`, `right`, or `down`) or an absolute direction (`north`, `south`,
`east`, or `west`) for which you need a `compass`.
Instead of `upload base` we could have also written `upload parent`;
every robot has a special variable `parent` which refers to the robot
that built it.

Notice that the robot did not actually need to walk on top of a `?` to
learn about it, since it could `scan west` to scan the cell one unit
to the west (you can also `scan down` to scan an item directly beneath the
learn about it, since it could `scan forward` to scan the cell one unit
in its direction (you can also `scan down` to scan an item directly beneath the
robot). Also, it was able to `upload` at a distance of one cell away from
the base.

Expand Down Expand Up @@ -338,14 +342,14 @@ First, we have to make a `logger` device. A `logger` can be made from
one `log`, which you should already have in your inventory, so simply
type `make "logger"` at the REPL.

Now, how de we `build` a robot with the `logger` installed? The
Now, how do we `build` a robot with the `logger` installed? The
easiest way is to have the robot explicitly use the `log` command; the
`build` command analyzes the given program and automatically installs
any devices that will be necessary to execute it. (It is also
possible to manually install devices with the `install` command.) So
let's type the following:
```
crasher <- build {setname "crasher"; log "hi!"; turn south; move; grab; move}
crasher <- build {setname "crasher"; log "hi!"; turn back; move; grab; move}
```
(The `setname "crasher"` command is not strictly necessary, but will
help us understand the logs we look at later --- otherwise the log
Expand Down Expand Up @@ -382,9 +386,9 @@ the `upload` command, which we have seen before. In addition to
uploading knowledge about entities, it turns out that it also uploads
the log from a `logger`.
```
build {turn west; m8; m; thing <- grab; turn back; m8; m; give base thing}
build {turn left; m8; m; thing <- grab; turn back; m8; m; give base thing}
make "log"; make "logger"
build {setname "salvager"; turn south; move; log "salvaging..."; salvage; turn back; move; upload base}
build {setname "salvager"; turn back; move; log "salvaging..."; salvage; turn back; move; upload base}
```
The world should now look something like this:

Expand Down
8 changes: 1 addition & 7 deletions bench/Benchmark.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ circlerProgram =
let forever : cmd () -> cmd () = \c. c; forever c
in forever (
move;
turn east;
move;
turn south;
move;
turn west;
move;
turn north
turn right;
)
|]

Expand Down
93 changes: 89 additions & 4 deletions data/entities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,50 @@
water or steam.
properties: [portable]

- name: iron plate
display:
attr: iron
char: '■'
description:
- Worked iron suitable for crafting resilient tools.
- It also possess some electro-magnetic properties.
properties: [portable]

- name: iron gear
display:
attr: iron
char: '*'
description:
- An iron gear.
properties: [portable]

- name: iron ore
display:
attr: iron
char: 'F'
description:
- Raw iron ore. Used to create more resilient tools.
- It can only be mined by drilling in the mountains.
properties: [portable]

- name: iron vein
display:
attr: iron'
char: 'A'
description:
- A place in the mountains where raw iron ore can be mined.
As it is hidden inside a mountain, a tunnel needs to be
first drilled through, so that the vein becomes accessible.
properties: [unwalkable]

- name: iron mine
display:
attr: iron'
char: 'Å'
description:
- An iron vein that can be actively mined to produce iron ore.
properties: []

- name: furnace
display:
attr: fire
Expand All @@ -145,13 +189,24 @@
- A furnace can be used to turn metal ore into various useful products.
properties: [portable]

- name: motor
- name: small motor
display:
attr: entity
char: 'm'
description:
- A motor is useful for making devices that can turn when electric
current is applied.
- This one is rather small, but suprisingly efficient.
properties: [portable]

- name: big motor
display:
attr: entity
char: 'M'
description:
- A motor is useful for making devices that can turn when electric
current is applied.
- This one is huge and could be used to construct powerful machinery.
properties: [portable]

- name: flower
Expand Down Expand Up @@ -268,14 +323,23 @@
- A wooden box. It can hold things.
properties: [portable]

- name: gear
- name: wooden gear
display:
attr: wood
char: '*'
description:
- A wooden gear.
properties: [portable]

- name: iron gear
display:
attr: iron
char: '*'
description:
- An iron gear that is more resilient.
- It can be used to create bigger and more complex machines.
properties: [portable]

- name: counter
display:
attr: device
Expand Down Expand Up @@ -364,7 +428,7 @@
- Installing treads on a robot allows it to move (via the 'move' command) and turn
(via the 'turn' command).
- 'Example:'
- ' move; turn left; move; turn north'
- ' move; turn left; move; turn right'
capabilities: [move, turn]
properties: [portable]

Expand Down Expand Up @@ -428,6 +492,15 @@
capabilities: [drill]
properties: [portable]

- name: metal drill
display:
attr: iron
char: '!'
description:
- A metal drill allows robots to drill through rocks and mountains faster.
capabilities: [drill]
properties: [portable]

- name: 3D printer
display:
attr: device
Expand Down Expand Up @@ -478,7 +551,7 @@
is 'if' followed by three arguments: a boolean test and then
two delayed expressions of the same type.
- 'Example:'
- 'if (x > 3) {move} {turn west; move}'
- 'if (x > 3) {move} {turn right; move}'
properties: [portable]
capabilities: [cond]

Expand Down Expand Up @@ -575,3 +648,15 @@
exponentiation."
properties: [portable]
capabilities: [arith]

- name: compass
display:
attr: device
char: 'N'
description:
- "A compass gives robot the ability to orient itself in cardinal directions."
- "That is north, south, west and east."
- "Example:"
- "turn west; move; turn north"
properties: [portable]
capabilities: [orient]
Loading