Beginnings of an implementation of Hunt the Wumpus in Robin.
Cat's Eye Technologies
13 years ago
0 | (robin (0 . 1) (small (0 . 1) | |
1 | list (0 . 1) | |
2 | concurrency (0 . 1) | |
3 | arith (0 . 1) | |
4 | random (0 . 1) | |
5 | crude-io (0 . 1) | |
6 | term (0 . 1)) | |
7 | ;''Beginnings of an implementation of Hunt the Wumpus.'' | |
8 | (let | |
9 | ( | |
10 | (caverns (literal ( | |
11 | ( 0 0 0) ;(to make it 1 based) | |
12 | ( 2 5 8) | |
13 | ( 1 3 10) | |
14 | ( 2 4 12) | |
15 | ( 3 5 14) | |
16 | ( 1 4 6) | |
17 | ( 5 7 15) | |
18 | ( 6 8 17) | |
19 | ( 1 7 9) | |
20 | ( 8 10 18) | |
21 | ( 2 9 11) | |
22 | (10 12 19) | |
23 | ( 3 11 13) | |
24 | (12 14 20) | |
25 | ( 4 13 15) | |
26 | ( 6 4 16) | |
27 | (15 17 20) | |
28 | ( 7 16 18) | |
29 | ( 9 17 19) | |
30 | (11 18 20) | |
31 | (13 16 19) | |
32 | ))) | |
33 | (get-random-room (fun () (call random range (list 1 20) value value))) | |
34 | (initial-room (get-random-room)) | |
35 | (initial-wumpus (get-random-room)) | |
36 | (initial-bats (list (get-random-room) (get-random-room))) | |
37 | (initial-pits (list (get-random-room) (get-random-room))) | |
38 | (initial-arrows 5) | |
39 | (main (fun (self room wumpus bats pits arrows) | |
40 | (let | |
41 | ( | |
42 | (tunnels (index room caverns)) | |
43 | (message (subst-many (list (pair (literal r) room) | |
44 | (pair (literal a) arrows) | |
45 | (pair (literal t) tunnels)) | |
46 | (literal ((you are in room r with a arrows) | |
47 | (tunnels lead to rooms t))))) | |
48 | (unrecognized-command (fun () | |
49 | (call crude-output write | |
50 | (literal ((unrecognized command) | |
51 | (try (m room) or (s room1 room2 etc)))) result | |
52 | (self self room wumpus bats pits arrows)))) | |
53 | ) | |
54 | (call crude-output write message result | |
55 | (choose | |
56 | ((elem? room bats) | |
57 | (call crude-output write | |
58 | (literal (super bat snatch elsewheresville for you)) result | |
59 | (self self (get-random-room) wumpus bats pits arrows))) | |
60 | ((elem? room pits) | |
61 | (call crude-output write | |
62 | (literal (yiiieeeee fell in a bottomless pit)) result | |
63 | result)) | |
64 | ((equal? room pits) | |
65 | (call crude-output write | |
66 | (literal (you stumbled upon the wumpus who ate you up)) result | |
67 | result)) | |
68 | (else | |
69 | (recv entered | |
70 | (choose | |
71 | ((equal? entered (literal eof)) | |
72 | (call crude-output write | |
73 | (literal (gave up eh? no wumpus for you)) result result)) | |
74 | ((list? entered) | |
75 | (if (equal? (head entered) (literal m)) | |
76 | (bind dest (head (tail entered)) | |
77 | (if (elem? dest tunnels) | |
78 | (self self dest wumpus bats pits arrows) | |
79 | (call crude-output write | |
80 | (literal (no tunnel in that direction)) result | |
81 | (self self room wumpus bats pits arrows)))) | |
82 | (unrecognized-command))) | |
83 | (else | |
84 | (unrecognized-command)))))))))) | |
85 | ) | |
86 | (call crude-input subscribe () x | |
87 | (main main initial-room initial-wumpus initial-bats | |
88 | initial-pits initial-arrows)))) |