derp.comp.js
· 8.9 KiB · JavaScript
Surowy
Playground
return function() {
let min = Math.min; var max = Math.max; var huge = Number.MAX_SAFE_INTEGER;
let self = { state: { strings: [], slots: {} } };
self.counters = {
"loop": 1,
}
function match(self, counters) {
console.log(Object.entries(counters).filter(([,v])=>v>0).map(([k,v]) => `${k} :: ${v}`).join('\n') );
console.log(self.state.strings);
console.log(self.state.slots);
if (counters["push string"] > 0) {
self.state.strings.push(self.string_constants[counters["push string"]-1]);
counters["push string"] = 0;
return true;
}
if (counters["dx"] > 0 && counters["-dx"] > 0) {
let acc = huge;
acc = min(acc, counters["dx"] || 0);
acc = min(acc, counters["-dx"] || 0);
counters["dx"] = max((counters["dx"] || 0) - acc, 0);
counters["-dx"] = max((counters["-dx"] || 0) - acc, 0);
return true;
}
if (counters["dy"] > 0 && counters["-dy"] > 0) {
let acc = huge;
acc = min(acc, counters["dy"] || 0);
acc = min(acc, counters["-dy"] || 0);
counters["dy"] = max((counters["dy"] || 0) - acc, 0);
counters["-dy"] = max((counters["-dy"] || 0) - acc, 0);
return true;
}
if (counters["get dy"] > 0 && counters["W pressed"] > 0) {
let acc = huge;
acc = min(acc, counters["get dy"] || 0);
acc = min(acc, counters["W pressed"] || 0);
counters["get dy"] = max((counters["get dy"] || 0) - acc, 0);
counters["W pressed"] = max((counters["W pressed"] || 0) - acc, 0);
counters["-dy"] = (counters["-dy"] || 0) + acc * 1;
counters["get dy"] = (counters["get dy"] || 0) + acc * 1;
return true;
}
if (counters["get dy"] > 0 && counters["S pressed"] > 0) {
let acc = huge;
acc = min(acc, counters["get dy"] || 0);
acc = min(acc, counters["S pressed"] || 0);
counters["get dy"] = max((counters["get dy"] || 0) - acc, 0);
counters["S pressed"] = max((counters["S pressed"] || 0) - acc, 0);
counters["dy"] = (counters["dy"] || 0) + acc * 1;
return true;
}
if (counters["get dx"] > 0 && counters["A pressed"] > 0) {
let acc = huge;
acc = min(acc, counters["get dx"] || 0);
acc = min(acc, counters["A pressed"] || 0);
counters["get dx"] = max((counters["get dx"] || 0) - acc, 0);
counters["A pressed"] = max((counters["A pressed"] || 0) - acc, 0);
counters["-dx"] = (counters["-dx"] || 0) + acc * 1;
counters["get dx"] = (counters["get dx"] || 0) + acc * 1;
return true;
}
if (counters["get dx"] > 0 && counters["D pressed"] > 0) {
let acc = huge;
acc = min(acc, counters["get dx"] || 0);
acc = min(acc, counters["D pressed"] || 0);
counters["get dx"] = max((counters["get dx"] || 0) - acc, 0);
counters["D pressed"] = max((counters["D pressed"] || 0) - acc, 0);
counters["dx"] = (counters["dx"] || 0) + acc * 1;
return true;
}
if (counters["loop"] > 0) {
let acc = counters["loop"] || 0;
counters["loop"] = max((counters["loop"] || 0) - acc, 0);
counters["input"] = (counters["input"] || 0) + acc * 1;
counters["player"] = (counters["player"] || 0) + acc * 1;
counters["enemies"] = (counters["enemies"] || 0) + acc * 1;
counters["cull"] = (counters["cull"] || 0) + acc * 1;
counters["re-loop"] = (counters["re-loop"] || 0) + acc * 1;
return true;
}
if (counters["input"] > 0) {
let acc = counters["input"] || 0;
counters["input"] = max((counters["input"] || 0) - acc, 0);
counters["poll"] = (counters["poll"] || 0) + acc * 1;
return true;
}
if (counters["player"] > 0) {
let acc = counters["player"] || 0;
counters["player"] = max((counters["player"] || 0) - acc, 0);
counters["get dx:max"] = (counters["get dx:max"] || 0) + acc * 1;
counters["get dy:max"] = (counters["get dy:max"] || 0) + acc * 1;
return true;
}
if (counters["update enemy"] > 0) {
let acc = counters["update enemy"] || 0;
counters["update enemy"] = max((counters["update enemy"] || 0) - acc, 0);
counters["track player"] = (counters["track player"] || 0) + acc * 1;
return true;
}
if (counters["enemies"] > 0 && counters["last enemy"] > 0) {
let acc = huge;
acc = min(acc, counters["enemies"] || 0);
acc = min(acc, counters["last enemy"] || 0);
counters["enemies"] = max((counters["enemies"] || 0) - acc, 0);
counters["last enemy"] = max((counters["last enemy"] || 0) - acc, 0);
return true;
}
if (counters["enemies"] > 0) {
let acc = counters["enemies"] || 0;
counters["enemies"] = max((counters["enemies"] || 0) - acc, 0);
counters["update enemy"] = (counters["update enemy"] || 0) + acc * 1;
counters["next enemy"] = (counters["next enemy"] || 0) + acc * 1;
return true;
}
if (counters["cull"] > 0) {
let acc = counters["cull"] || 0;
counters["cull"] = max((counters["cull"] || 0) - acc, 0);
counters["remove dead enemies"] = (counters["remove dead enemies"] || 0) + acc * 1;
return true;
}
if (counters["re-loop"] > 0) {
let acc = counters["re-loop"] || 0;
counters["re-loop"] = max((counters["re-loop"] || 0) - acc, 0);
counters["loop"] = (counters["loop"] || 0) + acc * 1;
return true;
}
if (counters["get dy"] > 0 && counters["W pressed"] > 0) {
let acc = huge;
acc = min(acc, counters["get dy"] || 0);
acc = min(acc, counters["W pressed"] || 0);
counters["get dy"] = max((counters["get dy"] || 0) - acc, 0);
counters["W pressed"] = max((counters["W pressed"] || 0) - acc, 0);
counters["-dy"] = (counters["-dy"] || 0) + acc * 1;
counters["get dy"] = (counters["get dy"] || 0) + acc * 1;
return true;
}
if (counters["get dy"] > 0 && counters["S pressed"] > 0) {
let acc = huge;
acc = min(acc, counters["get dy"] || 0);
acc = min(acc, counters["S pressed"] || 0);
counters["get dy"] = max((counters["get dy"] || 0) - acc, 0);
counters["S pressed"] = max((counters["S pressed"] || 0) - acc, 0);
counters["dy"] = (counters["dy"] || 0) + acc * 1;
return true;
}
if (counters["get dx"] > 0 && counters["A pressed"] > 0) {
let acc = huge;
acc = min(acc, counters["get dx"] || 0);
acc = min(acc, counters["A pressed"] || 0);
counters["get dx"] = max((counters["get dx"] || 0) - acc, 0);
counters["A pressed"] = max((counters["A pressed"] || 0) - acc, 0);
counters["-dx"] = (counters["-dx"] || 0) + acc * 1;
counters["get dx"] = (counters["get dx"] || 0) + acc * 1;
return true;
}
if (counters["get dx"] > 0 && counters["D pressed"] > 0) {
let acc = huge;
acc = min(acc, counters["get dx"] || 0);
acc = min(acc, counters["D pressed"] || 0);
counters["get dx"] = max((counters["get dx"] || 0) - acc, 0);
counters["D pressed"] = max((counters["D pressed"] || 0) - acc, 0);
counters["dx"] = (counters["dx"] || 0) + acc * 1;
return true;
}
if (counters["loop"] > 0) {
let acc = counters["loop"] || 0;
counters["loop"] = max((counters["loop"] || 0) - acc, 0);
counters["input"] = (counters["input"] || 0) + acc * 1;
counters["player"] = (counters["player"] || 0) + acc * 1;
counters["enemies"] = (counters["enemies"] || 0) + acc * 1;
counters["cull"] = (counters["cull"] || 0) + acc * 1;
counters["re-loop"] = (counters["re-loop"] || 0) + acc * 1;
return true;
}
if (counters["input"] > 0) {
let acc = counters["input"] || 0;
counters["input"] = max((counters["input"] || 0) - acc, 0);
counters["poll"] = (counters["poll"] || 0) + acc * 1;
return true;
}
if (counters["player"] > 0) {
let acc = counters["player"] || 0;
counters["player"] = max((counters["player"] || 0) - acc, 0);
counters["get dx:max"] = (counters["get dx:max"] || 0) + acc * 1;
counters["get dy:max"] = (counters["get dy:max"] || 0) + acc * 1;
return true;
}
if (counters["update enemy"] > 0) {
let acc = counters["update enemy"] || 0;
counters["update enemy"] = max((counters["update enemy"] || 0) - acc, 0);
counters["track player"] = (counters["track player"] || 0) + acc * 1;
return true;
}
if (counters["enemies"] > 0 && counters["last enemy"] > 0) {
let acc = huge;
acc = min(acc, counters["enemies"] || 0);
acc = min(acc, counters["last enemy"] || 0);
counters["enemies"] = max((counters["enemies"] || 0) - acc, 0);
counters["last enemy"] = max((counters["last enemy"] || 0) - acc, 0);
return true;
}
if (counters["enemies"] > 0) {
let acc = counters["enemies"] || 0;
counters["enemies"] = max((counters["enemies"] || 0) - acc, 0);
counters["update enemy"] = (counters["update enemy"] || 0) + acc * 1;
counters["next enemy"] = (counters["next enemy"] || 0) + acc * 1;
return true;
}
if (counters["cull"] > 0) {
let acc = counters["cull"] || 0;
counters["cull"] = max((counters["cull"] || 0) - acc, 0);
counters["remove dead enemies"] = (counters["remove dead enemies"] || 0) + acc * 1;
return true;
}
if (counters["re-loop"] > 0) {
let acc = counters["re-loop"] || 0;
counters["re-loop"] = max((counters["re-loop"] || 0) - acc, 0);
counters["loop"] = (counters["loop"] || 0) + acc * 1;
return true;
}
return false;
}
self.run = function() {
let counters = self.counters;
while(match(self, counters)){};
};
self.log_state = function() {
return Object.entries(self.counters).map(([k, v]) => `${k} :: ${v}`).join('\n');
}; return self;
};
1 | return function() { |
2 | let min = Math.min; var max = Math.max; var huge = Number.MAX_SAFE_INTEGER; |
3 | let self = { state: { strings: [], slots: {} } }; |
4 | |
5 | |
6 | self.counters = { |
7 | "loop": 1, |
8 | } |
9 | |
10 | function match(self, counters) { |
11 | |
12 | console.log(Object.entries(counters).filter(([,v])=>v>0).map(([k,v]) => `${k} :: ${v}`).join('\n') ); |
13 | console.log(self.state.strings); |
14 | console.log(self.state.slots); |
15 | if (counters["push string"] > 0) { |
16 | self.state.strings.push(self.string_constants[counters["push string"]-1]); |
17 | counters["push string"] = 0; |
18 | return true; |
19 | } |
20 | |
21 | if (counters["dx"] > 0 && counters["-dx"] > 0) { |
22 | let acc = huge; |
23 | acc = min(acc, counters["dx"] || 0); |
24 | acc = min(acc, counters["-dx"] || 0); |
25 | counters["dx"] = max((counters["dx"] || 0) - acc, 0); |
26 | counters["-dx"] = max((counters["-dx"] || 0) - acc, 0); |
27 | return true; |
28 | } |
29 | if (counters["dy"] > 0 && counters["-dy"] > 0) { |
30 | let acc = huge; |
31 | acc = min(acc, counters["dy"] || 0); |
32 | acc = min(acc, counters["-dy"] || 0); |
33 | counters["dy"] = max((counters["dy"] || 0) - acc, 0); |
34 | counters["-dy"] = max((counters["-dy"] || 0) - acc, 0); |
35 | return true; |
36 | } |
37 | if (counters["get dy"] > 0 && counters["W pressed"] > 0) { |
38 | let acc = huge; |
39 | acc = min(acc, counters["get dy"] || 0); |
40 | acc = min(acc, counters["W pressed"] || 0); |
41 | counters["get dy"] = max((counters["get dy"] || 0) - acc, 0); |
42 | counters["W pressed"] = max((counters["W pressed"] || 0) - acc, 0); |
43 | counters["-dy"] = (counters["-dy"] || 0) + acc * 1; |
44 | counters["get dy"] = (counters["get dy"] || 0) + acc * 1; |
45 | return true; |
46 | } |
47 | if (counters["get dy"] > 0 && counters["S pressed"] > 0) { |
48 | let acc = huge; |
49 | acc = min(acc, counters["get dy"] || 0); |
50 | acc = min(acc, counters["S pressed"] || 0); |
51 | counters["get dy"] = max((counters["get dy"] || 0) - acc, 0); |
52 | counters["S pressed"] = max((counters["S pressed"] || 0) - acc, 0); |
53 | counters["dy"] = (counters["dy"] || 0) + acc * 1; |
54 | return true; |
55 | } |
56 | if (counters["get dx"] > 0 && counters["A pressed"] > 0) { |
57 | let acc = huge; |
58 | acc = min(acc, counters["get dx"] || 0); |
59 | acc = min(acc, counters["A pressed"] || 0); |
60 | counters["get dx"] = max((counters["get dx"] || 0) - acc, 0); |
61 | counters["A pressed"] = max((counters["A pressed"] || 0) - acc, 0); |
62 | counters["-dx"] = (counters["-dx"] || 0) + acc * 1; |
63 | counters["get dx"] = (counters["get dx"] || 0) + acc * 1; |
64 | return true; |
65 | } |
66 | if (counters["get dx"] > 0 && counters["D pressed"] > 0) { |
67 | let acc = huge; |
68 | acc = min(acc, counters["get dx"] || 0); |
69 | acc = min(acc, counters["D pressed"] || 0); |
70 | counters["get dx"] = max((counters["get dx"] || 0) - acc, 0); |
71 | counters["D pressed"] = max((counters["D pressed"] || 0) - acc, 0); |
72 | counters["dx"] = (counters["dx"] || 0) + acc * 1; |
73 | return true; |
74 | } |
75 | if (counters["loop"] > 0) { |
76 | let acc = counters["loop"] || 0; |
77 | counters["loop"] = max((counters["loop"] || 0) - acc, 0); |
78 | counters["input"] = (counters["input"] || 0) + acc * 1; |
79 | counters["player"] = (counters["player"] || 0) + acc * 1; |
80 | counters["enemies"] = (counters["enemies"] || 0) + acc * 1; |
81 | counters["cull"] = (counters["cull"] || 0) + acc * 1; |
82 | counters["re-loop"] = (counters["re-loop"] || 0) + acc * 1; |
83 | return true; |
84 | } |
85 | if (counters["input"] > 0) { |
86 | let acc = counters["input"] || 0; |
87 | counters["input"] = max((counters["input"] || 0) - acc, 0); |
88 | counters["poll"] = (counters["poll"] || 0) + acc * 1; |
89 | return true; |
90 | } |
91 | if (counters["player"] > 0) { |
92 | let acc = counters["player"] || 0; |
93 | counters["player"] = max((counters["player"] || 0) - acc, 0); |
94 | counters["get dx:max"] = (counters["get dx:max"] || 0) + acc * 1; |
95 | counters["get dy:max"] = (counters["get dy:max"] || 0) + acc * 1; |
96 | return true; |
97 | } |
98 | if (counters["update enemy"] > 0) { |
99 | let acc = counters["update enemy"] || 0; |
100 | counters["update enemy"] = max((counters["update enemy"] || 0) - acc, 0); |
101 | counters["track player"] = (counters["track player"] || 0) + acc * 1; |
102 | return true; |
103 | } |
104 | if (counters["enemies"] > 0 && counters["last enemy"] > 0) { |
105 | let acc = huge; |
106 | acc = min(acc, counters["enemies"] || 0); |
107 | acc = min(acc, counters["last enemy"] || 0); |
108 | counters["enemies"] = max((counters["enemies"] || 0) - acc, 0); |
109 | counters["last enemy"] = max((counters["last enemy"] || 0) - acc, 0); |
110 | return true; |
111 | } |
112 | if (counters["enemies"] > 0) { |
113 | let acc = counters["enemies"] || 0; |
114 | counters["enemies"] = max((counters["enemies"] || 0) - acc, 0); |
115 | counters["update enemy"] = (counters["update enemy"] || 0) + acc * 1; |
116 | counters["next enemy"] = (counters["next enemy"] || 0) + acc * 1; |
117 | return true; |
118 | } |
119 | if (counters["cull"] > 0) { |
120 | let acc = counters["cull"] || 0; |
121 | counters["cull"] = max((counters["cull"] || 0) - acc, 0); |
122 | counters["remove dead enemies"] = (counters["remove dead enemies"] || 0) + acc * 1; |
123 | return true; |
124 | } |
125 | if (counters["re-loop"] > 0) { |
126 | let acc = counters["re-loop"] || 0; |
127 | counters["re-loop"] = max((counters["re-loop"] || 0) - acc, 0); |
128 | counters["loop"] = (counters["loop"] || 0) + acc * 1; |
129 | return true; |
130 | } |
131 | if (counters["get dy"] > 0 && counters["W pressed"] > 0) { |
132 | let acc = huge; |
133 | acc = min(acc, counters["get dy"] || 0); |
134 | acc = min(acc, counters["W pressed"] || 0); |
135 | counters["get dy"] = max((counters["get dy"] || 0) - acc, 0); |
136 | counters["W pressed"] = max((counters["W pressed"] || 0) - acc, 0); |
137 | counters["-dy"] = (counters["-dy"] || 0) + acc * 1; |
138 | counters["get dy"] = (counters["get dy"] || 0) + acc * 1; |
139 | return true; |
140 | } |
141 | if (counters["get dy"] > 0 && counters["S pressed"] > 0) { |
142 | let acc = huge; |
143 | acc = min(acc, counters["get dy"] || 0); |
144 | acc = min(acc, counters["S pressed"] || 0); |
145 | counters["get dy"] = max((counters["get dy"] || 0) - acc, 0); |
146 | counters["S pressed"] = max((counters["S pressed"] || 0) - acc, 0); |
147 | counters["dy"] = (counters["dy"] || 0) + acc * 1; |
148 | return true; |
149 | } |
150 | if (counters["get dx"] > 0 && counters["A pressed"] > 0) { |
151 | let acc = huge; |
152 | acc = min(acc, counters["get dx"] || 0); |
153 | acc = min(acc, counters["A pressed"] || 0); |
154 | counters["get dx"] = max((counters["get dx"] || 0) - acc, 0); |
155 | counters["A pressed"] = max((counters["A pressed"] || 0) - acc, 0); |
156 | counters["-dx"] = (counters["-dx"] || 0) + acc * 1; |
157 | counters["get dx"] = (counters["get dx"] || 0) + acc * 1; |
158 | return true; |
159 | } |
160 | if (counters["get dx"] > 0 && counters["D pressed"] > 0) { |
161 | let acc = huge; |
162 | acc = min(acc, counters["get dx"] || 0); |
163 | acc = min(acc, counters["D pressed"] || 0); |
164 | counters["get dx"] = max((counters["get dx"] || 0) - acc, 0); |
165 | counters["D pressed"] = max((counters["D pressed"] || 0) - acc, 0); |
166 | counters["dx"] = (counters["dx"] || 0) + acc * 1; |
167 | return true; |
168 | } |
169 | if (counters["loop"] > 0) { |
170 | let acc = counters["loop"] || 0; |
171 | counters["loop"] = max((counters["loop"] || 0) - acc, 0); |
172 | counters["input"] = (counters["input"] || 0) + acc * 1; |
173 | counters["player"] = (counters["player"] || 0) + acc * 1; |
174 | counters["enemies"] = (counters["enemies"] || 0) + acc * 1; |
175 | counters["cull"] = (counters["cull"] || 0) + acc * 1; |
176 | counters["re-loop"] = (counters["re-loop"] || 0) + acc * 1; |
177 | return true; |
178 | } |
179 | if (counters["input"] > 0) { |
180 | let acc = counters["input"] || 0; |
181 | counters["input"] = max((counters["input"] || 0) - acc, 0); |
182 | counters["poll"] = (counters["poll"] || 0) + acc * 1; |
183 | return true; |
184 | } |
185 | if (counters["player"] > 0) { |
186 | let acc = counters["player"] || 0; |
187 | counters["player"] = max((counters["player"] || 0) - acc, 0); |
188 | counters["get dx:max"] = (counters["get dx:max"] || 0) + acc * 1; |
189 | counters["get dy:max"] = (counters["get dy:max"] || 0) + acc * 1; |
190 | return true; |
191 | } |
192 | if (counters["update enemy"] > 0) { |
193 | let acc = counters["update enemy"] || 0; |
194 | counters["update enemy"] = max((counters["update enemy"] || 0) - acc, 0); |
195 | counters["track player"] = (counters["track player"] || 0) + acc * 1; |
196 | return true; |
197 | } |
198 | if (counters["enemies"] > 0 && counters["last enemy"] > 0) { |
199 | let acc = huge; |
200 | acc = min(acc, counters["enemies"] || 0); |
201 | acc = min(acc, counters["last enemy"] || 0); |
202 | counters["enemies"] = max((counters["enemies"] || 0) - acc, 0); |
203 | counters["last enemy"] = max((counters["last enemy"] || 0) - acc, 0); |
204 | return true; |
205 | } |
206 | if (counters["enemies"] > 0) { |
207 | let acc = counters["enemies"] || 0; |
208 | counters["enemies"] = max((counters["enemies"] || 0) - acc, 0); |
209 | counters["update enemy"] = (counters["update enemy"] || 0) + acc * 1; |
210 | counters["next enemy"] = (counters["next enemy"] || 0) + acc * 1; |
211 | return true; |
212 | } |
213 | if (counters["cull"] > 0) { |
214 | let acc = counters["cull"] || 0; |
215 | counters["cull"] = max((counters["cull"] || 0) - acc, 0); |
216 | counters["remove dead enemies"] = (counters["remove dead enemies"] || 0) + acc * 1; |
217 | return true; |
218 | } |
219 | if (counters["re-loop"] > 0) { |
220 | let acc = counters["re-loop"] || 0; |
221 | counters["re-loop"] = max((counters["re-loop"] || 0) - acc, 0); |
222 | counters["loop"] = (counters["loop"] || 0) + acc * 1; |
223 | return true; |
224 | } |
225 | return false; |
226 | } |
227 | self.run = function() { |
228 | let counters = self.counters; |
229 | while(match(self, counters)){}; |
230 | }; |
231 | self.log_state = function() { |
232 | return Object.entries(self.counters).map(([k, v]) => `${k} :: ${v}`).join('\n'); |
233 | }; return self; |
234 | }; |
derp.comp.tiny.js
· 4.1 KiB · JavaScript
Surowy
Playground
return function() {
let min = Math.min; var max = Math.max; var huge = Number.MAX_SAFE_INTEGER;
let self = { state: { strings: [], slots: {} } };
self._ = [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
function match(self, _) {
console.log(Object.entries(_).filter(([,v])=>v>0).map(([k,v]) => `${k} :: ${v}`).join('\n') );
console.log(self.state.strings);
console.log(self.state.slots);
if (_[0] > 0 && _[1] > 0) {
let acc = min(_[0],_[1])
_[0] = max(_[0] - acc, 0);
_[1] = max(_[1] - acc, 0);
return true;
}
if (_[2] > 0 && _[3] > 0) {
let acc = min(_[2],_[3])
_[2] = max(_[2] - acc, 0);
_[3] = max(_[3] - acc, 0);
return true;
}
if (_[4] > 0 && _[5] > 0) {
let acc = min(_[4],_[5])
_[4] = max(_[4] - acc, 0);
_[5] = max(_[5] - acc, 0);
_[3] += acc * 1;
_[4] += acc * 1;
return true;
}
if (_[4] > 0 && _[6] > 0) {
let acc = min(_[4],_[6])
_[4] = max(_[4] - acc, 0);
_[6] = max(_[6] - acc, 0);
_[2] += acc * 1;
return true;
}
if (_[7] > 0 && _[8] > 0) {
let acc = min(_[7],_[8])
_[7] = max(_[7] - acc, 0);
_[8] = max(_[8] - acc, 0);
_[1] += acc * 1;
_[7] += acc * 1;
return true;
}
if (_[7] > 0 && _[9] > 0) {
let acc = min(_[7],_[9])
_[7] = max(_[7] - acc, 0);
_[9] = max(_[9] - acc, 0);
_[0] += acc * 1;
return true;
}
if (_[10] > 0) {
let acc = _[10];
_[10] = max(_[10] - acc, 0);
_[11] += acc * 1;
_[12] += acc * 1;
_[13] += acc * 1;
_[14] += acc * 1;
_[15] += acc * 1;
return true;
}
if (_[11] > 0) {
let acc = _[11];
_[11] = max(_[11] - acc, 0);
_[16] += acc * 1;
return true;
}
if (_[12] > 0) {
let acc = _[12];
_[12] = max(_[12] - acc, 0);
_[17] += acc * 1;
_[18] += acc * 1;
return true;
}
if (_[19] > 0) {
let acc = _[19];
_[19] = max(_[19] - acc, 0);
_[20] += acc * 1;
return true;
}
if (_[13] > 0 && _[21] > 0) {
let acc = min(_[13],_[21])
_[13] = max(_[13] - acc, 0);
_[21] = max(_[21] - acc, 0);
return true;
}
if (_[13] > 0) {
let acc = _[13];
_[13] = max(_[13] - acc, 0);
_[19] += acc * 1;
_[22] += acc * 1;
return true;
}
if (_[14] > 0) {
let acc = _[14];
_[14] = max(_[14] - acc, 0);
_[23] += acc * 1;
return true;
}
if (_[15] > 0) {
let acc = _[15];
_[15] = max(_[15] - acc, 0);
_[10] += acc * 1;
return true;
}
if (_[4] > 0 && _[5] > 0) {
let acc = min(_[4],_[5])
_[4] = max(_[4] - acc, 0);
_[5] = max(_[5] - acc, 0);
_[3] += acc * 1;
_[4] += acc * 1;
return true;
}
if (_[4] > 0 && _[6] > 0) {
let acc = min(_[4],_[6])
_[4] = max(_[4] - acc, 0);
_[6] = max(_[6] - acc, 0);
_[2] += acc * 1;
return true;
}
if (_[7] > 0 && _[8] > 0) {
let acc = min(_[7],_[8])
_[7] = max(_[7] - acc, 0);
_[8] = max(_[8] - acc, 0);
_[1] += acc * 1;
_[7] += acc * 1;
return true;
}
if (_[7] > 0 && _[9] > 0) {
let acc = min(_[7],_[9])
_[7] = max(_[7] - acc, 0);
_[9] = max(_[9] - acc, 0);
_[0] += acc * 1;
return true;
}
if (_[10] > 0) {
let acc = _[10];
_[10] = max(_[10] - acc, 0);
_[11] += acc * 1;
_[12] += acc * 1;
_[13] += acc * 1;
_[14] += acc * 1;
_[15] += acc * 1;
return true;
}
if (_[11] > 0) {
let acc = _[11];
_[11] = max(_[11] - acc, 0);
_[16] += acc * 1;
return true;
}
if (_[12] > 0) {
let acc = _[12];
_[12] = max(_[12] - acc, 0);
_[17] += acc * 1;
_[18] += acc * 1;
return true;
}
if (_[19] > 0) {
let acc = _[19];
_[19] = max(_[19] - acc, 0);
_[20] += acc * 1;
return true;
}
if (_[13] > 0 && _[21] > 0) {
let acc = min(_[13],_[21])
_[13] = max(_[13] - acc, 0);
_[21] = max(_[21] - acc, 0);
return true;
}
if (_[13] > 0) {
let acc = _[13];
_[13] = max(_[13] - acc, 0);
_[19] += acc * 1;
_[22] += acc * 1;
return true;
}
if (_[14] > 0) {
let acc = _[14];
_[14] = max(_[14] - acc, 0);
_[23] += acc * 1;
return true;
}
if (_[15] > 0) {
let acc = _[15];
_[15] = max(_[15] - acc, 0);
_[10] += acc * 1;
return true;
}
return false;
}
self.run = function() {
let _ = self._;
while(match(self, _)){};
};
self.log_state = function() {
return Object.entries(self._).map(([k, v]) => `${k} :: ${v}`).join('\n');
}; return self;
};
1 | return function() { |
2 | let min = Math.min; var max = Math.max; var huge = Number.MAX_SAFE_INTEGER; |
3 | let self = { state: { strings: [], slots: {} } }; |
4 | |
5 | |
6 | self._ = [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0] |
7 | |
8 | function match(self, _) { |
9 | |
10 | console.log(Object.entries(_).filter(([,v])=>v>0).map(([k,v]) => `${k} :: ${v}`).join('\n') ); |
11 | console.log(self.state.strings); |
12 | console.log(self.state.slots); |
13 | |
14 | if (_[0] > 0 && _[1] > 0) { |
15 | let acc = min(_[0],_[1]) |
16 | _[0] = max(_[0] - acc, 0); |
17 | _[1] = max(_[1] - acc, 0); |
18 | return true; |
19 | } |
20 | if (_[2] > 0 && _[3] > 0) { |
21 | let acc = min(_[2],_[3]) |
22 | _[2] = max(_[2] - acc, 0); |
23 | _[3] = max(_[3] - acc, 0); |
24 | return true; |
25 | } |
26 | if (_[4] > 0 && _[5] > 0) { |
27 | let acc = min(_[4],_[5]) |
28 | _[4] = max(_[4] - acc, 0); |
29 | _[5] = max(_[5] - acc, 0); |
30 | _[3] += acc * 1; |
31 | _[4] += acc * 1; |
32 | return true; |
33 | } |
34 | if (_[4] > 0 && _[6] > 0) { |
35 | let acc = min(_[4],_[6]) |
36 | _[4] = max(_[4] - acc, 0); |
37 | _[6] = max(_[6] - acc, 0); |
38 | _[2] += acc * 1; |
39 | return true; |
40 | } |
41 | if (_[7] > 0 && _[8] > 0) { |
42 | let acc = min(_[7],_[8]) |
43 | _[7] = max(_[7] - acc, 0); |
44 | _[8] = max(_[8] - acc, 0); |
45 | _[1] += acc * 1; |
46 | _[7] += acc * 1; |
47 | return true; |
48 | } |
49 | if (_[7] > 0 && _[9] > 0) { |
50 | let acc = min(_[7],_[9]) |
51 | _[7] = max(_[7] - acc, 0); |
52 | _[9] = max(_[9] - acc, 0); |
53 | _[0] += acc * 1; |
54 | return true; |
55 | } |
56 | if (_[10] > 0) { |
57 | let acc = _[10]; |
58 | _[10] = max(_[10] - acc, 0); |
59 | _[11] += acc * 1; |
60 | _[12] += acc * 1; |
61 | _[13] += acc * 1; |
62 | _[14] += acc * 1; |
63 | _[15] += acc * 1; |
64 | return true; |
65 | } |
66 | if (_[11] > 0) { |
67 | let acc = _[11]; |
68 | _[11] = max(_[11] - acc, 0); |
69 | _[16] += acc * 1; |
70 | return true; |
71 | } |
72 | if (_[12] > 0) { |
73 | let acc = _[12]; |
74 | _[12] = max(_[12] - acc, 0); |
75 | _[17] += acc * 1; |
76 | _[18] += acc * 1; |
77 | return true; |
78 | } |
79 | if (_[19] > 0) { |
80 | let acc = _[19]; |
81 | _[19] = max(_[19] - acc, 0); |
82 | _[20] += acc * 1; |
83 | return true; |
84 | } |
85 | if (_[13] > 0 && _[21] > 0) { |
86 | let acc = min(_[13],_[21]) |
87 | _[13] = max(_[13] - acc, 0); |
88 | _[21] = max(_[21] - acc, 0); |
89 | return true; |
90 | } |
91 | if (_[13] > 0) { |
92 | let acc = _[13]; |
93 | _[13] = max(_[13] - acc, 0); |
94 | _[19] += acc * 1; |
95 | _[22] += acc * 1; |
96 | return true; |
97 | } |
98 | if (_[14] > 0) { |
99 | let acc = _[14]; |
100 | _[14] = max(_[14] - acc, 0); |
101 | _[23] += acc * 1; |
102 | return true; |
103 | } |
104 | if (_[15] > 0) { |
105 | let acc = _[15]; |
106 | _[15] = max(_[15] - acc, 0); |
107 | _[10] += acc * 1; |
108 | return true; |
109 | } |
110 | if (_[4] > 0 && _[5] > 0) { |
111 | let acc = min(_[4],_[5]) |
112 | _[4] = max(_[4] - acc, 0); |
113 | _[5] = max(_[5] - acc, 0); |
114 | _[3] += acc * 1; |
115 | _[4] += acc * 1; |
116 | return true; |
117 | } |
118 | if (_[4] > 0 && _[6] > 0) { |
119 | let acc = min(_[4],_[6]) |
120 | _[4] = max(_[4] - acc, 0); |
121 | _[6] = max(_[6] - acc, 0); |
122 | _[2] += acc * 1; |
123 | return true; |
124 | } |
125 | if (_[7] > 0 && _[8] > 0) { |
126 | let acc = min(_[7],_[8]) |
127 | _[7] = max(_[7] - acc, 0); |
128 | _[8] = max(_[8] - acc, 0); |
129 | _[1] += acc * 1; |
130 | _[7] += acc * 1; |
131 | return true; |
132 | } |
133 | if (_[7] > 0 && _[9] > 0) { |
134 | let acc = min(_[7],_[9]) |
135 | _[7] = max(_[7] - acc, 0); |
136 | _[9] = max(_[9] - acc, 0); |
137 | _[0] += acc * 1; |
138 | return true; |
139 | } |
140 | if (_[10] > 0) { |
141 | let acc = _[10]; |
142 | _[10] = max(_[10] - acc, 0); |
143 | _[11] += acc * 1; |
144 | _[12] += acc * 1; |
145 | _[13] += acc * 1; |
146 | _[14] += acc * 1; |
147 | _[15] += acc * 1; |
148 | return true; |
149 | } |
150 | if (_[11] > 0) { |
151 | let acc = _[11]; |
152 | _[11] = max(_[11] - acc, 0); |
153 | _[16] += acc * 1; |
154 | return true; |
155 | } |
156 | if (_[12] > 0) { |
157 | let acc = _[12]; |
158 | _[12] = max(_[12] - acc, 0); |
159 | _[17] += acc * 1; |
160 | _[18] += acc * 1; |
161 | return true; |
162 | } |
163 | if (_[19] > 0) { |
164 | let acc = _[19]; |
165 | _[19] = max(_[19] - acc, 0); |
166 | _[20] += acc * 1; |
167 | return true; |
168 | } |
169 | if (_[13] > 0 && _[21] > 0) { |
170 | let acc = min(_[13],_[21]) |
171 | _[13] = max(_[13] - acc, 0); |
172 | _[21] = max(_[21] - acc, 0); |
173 | return true; |
174 | } |
175 | if (_[13] > 0) { |
176 | let acc = _[13]; |
177 | _[13] = max(_[13] - acc, 0); |
178 | _[19] += acc * 1; |
179 | _[22] += acc * 1; |
180 | return true; |
181 | } |
182 | if (_[14] > 0) { |
183 | let acc = _[14]; |
184 | _[14] = max(_[14] - acc, 0); |
185 | _[23] += acc * 1; |
186 | return true; |
187 | } |
188 | if (_[15] > 0) { |
189 | let acc = _[15]; |
190 | _[15] = max(_[15] - acc, 0); |
191 | _[10] += acc * 1; |
192 | return true; |
193 | } |
194 | return false; |
195 | } |
196 | self.run = function() { |
197 | let _ = self._; |
198 | while(match(self, _)){}; |
199 | }; |
200 | self.log_state = function() { |
201 | return Object.entries(self._).map(([k, v]) => `${k} :: ${v}`).join('\n'); |
202 | }; return self; |
203 | }; |
derp.nv
· 748 B · Text
Surowy
Playground
| dx, -dx |
| dy, -dy |
| get dy, W pressed | -dy, get dy
| get dy, S pressed | dy
| get dx, A pressed | -dx, get dx
| get dx, D pressed | dx
| loop | input, player, enemies, cull, re-loop
| input | poll
| player | get dx:max, get dy:max
|| loop
| update enemy | track player
| enemies, last enemy |
| enemies | update enemy, next enemy
| cull | remove dead enemies
| re-loop | loop
| get dy, W pressed | -dy, get dy
| get dy, S pressed | dy
| get dx, A pressed | -dx, get dx
| get dx, D pressed | dx
| loop | input, player, enemies, cull, re-loop
| input | poll
| player | get dx:max, get dy:max
| update enemy | track player
| enemies, last enemy |
| enemies | update enemy, next enemy
| cull | remove dead enemies
| re-loop | loop
1 | | dx, -dx | |
2 | | dy, -dy | |
3 | |
4 | | get dy, W pressed | -dy, get dy |
5 | | get dy, S pressed | dy |
6 | | get dx, A pressed | -dx, get dx |
7 | | get dx, D pressed | dx |
8 | |
9 | |
10 | | loop | input, player, enemies, cull, re-loop |
11 | | input | poll |
12 | | player | get dx:max, get dy:max |
13 | |
14 | || loop |
15 | |
16 | | update enemy | track player |
17 | | enemies, last enemy | |
18 | | enemies | update enemy, next enemy |
19 | |
20 | | cull | remove dead enemies |
21 | | re-loop | loop |
22 | |
23 | | get dy, W pressed | -dy, get dy |
24 | | get dy, S pressed | dy |
25 | | get dx, A pressed | -dx, get dx |
26 | | get dx, D pressed | dx |
27 | |
28 | |
29 | | loop | input, player, enemies, cull, re-loop |
30 | | input | poll |
31 | | player | get dx:max, get dy:max |
32 | |
33 | | update enemy | track player |
34 | | enemies, last enemy | |
35 | | enemies | update enemy, next enemy |
36 | |
37 | | cull | remove dead enemies |
38 | | re-loop | loop |