Skip to content

Add a few tutorial challenges #411

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

Merged
merged 6 commits into from
Jun 22, 2022
Merged
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
9 changes: 7 additions & 2 deletions data/entities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,13 @@
attr: device
char: '%'
description:
- Installing treads on a robot allows it to move (via the 'move' command) and turn
(via the 'turn' command).
- Installing treads on a robot allows it to move and turn.
- The 'move' command simply moves the robot one space in its direction.
- 'Example:'
- ' move; move; // moves two spaces'
- The 'turn' command takes a direction as an argument, which
can be either absolute (north, west, east, south) or relative
(left, right, forward, back).
- 'Example:'
- ' move; turn left; move; turn right'
capabilities: [move, turn]
Expand Down
25 changes: 11 additions & 14 deletions data/scenarios/02Tutorials/00-move.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
name: Moving, part 1
entities:
- name: goal
display:
attr: device
char: 'X'
description:
- |
Robots can use the 'move' command to move forward one unit
in the direction they are currently facing. To complete
this challenge, move your robot two spaces to the right, to
the coordinates (2,0).
properties: [portable]
description: |
Learn how to move and chain commands.
#
# The players might not use ';' here, so it should be brought up again when building robots.
#
goal:
- Robots can use the 'move' command to move forward one unit
in the direction they are currently facing.
- To complete this challenge, move your robot two spaces to the right,
to the coordinates (2,0).
- Note that you can chain commands with ';'.
win: |
try {
loc <- as base {whereami};
Expand All @@ -25,8 +24,6 @@ robots:
devices:
- treads
- logger
inventory:
- [1, goal]
world:
default: [blank, none]
palette:
Expand Down
54 changes: 38 additions & 16 deletions data/scenarios/02Tutorials/01-turn.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
name: Moving, part 2
description: |
Learn how to turn in some direction and pass parameters to commands.
#
# Note that parameters are not in parentheses like in e.g. Python.
#
goal:
- In addition to 'move', you can use the 'turn' command
to turn your robot. For example 'turn right' or 'turn east'.
- Move over to the inventory view with Alt+E and select the treads
device to read about the details. You can come back with Alt+R.
- Afterwards move your robot to the flower in the northeast corner.
- Remember, you can chain commands with ';', for example 'move; move; move;'.
entities:
- name: goal
display:
attr: device
char: 'X'
description:
- |
In addition to 'move', you can use the 'turn' command
to turn your robot. 'turn' takes a direction as an argument,
which can be either absolute (north, west, east, south) or relative
(left, right, forward, back). Move your robot to the flower in
the northeast corner.
- name: knownflower
display:
attr: flower
char: '*'
description:
- A flower.
properties: [known]
- name: left T
display:
attr: entity
char: '├'
description:
- How did you get out of the maze? You should never see me.
properties: [unwalkable, known]
- name: right T
display:
attr: entity
char: '┤'
description:
- How did you get out of the maze? You should never see me.
properties: [unwalkable, known]

win: |
try {
loc <- as base {whereami};
return (loc == (3,1))
return (loc == (3,4))
} { return false }
solution: |
move; move; move; turn north; move
move; move; move;
turn north; move; move; turn west;
move; move; move;
turn north; move; move; turn east;
move; move; move;

robots:
- name: base
Expand All @@ -35,22 +54,25 @@ robots:
- treads
- compass
- logger
inventory:
- [1, goal]
world:
default: [blank, none]
palette:
'.': [grass, null]
'├': [stone, left T]
'┤': [stone, right T]
'┌': [stone, upper left corner]
'┐': [stone, upper right corner]
'└': [stone, lower left corner]
'┘': [stone, lower right corner]
'─': [stone, horizontal wall]
'│': [stone, vertical wall]
'*': [grass, knownflower]
upperleft: [-1, 2]
upperleft: [-1, 5]
map: |
┌────┐
│...*│
│.───┤
│....│
├───.│
│....│
└────┘
41 changes: 0 additions & 41 deletions data/scenarios/02Tutorials/02-craft.yaml

This file was deleted.

72 changes: 72 additions & 0 deletions data/scenarios/02Tutorials/02-types.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Typing
description: |
Learn about the types of commands and values.
goal:
- Before we get to solving more complex challenges,
it would be good to get used to how the commands
in Swarm language work and how they don't.
- Previosly, you have used the 'turn' command,
which takes one parameter, which must be a direction.
- What happens if you do not pass it a direction?
- 'Try these commands:'
- |
'turn 1'
- |
'turn move'
- |
'turn north move'
- |
'move move'
- The last two commands might give the most confusing error,
when they are obviously missing a ';' separating the commands.
- |
Finally try these commands, which will just show the value
(passing values will be useful later) and its type:
- |
'turn'
- |
'north'
- Once you are done, do 'place "Win"' to finish this challenge.
entities:
- name: Win
display:
attr: device
char: 'W'
description:
- Do 'place "Win"' once you are done with this challenge.
properties: [known, portable]
win: |
try {
w <- as base {has "Win"};
return (not w);
} { return false }
solution: |
place "Win"

robots:
- name: base
loc: [0,0]
dir: [1,0]
devices:
- treads
- compass
- logger
- grabber
inventory:
- [1, Win]
world:
default: [blank, none]
palette:
'.': [grass, null]
'┌': [stone, upper left corner]
'┐': [stone, upper right corner]
'└': [stone, lower left corner]
'┘': [stone, lower right corner]
'─': [stone, horizontal wall]
'│': [stone, vertical wall]
upperleft: [-1, 1]
map: |
┌───┐
│...│
│...│
└───┘
43 changes: 43 additions & 0 deletions data/scenarios/02Tutorials/03-craft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Crafting, part 1
description: |
Learn how to make new things using recipes.
#
# The players should read the recipes and aquaint themselves with the UI.
# This also motivates the next tutorial about obtaining entites.
#
goal:
- Robots can use the 'make' command to make things.
- Your base has a few trees in its inventory. Select them to see the
available recipes.
- Your goal is to make a "branch predictor", so you will have to make
some "branches" first.
win: |
try {
as base {has "branch predictor"}
} { return false }
solution: |
make "branch"; make "branch predictor"
robots:
- name: base
loc: [0,0]
dir: [1,0]
devices:
- workbench
- logger
inventory:
- [10, tree]
world:
default: [blank, none]
palette:
'┌': [stone, upper left corner]
'┐': [stone, upper right corner]
'└': [stone, lower left corner]
'┘': [stone, lower right corner]
'─': [stone, horizontal wall]
'│': [stone, vertical wall]
' ': [grass, null]
upperleft: [-1, 1]
map: |
┌─┐
│ │
└─┘
50 changes: 50 additions & 0 deletions data/scenarios/02Tutorials/04-grab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Grab
description: |
Learn how to interact with the world by grabbing entities.
goal:
- Previously you learned how to make new things (like a branch predictor) from ingredients.
Now you will learn how to obtain the ingredients you need.
- There are trees ahead of you, 'move' to each one and 'grab' it.
- You can learn more by selecting the grabber device in your inventory.
- |
TIP: You can use the arrow key Up ('↑') to reuse your previous commands.
win: |
try {
t <- as base {count "tree"};
return (t >= 6);
} { return false }
solution:
move;
move; grab;
move; grab;
move; grab;
move; grab;
move; grab;
move; grab;
robots:
- name: base
loc: [0,0]
dir: [1,0]
devices:
- treads
- grabber
- logger
- compass
inventory:
- [0, tree]
world:
default: [blank, none]
palette:
'.': [grass, null]
'T': [grass, tree]
'┌': [stone, upper left corner]
'┐': [stone, upper right corner]
'└': [stone, lower left corner]
'┘': [stone, lower right corner]
'─': [stone, horizontal wall]
'│': [stone, vertical wall]
upperleft: [-1, 1]
map: |
┌────────┐
│..TTTTTT│
└────────┘
Loading