capitalex a révisé ce gist . Aller à la révision
1 file changed, 279 insertions
maze-array-polyfill.nv(fichier créé)
@@ -0,0 +1,279 @@ | |||
1 | + | = |@math| $last |@math| $op $value * = | |
2 | + | |@math| $op $value $last | |
3 | + | = |@math| $last |@math| $op * $value = | |
4 | + | |@math| $op $last $value | |
5 | + | ||
6 | + | ||
7 | + | = |@ array| flush cells? |cells array direction| forwards? |forwards cells| $value = | |
8 | + | |backwards cells| $value | |
9 | + | ||
10 | + | = |@ array| flush cells? |cells array direction| forwards? |forwards cells| = | |
11 | + | |backwards cells| | |
12 | + | ||
13 | + | = |@ array| flush cells |cells array direction| forwards = | |
14 | + | |cells array direction| backwards | |
15 | + | ||
16 | + | = |@ array| flush cells? |cells array direction| backwards? |backwards cells| $value = | |
17 | + | |forwards cells| $value | |
18 | + | ||
19 | + | = |@ array| flush cells? |cells array direction| backwards? |backwards cells| = | |
20 | + | |forwards cells| | |
21 | + | ||
22 | + | = |@ array| flush cells |cells array direction| backwards = | |
23 | + | |cells array direction| forwards | |
24 | + | ||
25 | + | ||
26 | + | ||
27 | + | = |@ array| set cells index $value |@math| 0 |cells array direction| forwards? |forwards cells| $_ = | |
28 | + | |backwards cells| $value |@ array| flush cells | |
29 | + | ||
30 | + | = |@ array| set cells index $value? |@math| $iter |cells array direction| forwards? |forwards cells| $_ = | |
31 | + | |backwards cells| $_ |@math| subtract $iter 1 | |
32 | + | ||
33 | + | = |@ array| set cells index $value |@math| 0 |cells array direction| forwards? |forwards cells| = | |
34 | + | |backwards cells| $value |@ array| flush cells | |
35 | + | ||
36 | + | = |@ array| set cells index $value? |@math| $iter |cells array direction| forwards? |forwards cells| = | |
37 | + | |backwards cells| |@math| subtract $iter 1 | |
38 | + | ||
39 | + | = |@ array| set cells index $value |@math| 0 |cells array direction| backwards? |backwards cells| $_ = | |
40 | + | |forwards cells| $value |@ array| flush cells | |
41 | + | ||
42 | + | = |@ array| set cells index $value? |@math| $iter |cells array direction| backwards? |backwards cells| $_ = | |
43 | + | |forwards cells| $_ |@math| subtract $iter 1 | |
44 | + | ||
45 | + | = |@ array| set cells index $value |@math| 0 |cells array direction| backwards? |backwards cells| = | |
46 | + | |forwards cells| $value |@ array| flush cells | |
47 | + | ||
48 | + | = |@ array| set cells index $value? |@math| $iter |cells array direction| backwards? |backwards cells| = | |
49 | + | |forwards cells| |@math| subtract $iter 1 | |
50 | + | ||
51 | + | = |@ array| set cells index $value |@math| $iter = | |
52 | + | |@ array| flush cells | |
53 | + | ||
54 | + | = |@ array| set cells $index $value |cells array direction| forwards? = | |
55 | + | |@ array| set cells index $value | |
56 | + | |@math| $index | |
57 | + | |@math| protected system call stack | |
58 | + | ||
59 | + | = |@ array| set cells $index $value |cells array direction| backwards? |cells array length| $len? = | |
60 | + | |@ array| set cells index $value | |
61 | + | |@math| subtract $len $index | |
62 | + | |@math| subtract * 1 | |
63 | + | |@math| protected system call stack | |
64 | + | ||
65 | + | = |@ array| getting cells $index |@math| 0 |cells array direction| forwards? |forwards cells| $value = | |
66 | + | |@ array| flush cells |@ array| cells $index $value |backwards cells| $value | |
67 | + | ||
68 | + | = |@ array| getting cells $index |@math| $iter |cells array direction| forwards? |forwards cells| $value = | |
69 | + | |@ array| getting cells $index |backwards cells| $value |@math| subtract $iter 1 | |
70 | + | ||
71 | + | = |@ array| getting cells $index |@math| 0 |cells array direction| backwards? |backwards cells| $value = | |
72 | + | |@ array| flush cells |@ array| cells $index $value |forwards cells| $value | |
73 | + | ||
74 | + | = |@ array| getting cells $index |@math| $iter |cells array direction| backwards? |backwards cells| $value = | |
75 | + | |@ array| getting cells $index |forwards cells| $value |@math| subtract $iter 1 | |
76 | + | ||
77 | + | = |@ array| getting cells $index |@math| 0 |cells array direction| forwards? |forwards cells| = | |
78 | + | |@ array| flush cells |@ array| cells $index |backwards cells| | |
79 | + | ||
80 | + | = |@ array| getting cells $index |@math| $iter |cells array direction| forwards? |forwards cells| = | |
81 | + | |@ array| getting cells $index |backwards cells| |@math| subtract $iter 1 | |
82 | + | ||
83 | + | = |@ array| getting cells $index |@math| 0 |cells array direction| backwards? |backwards cells| = | |
84 | + | |@ array| flush cells |@ array| cells $index |forwards cells| | |
85 | + | ||
86 | + | = |@ array| getting cells $index |@math| $iter |cells array direction| backwards? |backwards cells| = | |
87 | + | |@ array| getting cells $index |forwards cells| |@math| subtract $iter 1 | |
88 | + | ||
89 | + | = |@ array| getting cells $index |@math| $iter = | |
90 | + | |@ array| flush cells | |
91 | + | ||
92 | + | = |@ array| get cells $index |cells array direction| forwards? = | |
93 | + | |@ array| getting cells $index | |
94 | + | |@math| $index | |
95 | + | |@math| protected system call stack | |
96 | + | ||
97 | + | = |@ array| get cells $index |cells array direction| backwards? |cells array length| $len? = | |
98 | + | |@ array| getting cells $index | |
99 | + | |@math| subtract $len $index | |
100 | + | |@math| subtract * 1 | |
101 | + | |@math| protected system call stack | |
102 | + | ||
103 | + | ||
104 | + | = |@ array| alloc cells array |@math| 0 = | |
105 | + | |forwards cells| | |
106 | + | |cells array direction| forwards | |
107 | + | ||
108 | + | = |@ array| alloc cells array |@math| $size = | |
109 | + | |forwards cells| |@math| subtract $size 1 |@ array| alloc cells array | |
110 | + | ||
111 | + | = |@ array| create cells $size = | |
112 | + | |@math| subtract $size 1 |@ array| alloc cells array | |
113 | + | |@math| protected system call stack | |
114 | + | |cells array length| $size | |
115 | + | ||
116 | + | ||
117 | + | = |@math| protected system call stack = | |
118 | + | ||
119 | + | = || set new pen color? |pen color| r $g $b |@math| $r = | |
120 | + | |pen color| $r $g $b | |
121 | + | ||
122 | + | = || set new pen color? |pen color| $r g $b |@math| $g = | |
123 | + | |pen color| $r $g $b | |
124 | + | ||
125 | + | = || set new pen color? |pen color|$r $g b |@math| $b = | |
126 | + | |pen color| $r $g $b | |
127 | + | ||
128 | + | = || set new pen color = | |
129 | + | ||
130 | + | = || next color |pen color| $r $g $b = | |
131 | + | |@math| random 50 255 |@math| random 50 255 |@math| random 100 255 | |
132 | + | || set new pen color |pen color| r g b | |
133 | + | ||
134 | + | = || jump |backtrack| $row $col = | |
135 | + | |matrix position| $row $col | |
136 | + | |@math| multiply $col 2 |@math| multiply $row 2 | |
137 | + | || jump pen x || jump pen y | |
138 | + | || next color | |
139 | + | = || jump |generate| = | |
140 | + | ||
141 | + | = || jump pen x |pen position| $oldx $y |@math| $x = | |
142 | + | |pen position| $x $y | |
143 | + | ||
144 | + | = || jump pen y |pen position| $x $oldy |@math| $y = | |
145 | + | |pen position| $x $y | |
146 | + | ||
147 | + | = || mark cell at |@math| $index = | |
148 | + | |@ array| set cells $index seen | |
149 | + | ||
150 | + | = || mark cell at? |location| $row $col = | |
151 | + | |@math| multiply $row 128 | |
152 | + | |@math| add $col * | |
153 | + | ||
154 | + | = || find neighbors |location| $row $col = | |
155 | + | || get free cell downwards |col| downwards $col |@math| add $row 1 | |
156 | + | || get free cell rightwards |row| rightwards $row |@math| add $col 1 | |
157 | + | || get free cell upwards |col| upwards $col |@math| add $row -1 | |
158 | + | || get free cell leftwards |row| leftwards $row |@math| add $col -1 | |
159 | + | ||
160 | + | = || get free cell $dir |col| $dir $col |@math| -1 = | |
161 | + | = || get free cell $dir |col| $dir $col |@math| 128 = | |
162 | + | = || get free cell $dir |row| $dir $row |@math| -1 = | |
163 | + | = || get free cell $dir |row| $dir $row |@math| 128 = | |
164 | + | ||
165 | + | = || get free cell $dir |col| $dir $col |@math| $row = | |
166 | + | |@math| multiply $row 128 | |
167 | + | |@math| add $col * | |
168 | + | || is $dir cell free |location| $row $col | |
169 | + | ||
170 | + | = || get free cell $dir |row| $dir $row |@math| $col = | |
171 | + | |@math| multiply $row 128 | |
172 | + | |@math| add $col * | |
173 | + | || is $dir cell free |location| $row $col | |
174 | + | ||
175 | + | = || is downwards cell free |@ array| cells $index |location| $row $col = | |
176 | + | |downwards cell| $row $col | |
177 | + | ||
178 | + | = || is rightwards cell free |@ array| cells $index |location| $row $col = | |
179 | + | |rightwards cell| $row $col | |
180 | + | ||
181 | + | = || is upwards cell free |@ array| cells $index |location| $row $col = | |
182 | + | |upwards cell| $row $col | |
183 | + | ||
184 | + | = || is leftwards cell free |@ array| cells $index |location| $row $col = | |
185 | + | |leftwards cell| $row $col | |
186 | + | ||
187 | + | = || is $dir cell free |@ array| cells $index $value |location| $row $col = | |
188 | + | ||
189 | + | = || is $dir cell free? |@math| $index = | |
190 | + | |@ array| get cells $index | |
191 | + | ||
192 | + | ||
193 | + | = || go in direction |@math| 1 |upwards cell| $row $col = | |
194 | + | |matrix position| $row $col | |
195 | + | || mark cell at |location| $row $col | |
196 | + | || move up | |
197 | + | || move up | |
198 | + | || clear navigation state | |
199 | + | ||
200 | + | = || go in direction |@math| 2 |rightwards cell| $row $col = | |
201 | + | |matrix position| $row $col | |
202 | + | || mark cell at |location| $row $col | |
203 | + | || move right | |
204 | + | || move right | |
205 | + | || clear navigation state | |
206 | + | ||
207 | + | ||
208 | + | = || go in direction |@math| 3 |downwards cell| $row $col = | |
209 | + | |matrix position| $row $col | |
210 | + | || mark cell at |location| $row $col | |
211 | + | || move down | |
212 | + | || move down | |
213 | + | || clear navigation state | |
214 | + | ||
215 | + | ||
216 | + | = || go in direction |@math| 4 |leftwards cell| $row $col = | |
217 | + | |matrix position| $row $col | |
218 | + | || mark cell at |location| $row $col | |
219 | + | || move left | |
220 | + | || move left | |
221 | + | || clear navigation state | |
222 | + | ||
223 | + | ||
224 | + | = || go in direction? |@math| 1 |sweep|= | |
225 | + | |@math| 2 | |
226 | + | = || go in direction? |@math| 2 |sweep|= | |
227 | + | |@math| 3 | |
228 | + | = || go in direction? |@math| 3 |sweep|= | |
229 | + | |@math| 4 | |
230 | + | = || go in direction? |@math| 4 |sweep|= | |
231 | + | |@math| 1 | |
232 | + | ||
233 | + | = || go in direction |@math| $n = | |
234 | + | || clear navigation state || jump | |
235 | + | ||
236 | + | = || clear navigation state |upwards cell| $r $c = | |
237 | + | || push location to backtrack stack | |
238 | + | || clear navigation state | |
239 | + | ||
240 | + | = || clear navigation state |rightwards cell| $r $c = | |
241 | + | || push location to backtrack stack | |
242 | + | || clear navigation state | |
243 | + | ||
244 | + | = || clear navigation state |downwards cell| $r $c = | |
245 | + | || push location to backtrack stack | |
246 | + | || clear navigation state | |
247 | + | ||
248 | + | = || clear navigation state |leftwards cell| $r $c = | |
249 | + | || push location to backtrack stack | |
250 | + | || clear navigation state | |
251 | + | ||
252 | + | = || clear navigation state? |sweep| = | |
253 | + | ||
254 | + | = || clear navigation state? |location| $row $col = | |
255 | + | ||
256 | + | = || clear navigation state = | |
257 | + | ||
258 | + | = || push location to backtrack stack |location| $row $col = | |
259 | + | |backtrack| $row $col | |
260 | + | ||
261 | + | = || push location to backtrack stack = | |
262 | + | ||
263 | + | = || pick a random direction |matrix position| $row $col = | |
264 | + | |@math| random 1 5 | |
265 | + | || find neighbors |location| $row $col | |
266 | + | || go in direction |location| $row $col |sweep| |sweep| |sweep| | |
267 | + | ||
268 | + | = || update |generate|? = | |
269 | + | || pick a random direction | |
270 | + | |@graphics| draw-fps | |
271 | + | ||
272 | + | == | |
273 | + | |@ array| create cells 16384 | |
274 | + | |matrix position| 64 64 |screen resolution| 256 256 | |
275 | + | |pen position| 128 128 | |
276 | + | || pen brush pencil | |
277 | + | || pen down | |
278 | + | || pen color 255 64 128 | |
279 | + | |generate| |
Plus récent
Plus ancien