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

Add cotton, strings, and nets #658

Merged
merged 10 commits into from
Sep 4, 2022
43 changes: 43 additions & 0 deletions data/entities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,35 @@
properties: [portable, growable]
growth: [30, 50]

- name: cotton
display:
attr: silver
char: 'i'
description:
- A plant with tufts of soft fibers that can be harvested and used
to make things, including sheets of material that the local
aliens like to drape over their bodies.
properties: [portable, growable]
growth: [100, 800]

- name: string
display:
attr: silver
char: '~'
description:
- A long, flexible device for transferring either force or
information, made of twisted cotton fibers. Multiple strings can
also be woven into larger configurations such as cloth or nets.
- |
A string device enables two commands: the first, `format : a ->
text`, can turn any value into a suitable text representation.
The second is the infix operator `++ : text -> text -> text`
which can be used to concatenate two text values. For example,
- |
"Number of widgets: " ++ format numWidgets
properties: [portable]
capabilities: [text]

- name: lambda
display:
attr: flower
Expand Down Expand Up @@ -944,3 +973,17 @@

properties: [portable]
capabilities: [atomic]

- name: net
display:
attr: silver
char: '#'
description:
- A net is a device woven out of many strings. With a net
installed, you can use the `try` command to catch errors. For example,
- |
`try {move} {turn left}`
- will attempt to move, but if that fails, turn left instead.
properties: [portable]
capabilities: [try]

16 changes: 16 additions & 0 deletions data/recipes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -690,3 +690,19 @@
- [1, strange loop]
out:
- [1, rubber band]

#########################################
## COTTON ##
#########################################

- in:
- [4, cotton]
out:
- [1, string]
required:
- [1, small motor]

- in:
- [256, string]
out:
- [1, net]
8 changes: 7 additions & 1 deletion data/scenarios/Testing/508-capability-subset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ objectives:
} { return false }
solution: |
log "Hi, I can build teleporting robots!";
build {log "Hi, I can teleport!"; teleport self (5,0); p <- whereami; log $ "I am at " ++ format p}
try {
build {log "Hi, I can teleport!"; teleport self (5,0); p <- whereami; log $ "I am at " ++ format p}
} {
fail "Fatal error: BASE: I could not build my robot! What happened?!"
}
robots:
- name: base
loc: [0,0]
dir: [1,0]
devices:
- logger
- net
- 3D printer
inventory:
- [1, mirror]
- [1, string]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😉

- [1, GPS]
- [1, Tardis]
- [1, logger]
Expand Down
4 changes: 2 additions & 2 deletions data/scenarios/Tutorials/bind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ objectives:
- |
Other commands do return a nontrivial value after executing.
For example, `grab` has type
`cmd string`, and returns the name of the
grabbed entity as a string. Try it:
`cmd text`, and returns the name of the
grabbed entity as a text value. Try it:
- |
move; grab
- |
Expand Down
4 changes: 2 additions & 2 deletions data/scenarios/Tutorials/conditionals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ objectives:
to sweep over the entire 4x4 square and pick up a `very small
rock` any time you detect one.
- |
The `ishere` command, with type `string -> cmd bool`, can be used
The `ishere` command, with type `text -> cmd bool`, can be used
for detecting the presence of a specific item such as a `very small rock`.
What we need is a way to take the `bool` output from `ishere`
and use it to decide whether to `grab` a rock or not.
Expand Down Expand Up @@ -45,7 +45,7 @@ objectives:
- |
TIP: the two branches of an `if` must have the same type. In particular,
`if ... {grab} {}` is not
allowed, because `{grab}` has type `{cmd string}` whereas `{}` has type `{cmd ()}`.
allowed, because `{grab}` has type `{cmd text}` whereas `{}` has type `{cmd ()}`.
In this case `{grab; return ()}` has the right type.
condition: |
try {
Expand Down
2 changes: 1 addition & 1 deletion data/scenarios/Tutorials/crash-secret.sw
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end;

// Try to give a robot a Win, filtering out those that were already given a Win.
// The robot will also receive instructions, so it **must have a logger!**
def tryGive: string -> (robot -> bool) -> int -> cmd (robot -> bool) = \msg.\f.\i.
def tryGive: text -> (robot -> bool) -> int -> cmd (robot -> bool) = \msg.\f.\i.
r <- try {
robotNumbered i;
} {
Expand Down
6 changes: 3 additions & 3 deletions data/scenarios/Tutorials/farming.sw
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ end;
def while : cmd bool -> {cmd a} -> cmd () = \test. \body.
ifC test {force body ; while test body} {}
end;
def giveall : robot -> string -> cmd () = \r. \thing.
def giveall : robot -> text -> cmd () = \r. \thing.
while (has thing) {give r thing}
end;
def x4 = \c. c; c; c; c end;
def m4 = x4 move end;
def x12 = \c. x4 (c;c;c) end;
def m12 = x12 move end;
def next_row = tB; m12; tL; move; tL end;
def plant_field : string -> cmd () = \thing.
def plant_field : text -> cmd () = \thing.
log "planting";
x4 (
x12 (move; place thing; harvest);
next_row
)
end;
def harvest_field : string -> cmd () = \thing.
def harvest_field : text -> cmd () = \thing.
x4 (
x12 (move; ifC (ishere thing) {harvest; return ()} {});
next_row
Expand Down
2 changes: 1 addition & 1 deletion editors/emacs/swarm-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"west"
"down"
))
(x-types '("int" "string" "dir" "bool" "cmd"))
(x-types '("int" "text" "dir" "bool" "cmd"))

(x-keywords-regexp (regexp-opt x-keywords 'words))
(x-builtins-regexp (regexp-opt x-builtins 'words))
Expand Down
4 changes: 2 additions & 2 deletions src/Swarm/Game/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ import Swarm.Language.Capability (constCaps)
import Swarm.Language.Context qualified as Ctx
import Swarm.Language.Pipeline (ProcessedTerm)
import Swarm.Language.Pipeline.QQ (tmQ)
import Swarm.Language.Syntax (Const, Term (TString), allConst)
import Swarm.Language.Syntax (Const, Term (TText), allConst)
import Swarm.Language.Types
import Swarm.Util (getElemsInArea, isRightOr, manhattan, uniq, (<+=), (<<.=), (?))
import System.Clock qualified as Clock
Expand Down Expand Up @@ -567,7 +567,7 @@ viewingRegion :: GameState -> (Int64, Int64) -> (W.Coords, W.Coords)
viewingRegion g (w, h) = (W.Coords (rmin, cmin), W.Coords (rmax, cmax))
where
V2 cx cy = g ^. viewCenter
(rmin, rmax) = over both (+ (- cy - h `div` 2)) (0, h - 1)
(rmin, rmax) = over both (+ (-cy - h `div` 2)) (0, h - 1)
(cmin, cmax) = over both (+ (cx - w `div` 2)) (0, w - 1)

-- | Find out which robot has been last specified by the
Expand Down
Loading