derp.comp.js
· 8.9 KiB · JavaScript
原始文件
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
· 1.5 KiB · JavaScript
原始文件
Playground
return () => {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,0,0]
function match(self, _) {
const m=Math.min;
const M=(a,idx)=>(_[idx]=Math.max(_[idx]-a, 0), a)
const I=(a,idx,c)=>(_[idx]+=a*c, a)
const P=(...p)=>p.every((x)=>x>0)
return (
P(17)?(i(M(_[17],17),7,10000000),!0):
P(18)?(i(M(_[18],18),4,100000000),!0):
P(0,1)?(M(M(m(_[0],_[1]),0),1),!0):
P(2,3)?(M(M(m(_[2],_[3]),2),3),!0):
P(4,5)?(i(i(M(M(m(_[4],_[5]),4),5),3),4),!0):
P(4,6)?(i(M(M(m(_[4],_[6]),4),6),2),!0):
P(7,8)?(i(i(M(M(m(_[7],_[8]),7),8),1),7),!0):
P(7,9)?(i(M(M(m(_[7],_[9]),7),9),0),!0):
P(10)?(i(i(i(i(i(M(_[10],10),11),12),13),14),15),!0):
P(11)?(i(M(_[11],11),16),!0):
P(12)?(i(i(M(_[12],12),17),18),!0):
P(19)?(i(M(_[19],19),20),!0):
P(13,21)?(M(M(m(_[13],_[21]),13),21),!0):
P(13)?(i(i(M(_[13],13),19),22),!0):
P(14)?(i(M(_[14],14),23),!0):
P(15)?(i(M(_[15],15),10),!0):
P(4,5)?(i(i(M(M(m(_[4],_[5]),4),5),3),4),!0):
P(4,6)?(i(M(M(m(_[4],_[6]),4),6),2),!0):
P(7,8)?(i(i(M(M(m(_[7],_[8]),7),8),1),7),!0):
P(7,9)?(i(M(M(m(_[7],_[9]),7),9),0),!0):
P(10)?(i(i(i(i(i(M(_[10],10),11),12),13),14),15),!0):
P(11)?(i(M(_[11],11),16),!0):
P(12)?(i(i(M(_[12],12),24),25),!0):
P(19)?(i(M(_[19],19),20),!0):
P(13,21)?(M(M(m(_[13],_[21]),13),21),!0):
P(13)?(i(i(M(_[13],13),19),22),!0):
P(14)?(i(M(_[14],14),23),!0):
P(15)?(i(M(_[15],15),10),!0):
!1)
}
self.run = function() {while(match(self, self._)){}};
self.log_state = function() {
return Object.entries(self._).map(([k, v]) => `${k} :: ${v}`).join('\n');
}; return self;
};
| 1 | return () => {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,0,0] |
| 2 | |
| 3 | function match(self, _) { |
| 4 | |
| 5 | const m=Math.min; |
| 6 | const M=(a,idx)=>(_[idx]=Math.max(_[idx]-a, 0), a) |
| 7 | const I=(a,idx,c)=>(_[idx]+=a*c, a) |
| 8 | const P=(...p)=>p.every((x)=>x>0) |
| 9 | return ( |
| 10 | P(17)?(i(M(_[17],17),7,10000000),!0): |
| 11 | P(18)?(i(M(_[18],18),4,100000000),!0): |
| 12 | P(0,1)?(M(M(m(_[0],_[1]),0),1),!0): |
| 13 | P(2,3)?(M(M(m(_[2],_[3]),2),3),!0): |
| 14 | P(4,5)?(i(i(M(M(m(_[4],_[5]),4),5),3),4),!0): |
| 15 | P(4,6)?(i(M(M(m(_[4],_[6]),4),6),2),!0): |
| 16 | P(7,8)?(i(i(M(M(m(_[7],_[8]),7),8),1),7),!0): |
| 17 | P(7,9)?(i(M(M(m(_[7],_[9]),7),9),0),!0): |
| 18 | P(10)?(i(i(i(i(i(M(_[10],10),11),12),13),14),15),!0): |
| 19 | P(11)?(i(M(_[11],11),16),!0): |
| 20 | P(12)?(i(i(M(_[12],12),17),18),!0): |
| 21 | P(19)?(i(M(_[19],19),20),!0): |
| 22 | P(13,21)?(M(M(m(_[13],_[21]),13),21),!0): |
| 23 | P(13)?(i(i(M(_[13],13),19),22),!0): |
| 24 | P(14)?(i(M(_[14],14),23),!0): |
| 25 | P(15)?(i(M(_[15],15),10),!0): |
| 26 | P(4,5)?(i(i(M(M(m(_[4],_[5]),4),5),3),4),!0): |
| 27 | P(4,6)?(i(M(M(m(_[4],_[6]),4),6),2),!0): |
| 28 | P(7,8)?(i(i(M(M(m(_[7],_[8]),7),8),1),7),!0): |
| 29 | P(7,9)?(i(M(M(m(_[7],_[9]),7),9),0),!0): |
| 30 | P(10)?(i(i(i(i(i(M(_[10],10),11),12),13),14),15),!0): |
| 31 | P(11)?(i(M(_[11],11),16),!0): |
| 32 | P(12)?(i(i(M(_[12],12),24),25),!0): |
| 33 | P(19)?(i(M(_[19],19),20),!0): |
| 34 | P(13,21)?(M(M(m(_[13],_[21]),13),21),!0): |
| 35 | P(13)?(i(i(M(_[13],13),19),22),!0): |
| 36 | P(14)?(i(M(_[14],14),23),!0): |
| 37 | P(15)?(i(M(_[15],15),10),!0): |
| 38 | !1) |
| 39 | } |
| 40 | self.run = function() {while(match(self, self._)){}}; |
| 41 | self.log_state = function() { |
| 42 | return Object.entries(self._).map(([k, v]) => `${k} :: ${v}`).join('\n'); |
| 43 | }; return self; |
| 44 | }; |
derp.nv
· 748 B · Text
原始文件
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 |