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

Iron #373

Merged
merged 31 commits into from
Jun 14, 2022
Merged

Iron #373

Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c94c499
Add iron
xsebek Jun 8, 2022
d231ab8
Make iron gear
xsebek Jun 8, 2022
95752fc
Make iron or wooden motors and gears
xsebek Jun 8, 2022
99ce4d2
Add metal drill recipes
xsebek Jun 8, 2022
32f1ac0
Handle multiple capability providers
xsebek Jun 8, 2022
06b9f28
Fix entity attributes (thanks @byorgey)
xsebek Jun 10, 2022
5650d51
Fix iron plate description
xsebek Jun 10, 2022
7cee36f
Add compass device
xsebek Jun 10, 2022
dd03922
Disallow cardinal diretion values without compass
xsebek Jun 10, 2022
be8eb73
Refactor checking required devices
xsebek Jun 10, 2022
a8de1d5
Make down a relative direction
xsebek Jun 10, 2022
d0ba08a
Improve drilling direction error message
xsebek Jun 10, 2022
e5a4571
Inline moves in benchmark
xsebek Jun 10, 2022
5b54dcc
Check direction on use
xsebek Jun 10, 2022
fe1f851
Revert "Disallow cardinal diretion values without compass"
xsebek Jun 10, 2022
f527b18
Parse Recipe With EntityMap
xsebek Jun 11, 2022
14114dd
Add custom recipes to scenarios
xsebek Jun 11, 2022
806fa32
Use custom recipes in scenarios
xsebek Jun 11, 2022
9bf5b17
Fix doctest setup
xsebek Jun 11, 2022
2f5f5f6
Restyled by fourmolu
restyled-commits Jun 11, 2022
79eddbc
Fix wording (thanks @byorgey)
xsebek Jun 12, 2022
7a5e4cf
Explain ignoreOK
xsebek Jun 12, 2022
6c01e62
Differentiate exception for CGod and others
xsebek Jun 12, 2022
c29558c
Use common code for incapable exception
xsebek Jun 12, 2022
dcbd614
Rename fromE
xsebek Jun 12, 2022
e916322
Improve and test incapable exception
xsebek Jun 12, 2022
9e24293
Fix creative robots not getting devices
xsebek Jun 12, 2022
a8c83be
Restyled by fourmolu
restyled-commits Jun 12, 2022
6365428
Add standard devices
xsebek Jun 14, 2022
8ab3ef7
Explain blasphemy better
xsebek Jun 14, 2022
950256a
Merge branch 'main' into iron
mergify[bot] Jun 14, 2022
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: 4 additions & 4 deletions bench/Benchmark.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ circlerProgram =
let forever : cmd () -> cmd () = \c. c; forever c
in forever (
move;
turn east;
turn right;
xsebek marked this conversation as resolved.
Show resolved Hide resolved
move;
turn south;
turn right;
move;
turn west;
turn right;
move;
turn north
turn right;
)
|]

Expand Down
92 changes: 78 additions & 14 deletions data/entities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@
mountains, but those would require a drill to access and mine.
properties: [portable]

- name: copper vein
display:
attr: copper'
char: 'A'
description:
- A place in the mountains where raw copper 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: copper mine
display:
attr: copper'
Expand Down Expand Up @@ -137,6 +127,40 @@
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 mine
byorgey marked this conversation as resolved.
Show resolved Hide resolved
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 +169,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 +303,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 +408,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 +472,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 +531,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 +628,14 @@
exponentiation."
properties: [portable]
capabilities: [arith]

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