Updated wumpus to use `fastrand` instead of `random`.
[vvhitespace] / examples / hunt-the-wumpus / wump_game.pvvs
CommitLineData
2da74194
AT
1#ifndef WUMP_GAME
2#define WUMP_GAME
3
4@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
5@ (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com>
6@ See LICENSE.txt file for copyright and license details.
7@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
8
9@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
10@ Name:
11@ get_tunnel_destination
12@ Description:
13@ Returns the room number corresponding to the destination of a tunnel
14@ specified by room and slot.
15@ Call Stack:
16@ slot
17@ room_number <-- TOS
18@ Return Stack:
19@ dst_room_number <-- TOS
20@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
21NSSVTSSSTSSSN | MARK: 10001000 (get_tunnel_destination)
22@ The pointer we seek is:
23@ (room_number * room_struct_size) + 2 + slot + ROOM_DATA_BASE
24@ Where the '+2' accounts for the pit and bat booleans.
25NSTTSSSTSTTN | JSR > 10001011 (get_room_struct_size)
26TSSN | MULTIPLY
27SSSTSN | PUSH +2
28TSSS | ADD
29TSSS | ADD
30SSSTSSSSSSSSSSSSSN | PUSH 0x2000 (ROOM_DATA_BASE address)
31TSSS | ADD
32TTT | LOAD
33NTN | RTS
34
35@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
36@ Name:
37@ get_room_struct_size
38@ Description:
39@ Returns the size in words of the data structure for a single room.
40@ For example, with 3 links plus bat and pit booleans, the size is 5 words.
41@ Call Stack:
42@ <empty>
43@ Return Stack:
44@ size <-- TOS
45@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
46NSSVTSSSTSTTN | MARK: 10001011 (get_room_struct_size)
47SSSTSSSSSSSSSSTTN | PUSH 0x1003 (GAME_DATA_BASE+3 = links_per_room address)
48TTT | LOAD
49SSSTSN | PUSH +2
50TSSS | ADD
51NTN | RTS
52
53@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
54@ Name:
55@ room_has_bats
56@ Description:
57@ Check if room_number contains bats.
58@ Returns 1 or 0 representing true or false.
59@ Call Stack:
60@ room_number <-- TOS
61@ Return Stack:
62@ 1 or 0 <-- TOS
63@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
64NSSVTSSSTTSSN | MARK: 10001100 (room_has_bats)
65@ We seek the pointer:
66@ (room_number * room_struct_size) + 1 + ROOM_DATA_BASE
67@ where '+1' accounts for the offset of the bat boolean in the desired room.
68NSTTSSSTSTTN | JSR > 10001011 (get_room_struct_size)
69TSSN | MULTIPLY
70SSSTN | PUSH +1
71TSSS | ADD
72SSSTSSSSSSSSSSSSSN | PUSH 0x2000 (GAME_DATA_BASE address)
73TSSS | ADD
74TTT | LOAD
75NTN | RTS
76
77@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
78@ Name:
79@ room_has_pits
80@ Description:
81@ Check if room_number contains pits.
82@ Returns 1 or 0 representing true or false.
83@ Call Stack:
84@ room_number <-- TOS
85@ Return Stack:
86@ 1 or 0 <-- TOS
87@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
88NSSVTSSSTTSTN | MARK: 10001101 (room_has_pits)
89@ We seek the pointer:
90@ (room_number * room_struct_size) + 0 + ROOM_DATA_BASE
91@ where '+0' accounts for the offset of the pit boolean in the desired room.
92NSTTSSSTSTTN | JSR > 10001011 (get_room_struct_size)
93TSSN | MULTIPLY
94SSSTSSSSSSSSSSSSSN | PUSH 0x2000 (GAME_DATA_BASE address)
95TSSS | ADD
96TTT | LOAD
97NTN | RTS
98
99@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
100@ Name:
101@ room_has_wumpus
102@ Description:
103@ Check if room contains wumpus.
104@ Returns 1 or 0 representing true or false.
105@ Call Stack:
106@ room_number <-- TOS
107@ Return Stack:
108@ 1 or 0 <-- TOS
109@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
110NSSVTSTSSSSSN | MARK: 10100000 (room_has_wumpus)
111SSSTSSSSSSSSSTTTN | PUSH 0x1007 (wumpus_location address)
112TTT | LOAD
113TSST | SUBTRACT
114NTSTSTSSSSSSSSSSSSSN | BRZ > 10100000 00000000 (room_has_wumpus:true)
115SSSSN | PUSH 0 (false)
116NTN | RTS
117NSSVTSTSSSSSSSSSSSSSN | MARK: 10100000 00000000 (room_has_wumpus:true)
118SSSTN | PUSH 1 (true)
119NTN | RTS
120
121@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
122@ Name:
123@ are_bats_near
124@ Description:
125@ Given a room number, checks rooms within one hop for bats.
126@ Returns 1 if bats are present or 0 if no bats.
127@ Call Stack:
128@ room_number <-- TOS
129@ Return Stack:
130@ 1 or 0 <-- TOS
131@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
132#include <stack.pvvs>
133NSSVTSSTTTSSN | MARK: 10011100 (are_bats_near)
134
135@ Prepare the stack by loading the number of links per room and decrementing.
136@ We will loop until this reaches 0 or we find bats.
137SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address)
138TTT | LOAD
139SSSTN | PUSH 1
140TSST | SUBTRACT
141
142@ Check one nearby room on each pass through this loop.
143@ TOS> tunnel_index, room_number
144NSSVTSSTTTSSSSSSSSSSN | MARK: 10011100 00000000 (are_bats_near:loop)
145SNS | DUP
146SSSTTN | PUSH 3
147NSTTTSSN | JSR > 1100 (deepdup)
148NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
149NSTTSSSTTSSN | JSR > 10001100 (room_has_bats)
150NTSTSSTTTSSSSSSSSSTN | BRZ > 10011100 00000001 (no_bats_in_this_room)
151@ Found bats. Clean up and return.
152SNN | DROP
153SNN | DROP
154SSSTN | PUSH 1
155NTN | RTS
156NSSVTSSTTTSSSSSSSSSTN | MARK: 10011100 00000001 (no_bats_in_this_room)
157@ Test for end of loop.
158SNS | DUP
159NTSTSSTTTSSSSSSSSTSN | BRZ > 10011100 00000010 (are_bats_near:loop_end)
160@ No bats found yet, but still need to check some rooms.
161@ Decrement tunnel index and loop again.
162SSSTN | PUSH 1
163TSST | SUBTRACT
164NSNTSSTTTSSSSSSSSSSN | JMP > 10011100 00000000 (are_bats_near:loop)
165@ No bats found in nearby rooms. Clean up and return.
166NSSVTSSTTTSSSSSSSSTSN | MARK: 10011100 00000010 (are_bats_near:loop_end)
167SNN | DROP
168SNN | DROP
169SSSSN | PUSH 0
170NTN | RTS
171
172@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
173@ Name:
174@ are_pits_near
175@ Description:
176@ Given a room number, checks rooms within one hop for pits.
177@ Returns 1 if pits are present or 0 if no pits.
178@ Call Stack:
179@ room_number <-- TOS
180@ Return Stack:
181@ 1 or 0 <-- TOS
182@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
183#include <stack.pvvs>
184NSSVTSSTTTSTN | MARK: 10011101 (are_pits_near)
185
186@ Prepare the stack by loading the number of links per room and decrementing.
187@ We will loop until this reaches 0 or we find pits.
188SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address)
189TTT | LOAD
190SSSTN | PUSH 1
191TSST | SUBTRACT
192
193@ Check one nearby room on each pass through this loop.
194@ TOS> tunnel_index, room_number
195NSSVTSSTTTSTSSSSSSSSN | MARK: 10011101 00000000 (are_pits_near:loop)
196SNS | DUP
197SSSTTN | PUSH 3
198NSTTTSSN | JSR > 1100 (deepdup)
199NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
200NSTTSSSTTSTN | JSR > 10001101 (room_has_pits)
201NTSTSSTTTSTSSSSSSSTN | BRZ > 10011101 00000001 (no_pits_in_this_room)
202@ Found pits. Clean up and return.
203SNN | DROP
204SNN | DROP
205SSSTN | PUSH 1
206NTN | RTS
207NSSVTSSTTTSTSSSSSSSTN | MARK: 10011101 00000001 (no_pits_in_this_room)
208@ Test for end of loop.
209SNS | DUP
210NTSTSSTTTSTSSSSSSTSN | BRZ > 10011101 00000010 (are_pits_near:loop_end)
211@ No pits found yet, but still need to check some rooms.
212@ Decrement tunnel index and loop again.
213SSSTN | PUSH 1
214TSST | SUBTRACT
215NSNTSSTTTSTSSSSSSSSN | JMP > 10011101 00000000 (are_pits_near:loop)
216@ No pits found in nearby rooms. Clean up and return.
217NSSVTSSTTTSTSSSSSSTSN | MARK: 10011101 00000010 (are_pits_near:loop_end)
218SNN | DROP
219SNN | DROP
220SSSSN | PUSH 0
221NTN | RTS
222
223@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
224@ Name:
225@ is_wumpus_very_near
226@ Description:
227@ Given a room number, checks rooms within one hop for the wumpus.
228@ Returns 1 if wumpus is present, otherwise 0.
229@ Call Stack:
230@ room_number <-- TOS
231@ Return Stack:
232@ 1 or 0 <-- TOS
233@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
234#include <stack.pvvs>
235NSSVTSSTTTTTN | MARK: 10011111 (is_wumpus_very_near)
236
237@ Prepare the stack by loading the number of links per room and decrementing.
238@ We will loop until this reaches 0 or we find the wumpus.
239SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address)
240TTT | LOAD
241SSSTN | PUSH 1
242TSST | SUBTRACT
243
244@ Check one nearby room on each pass through this loop.
245@ TOS> tunnel_index, room_number
246NSSVTSSTTTTTSSSSSSSSN | MARK: 10011111 00000000 (is_wumpus_very_near:loop)
247SNS | DUP
248SSSTTN | PUSH 3
249NSTTTSSN | JSR > 1100 (deepdup)
250NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
251NSTTSTSSSSSN | JSR > 10100000 (room_has_wumpus)
252NTSTSSTTTTTSSSSSSSTN | BRZ > 10011111 00000001 (no_wumpus_in_this_room)
253@ Found wumpus. Clean up and return.
254SNN | DROP
255SNN | DROP
256SSSTN | PUSH 1
257NTN | RTS
258NSSVTSSTTTTTSSSSSSSTN | MARK: 10011111 00000001 (no_wumpus_in_this_room)
259@ Test for end of loop.
260SNS | DUP
261NTSTSSTTTTTSSSSSSTSN | BRZ > 10011111 00000010 (is_wumpus_very_near:loop_end)
262@ No wumpus found yet, but still need to check some rooms.
263@ Decrement tunnel index and loop again.
264SSSTN | PUSH 1
265TSST | SUBTRACT
266NSNTSSTTTTTSSSSSSSSN | JMP > 10011111 00000000 (is_wumpus_very_near:loop)
267@ No wumpus found in nearby rooms. Clean up and return.
268NSSVTSSTTTTTSSSSSSTSN | MARK: 10011111 00000010 (is_wumpus_very_near:loop_end)
269SNN | DROP
270SNN | DROP
271SSSSN | PUSH 0
272NTN | RTS
273
274@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
275@ Name:
276@ is_wumpus_near
277@ Description:
278@ Given a room number, checks rooms within two hops for the wumpus.
279@ Returns 1 if wumpus is present, otherwise 0.
280@ Call Stack:
281@ room_number <-- TOS
282@ Return Stack:
283@ 1 or 0 <-- TOS
284@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
285#include <stack.pvvs>
286NSSVTSSTTTTSN | MARK: 10011110 (is_wumpus_near)
287
288@ Prepare the stack by loading the number of links per room and decrementing.
289@ We will loop until this reaches 0 or we find the wumpus.
290SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address)
291TTT | LOAD
292SSSTN | PUSH 1
293TSST | SUBTRACT
294
295@ Check one nearby room and its connecting rooms on each pass through this loop.
296@ TOS> tunnel_index, room_number
297NSSVTSSTTTTSSSSSSSSSN | MARK: 10011110 00000000 (is_wumpus_near:loop)
298SNS | DUP
299SSSTTN | PUSH 3
300NSTTTSSN | JSR > 1100 (deepdup)
301NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
302@ TOS> tunnel_endpoint, tunnel_index, room_number
303SNS | DUP
304NSTTSTSSSSSN | JSR > 10100000 (room_has_wumpus)
305SSSTN | PUSH 1
306TSST | SUBTRACT
307NTSTSSTTTTSSSSSSSTTN | BRZ > 10011110 00000011 (found_wumpus_one_hop)
308NSTTSSTTTTTN | JSR > 10011111 (is_wumpus_very_near)
309SSSTN | PUSH 1
310TSST | SUBTRACT
311NTSTSSTTTTSSSSSSTSSN | BRZ > 10011110 00000100 (found_wumpus_two_hops)
312@ Test for end of loop.
313SNS | DUP
314NTSTSSTTTTSSSSSSSTSN | BRZ > 10011110 00000010 (is_wumpus_near:loop_end)
315@ No wumpus found yet, but still need to check some rooms.
316@ Decrement tunnel index and loop again.
317SSSTN | PUSH 1
318TSST | SUBTRACT
319NSNTSSTTTTSSSSSSSSSN | JMP > 10011110 00000000 (is_wumpus_near:loop)
320
321@ No wumpus found in nearby rooms. Clean up and return.
322NSSVTSSTTTTSSSSSSSTSN | MARK: 10011110 00000010 (is_wumpus_near:loop_end)
323SNN | DROP
324SNN | DROP
325SSSSN | PUSH 0
326NTN | RTS
327
328@ Found wumpus. Clean up and return.
329NSSVTSSTTTTSSSSSSSTTN | MARK: 10011110 00000011 (found_wumpus_one_hop)
330SNN | DROP
331NSSVTSSTTTTSSSSSSTSSN | MARK: 10011110 00000100 (found_wumpus_two_hops)
332SNN | DROP
333SNN | DROP
334SSSTN | PUSH 1
335NTN | RTS
336
337#endif