mirror of
https://github.com/swarm-game/swarm.git
synced 2024-09-11 14:46:33 +03:00
check in some random examples
This commit is contained in:
parent
9f23dd0295
commit
6d2b678ff7
21
example/cat.sw
Normal file
21
example/cat.sw
Normal file
@ -0,0 +1,21 @@
|
||||
let forever : cmd () -> cmd () = \c. c ; forever c in
|
||||
let repeat : int -> cmd () -> cmd () =
|
||||
\n. \c. if (n == 0) {} {c ; repeat (n-1) c} in
|
||||
let randdir : cmd dir = {
|
||||
d <- random 4;
|
||||
return (
|
||||
if (d == 0) north
|
||||
(if (d == 1) east
|
||||
(if (d == 2) south west)))
|
||||
} in
|
||||
|
||||
forever {
|
||||
n <- random 20;
|
||||
repeat (10 + n) wait;
|
||||
d <- randdir;
|
||||
turn d;
|
||||
dist <- random 10;
|
||||
repeat dist move;
|
||||
r <- random 5;
|
||||
if (r == 0) { say "meow" } {}
|
||||
}
|
7
example/fact.sw
Normal file
7
example/fact.sw
Normal file
@ -0,0 +1,7 @@
|
||||
let repeat : int -> cmd () -> cmd () = \n.\c.
|
||||
if (n == 0) {} (c ; repeat (n-1) c)
|
||||
in let fact : int -> int = \n:int.
|
||||
if (n == 0)
|
||||
1
|
||||
(n * fact (n-1))
|
||||
in move; move; repeat (fact 4) move
|
7
example/rep.sw
Normal file
7
example/rep.sw
Normal file
@ -0,0 +1,7 @@
|
||||
let rep : int -> cmd () -> cmd () =
|
||||
\n.\c.
|
||||
if (n == 0)
|
||||
{}
|
||||
{c ; rep (n-1) c}
|
||||
in
|
||||
rep 10 move
|
12
example/square.sw
Normal file
12
example/square.sw
Normal file
@ -0,0 +1,12 @@
|
||||
let rep : int -> cmd () -> cmd () =
|
||||
\n.\c.
|
||||
if (n == 0)
|
||||
{}
|
||||
{c ; rep (n-1) c}
|
||||
in
|
||||
rep 4 {
|
||||
rep 10 move;
|
||||
turn left;
|
||||
build "sq" (run("square.sw"));
|
||||
return ()
|
||||
}
|
7
example/wander.sw
Normal file
7
example/wander.sw
Normal file
@ -0,0 +1,7 @@
|
||||
let forever : cmd () -> cmd () =
|
||||
\c. c ; forever c in
|
||||
forever {
|
||||
b <- random 2;
|
||||
turn (if (b == 0) left right);
|
||||
move
|
||||
}
|
17
example/zigzag.sw
Normal file
17
example/zigzag.sw
Normal file
@ -0,0 +1,17 @@
|
||||
let rep : int -> cmd () -> cmd () = \n. \c.
|
||||
if (n == 0)
|
||||
{}
|
||||
{ c; rep (n-1) c }
|
||||
in
|
||||
rep 50 {
|
||||
harvest; move;
|
||||
turn left;
|
||||
harvest; move;
|
||||
turn right;
|
||||
y <- getY;
|
||||
if (y >= 10) {
|
||||
turn right
|
||||
} {
|
||||
if (y <= 0) { turn left } {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user