-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add imap
to world DSL, with examples
#1990
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ Speedruns | |
Testing | ||
Vignettes | ||
Mechanics | ||
World Examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ constant.yaml | |
erase.yaml | ||
override.yaml | ||
coords.yaml | ||
reflect.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
version: 1 | ||
name: Reflection (imap) test | ||
description: | | ||
A world with both horizontal and vertical reflection symmetry, | ||
created with 'imap'. | ||
creative: false | ||
objectives: | ||
- goal: | ||
- Pick up four trees | ||
condition: | | ||
as base {n <- count "tree"; return (n >= 4)} | ||
robots: | ||
- name: base | ||
loc: [0, 0] | ||
dir: north | ||
devices: | ||
- logger | ||
- grabber | ||
- treads | ||
- branch predictor | ||
- scanner | ||
- ADT calculator | ||
- comparator | ||
- GPS receiver | ||
- bitcoin | ||
solution: | | ||
def x = \n. \c. if (n==0) {} {c; x (n-1) c} end | ||
def ifC = \p. \t. \e. b <- p; if b t e end | ||
def findTree = ifC (ishere "tree") {whereami} {move; findTree} end | ||
def ell = \d. turn right; x (2*d) move; grab; return () end | ||
def grabTrees = \loc. let x = fst loc in let y = snd loc in grab; ell y; ell x; ell y end | ||
n <- random 10; | ||
x (n+1) move; turn right; move; | ||
loc <- findTree; | ||
grabTrees loc | ||
known: [tree] | ||
world: | ||
dsl: | | ||
let trees = if (hash % 4 == 0) then {tree, dirt} else {stone} | ||
in | ||
overlay | ||
[ mask (x >= 0 && y >= 0) trees | ||
, mask (x >= 0 && y < 0) (imap x (-y) trees) | ||
, mask (x < 0 && y >= 0) (imap (-x) y trees) | ||
, mask (x < 0 && y < 0) (imap (-x) (-y) trees) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
clearing.yaml | ||
rorschach.yaml | ||
stretch.yaml | ||
translate.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: 1 | ||
name: Clearing | ||
description: | | ||
The base is in a clearing in the forest: the area within a certain | ||
radius of the base is completely clear of trees; then there are | ||
random trees at increasing density up to another radius; outside of | ||
the outer radius there are only trees. | ||
creative: true | ||
robots: | ||
- name: base | ||
display: | ||
char: Ω | ||
loc: [0, 0] | ||
dir: north | ||
world: | ||
dsl: | | ||
overlay | ||
[ {dirt} | ||
, mask ((x*x + 4*y*y) >= (6*6) && (x*x + 4*y*y) <= (30*30)) | ||
(let h = hash % 24 in if (36 + h*h) <= (x*x + 4*y*y) then {tree,dirt} else {dirt} ) | ||
, mask ((x*x + 4*y*y) > (30*30)) {tree, dirt} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version: 1 | ||
name: Rorschach | ||
description: | | ||
A world with both horizontal and vertical reflection symmetry, | ||
created with `imap`{=snippet}. | ||
creative: true | ||
robots: | ||
- name: base | ||
dir: north | ||
loc: [0, 0] | ||
known: [tree] | ||
world: | ||
dsl: | | ||
let trees = if (hash % 4 == 0) then {tree, dirt} else {stone} | ||
in | ||
overlay | ||
[ mask (x >= 0 && y >= 0) trees | ||
, mask (x >= 0 && y < 0) (imap x (-y) trees) | ||
, mask (x < 0 && y >= 0) (imap (-x) y trees) | ||
, mask (x < 0 && y < 0) (imap (-x) (-y) trees) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: 1 | ||
name: Stretch | ||
description: | | ||
A world created by stretching a random pattern of trees, with the | ||
amount of stretching determined by the distance from the origin. | ||
creative: true | ||
robots: | ||
- name: base | ||
dir: north | ||
loc: [0, 0] | ||
known: [tree] | ||
world: | ||
dsl: | | ||
let trees = if (hash % 4 == 0) then {tree, dirt} else {stone} | ||
in | ||
imap (if (y == 0) then 0 else (x/abs(y))) (if (abs x <= 1) then 0 else (y/abs(x/2))) trees |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
version: 1 | ||
name: Translate | ||
description: | | ||
An illustration of how to use `imap`{=snippet} to translate. A basic patch is | ||
created and then overlaid at various translations. Note that since | ||
`imap`{=snippet} works by mapping a function over the coordinates, translation | ||
is "backwards": for example, `imap (x+4)`{=snippet} translates 4 units to the | ||
*left*. | ||
creative: true | ||
robots: | ||
- name: base | ||
dir: north | ||
loc: [0, 0] | ||
known: [rock] | ||
world: | ||
dsl: | | ||
let patch = mask (abs(x) <= 4 && abs(y) <= 4) (if ((x + y) % 2 == 0) then {rock, dirt} else {dirt}) | ||
in | ||
overlay | ||
[ patch | ||
, imap (x+6) (y+3) patch | ||
, imap (x-10) (y-7) patch | ||
, imap (x-14) (y+5) patch | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were there no worlds using reflection and rotation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. Reflection wasn't even fully implemented, as it turns out. And rotation is not very interesting until you have things like structures you can refer to from within the language.