-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #306. Closes #931. - Renamed `robot` type to `actor` in anticipation of meeting other things besides robots. - `meet : cmd (unit + actor)` returns an arbitrary actor within Manhattan distance 1, if any. - `meetAll : (b -> actor -> cmd b) -> b -> cmd b` will run on every nearby actor. - Added `antenna` device to provide the commands. - Added "make a friend" challenge that requires the use of `meet`.
- Loading branch information
Showing
22 changed files
with
388 additions
and
57 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ teleport.yaml | |
2048.yaml | ||
hanoi.yaml | ||
bucket-brigade.yaml | ||
friend.yaml | ||
Mazes | ||
Ranching |
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,75 @@ | ||
def forever : cmd unit -> cmd unit = \c. c ; forever c end | ||
|
||
def repeat : int -> cmd unit -> cmd unit = | ||
\n. \c. if (n == 0) {} {c ; repeat (n-1) c} | ||
end | ||
|
||
def elif = \t. \then. \else. {if t then else} end | ||
def else = \t. t end | ||
|
||
def abs = \n. if (n < 0) {-n} {n} end | ||
|
||
def randdir : cmd dir = | ||
d <- random 4; | ||
return ( | ||
if (d == 0) {north} | ||
$ elif (d == 1) {east} | ||
$ elif (d == 2) {south} | ||
$ else {west} | ||
) | ||
end | ||
|
||
def chooseWait : cmd int = | ||
t <- random (16*2); | ||
return (16 + t) | ||
end | ||
|
||
def wander = | ||
d <- randdir; | ||
turn d; | ||
dist <- random 2; | ||
try {repeat dist move} {}; | ||
r <- random 5; | ||
if (r == 0) { say "meow" } {} | ||
end | ||
|
||
def disappointed = \cat. say "meow??"; cat end | ||
|
||
def follow : cmd unit -> actor -> cmd unit = \cat. \r. | ||
rLoc <- as r {whereami}; | ||
myLoc <- whereami; | ||
let dx = fst rLoc - fst myLoc in | ||
let dy = snd rLoc - snd myLoc in | ||
if (abs dx > abs dy) | ||
{ if (dx < 0) {turn west} {turn east} } | ||
{ if (dy < 0) {turn south} {turn north} }; | ||
if (abs dx != 0 || abs dy != 0) {try { move } { disappointed cat }} {}; | ||
wait 4; | ||
follow cat r | ||
end | ||
|
||
def love = \cat. | ||
say "purr"; | ||
fishGiver <- meet; | ||
case fishGiver | ||
(\_. disappointed cat) | ||
(\r. follow cat r) | ||
end | ||
|
||
def cat = \start. \fishCount. \waitTime. | ||
if (waitTime == 0) { wander; start } { wait 1 }; | ||
n <- count "fish"; | ||
if (n > fishCount) | ||
{ say "yum!"; | ||
if (n >= 3) { love start } { cat start n (waitTime - 1) } | ||
} | ||
{ cat start fishCount (waitTime - 1) } | ||
end | ||
|
||
def startCat = | ||
n <- count "fish"; | ||
w <- chooseWait; | ||
cat startCat n w | ||
end; | ||
|
||
startCat |
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,18 @@ | ||
def m2 = move; move end | ||
def m5 = m2; m2; move end | ||
def m10 = m5; m5 end | ||
def m20 = m10; m10 end | ||
|
||
def give_fish = \n. | ||
if (n == 0) {} | ||
{ mcat <- meet; | ||
case mcat (\_. give_fish n) (\cat. give cat "fish"; give_fish (n-1)) | ||
} | ||
end; | ||
|
||
build { | ||
require 3 "fish"; | ||
m2; turn left; m20; | ||
give_fish 3; | ||
turn back; m20; turn right; m2 | ||
} |
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,94 @@ | ||
version: 1 | ||
name: Make a Friend | ||
author: Brent Yorgey | ||
description: | | ||
Win the trust of a furry companion. | ||
creative: false | ||
robots: | ||
- name: base | ||
display: | ||
char: 'Ω' | ||
attr: robot | ||
heavy: true | ||
dir: [0, 1] | ||
devices: | ||
- 3D printer | ||
- ADT calculator | ||
- antenna | ||
- branch predictor | ||
- clock | ||
- comparator | ||
- counter | ||
- dictionary | ||
- grabber | ||
- hearing aid | ||
- lambda | ||
- logger | ||
- mirror | ||
- net | ||
- scanner | ||
- strange loop | ||
- string | ||
- toolkit | ||
- workbench | ||
inventory: | ||
- [10, ADT calculator] | ||
- [10, antenna] | ||
- [10, treads] | ||
- [10, branch predictor] | ||
- [10, fish] | ||
- [10, solar panel] | ||
- [10, grabber] | ||
- [10, lambda] | ||
- [10, strange loop] | ||
- [10, logger] | ||
- [10, clock] | ||
- [10, comparator] | ||
- [10, calculator] | ||
- name: cat | ||
system: true | ||
dir: [-1, 0] | ||
display: | ||
invisible: false | ||
char: 'c' | ||
attr: sand | ||
devices: | ||
- logger | ||
program: | | ||
run "scenarios/Challenges/_friend/cat.sw" | ||
objectives: | ||
- goal: | ||
- There's a cat wandering around in the field. Bring it back to | ||
your base. If you give it something it likes, perhaps you can | ||
get it to follow you. | ||
condition: | | ||
c <- robotNamed "cat"; | ||
catLoc <- as c {whereami}; | ||
baseLoc <- as base {whereami}; | ||
return (catLoc == baseLoc) | ||
solution: | | ||
run "scenarios/Challenges/_friend/friend-solution.sw" | ||
entities: | ||
- name: fish | ||
display: | ||
char: 'f' | ||
description: | ||
- A smelly fish. Rather unappetizing to a robot. | ||
properties: [known, portable] | ||
|
||
known: [fish] | ||
seed: 0 | ||
world: | ||
offset: true | ||
palette: | ||
'Ω': [grass, null, base] | ||
'.': [stone] | ||
',': [grass] | ||
'c': [grass, null, cat] | ||
'*': [grass, flower] | ||
'@': [stone, boulder] | ||
upperleft: [-20, 2] | ||
map: |- | ||
c,..,,,,,,..,,,,...,. | ||
,..,,,,,,,........... | ||
*,.,@,,,,,,,.....,..Ω |
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
699-movement-fail | ||
858-inventory | ||
710-multi-robot.yaml | ||
920-meet.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,52 @@ | ||
version: 1 | ||
name: Test meet and meetAll commands | ||
description: | | ||
Make sure meet prefers a robot on the same cell, and test meetAll | ||
by giving everyone a boat. | ||
objectives: | ||
- condition: | | ||
r0 <- robotNamed "other0"; | ||
b0 <- as r0 { has "boat" }; | ||
teleport self (0,0); | ||
b1 <- meetAll (\b. \r. b0 <- as r {has "boat"}; return (b && b0)) true; | ||
n2 <- as r0 { count "boat" }; | ||
return (b0 && b1 && (n2 == 2)) | ||
solution: | | ||
mr0 <- meet; | ||
case mr0 (\_. return ()) (\r0. give r0 "boat"); | ||
meetAll (\_. \r. give r "boat") () | ||
robots: | ||
- name: base | ||
loc: [0,0] | ||
dir: [1,0] | ||
devices: | ||
- logger | ||
- antenna | ||
- ADT calculator | ||
- grabber | ||
inventory: | ||
- [7, boat] | ||
- name: other0 | ||
loc: [0,0] | ||
dir: [1,0] | ||
- name: other | ||
dir: [1,0] | ||
world: | ||
default: [blank] | ||
palette: | ||
'.': [grass] | ||
'Ω': [grass, null] | ||
'o': [grass, null, other] | ||
'┌': [stone, upper left corner] | ||
'┐': [stone, upper right corner] | ||
'└': [stone, lower left corner] | ||
'┘': [stone, lower right corner] | ||
'─': [stone, horizontal wall] | ||
'│': [stone, vertical wall] | ||
upperleft: [-2, 2] | ||
map: | | ||
┌───┐ | ||
│.o.│ | ||
│oΩo│ | ||
│.o.│ | ||
└───┘ |
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.