yolkbot 0.1.0-alpha.53 → 0.1.0-alpha.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "yolkbot",
3
3
  "description": "create a shell shockers (self) bot in under 10 lines.",
4
- "version": "0.1.0-alpha.53",
4
+ "version": "0.1.0-alpha.55",
5
5
  "keywords": [
6
6
  "shell shockers",
7
7
  "shellshock.io",
@@ -16,6 +16,10 @@
16
16
  }, 4);
17
17
  }*/
18
18
 
19
+ import fs from 'node:fs';
20
+
21
+ let timesCalledAt = 0;
22
+
19
23
  class NodeList {
20
24
  constructor(raw) {
21
25
  const now = Date.now();
@@ -74,7 +78,10 @@ class NodeList {
74
78
  }
75
79
 
76
80
  at(x, y, z) {
77
- return this.list.find(node => node.x == x && node.y == y && node.z == z);
81
+ timesCalledAt++;
82
+ fs.writeFileSync('/Users/user/.yolkbot/cocaine.txt', timesCalledAt);
83
+ const key = `${x},${y},${z}`;
84
+ return this.list.find(node => node.positionStr() == key);
78
85
  }
79
86
 
80
87
  clean() {
@@ -185,255 +192,48 @@ class MapNode {
185
192
  const dy = Math.abs(dy0);
186
193
  const dz = Math.abs(dz0);
187
194
 
188
- if (dx + dy + dz == 0) {
195
+ if (dx + dy + dz === 0 || dx + dz > 1 || this.isSolid() || node.isSolid()) {
189
196
  return false;
190
197
  }
191
198
 
192
- if (dx + dz > 1) {
199
+ const belowMe = list.at(this.x, this.y - 1, this.z);
200
+ const belowOther = list.at(node.x, node.y - 1, node.z);
201
+
202
+ if (!belowMe || !belowOther) {
193
203
  return false;
194
204
  }
195
- /*
196
- if (i am solid || target is solid) // can't walk into solid
197
- -> return false
198
- if (solid || ladder directly below me) and (solid directly below target) // above solid to above solid
199
- -> return true
200
- if (i am ladder && target is ladder && dy == 1 && dx, dz == 0) // up/down ladders
201
- -> return true
202
- if (below me is solid && target is wedge && dy == 0 && ry matches) // can walk onto stairs
203
- -> return true
204
- if (i am a wedge && dy == 1 && dx/dz matches my ry) // can walk up stairs
205
- -> return true
206
- */
207
-
208
- /*
209
- Wedge rotation data:
210
-
211
- ry | facing
212
- 0 | -z
213
- 1 | -x
214
- 2 | +z
215
- 3 | +x
216
- */
217
205
 
218
206
  const FORWARD_RY_WEDGE_MAPPING = {
219
207
  0: { x: 0, z: -1 },
220
208
  1: { x: -1, z: 0 },
221
209
  2: { x: 0, z: 1 },
222
210
  3: { x: 1, z: 0 }
223
- }
224
-
225
- if ((!this.isStair() && !node.isStair()) && dx + dy + dz > 1) { // if we are more than 1 unit away and no stairs, we can't travel
226
- return false;
227
- }
228
-
229
- if (this.isSolid() || node.isSolid()) { // if either of us are impassable, we obviously can't travel between
230
- return false;
231
- }
232
-
233
- const belowMe = list.at(this.x, this.y - 1, this.z);
234
- const belowOther = list.at(node.x, node.y - 1, node.z);
235
-
236
- if (!belowMe || !belowOther) { // if we are at the bottom of the map, we can't travel
237
- return false;
238
- }
211
+ };
239
212
 
240
213
  switch (this.meshType) {
241
- // full block
242
- case 'full':
243
- return false;
244
-
245
- // usually useless decorations or internal things like spawnpoints
246
214
  case 'none':
247
- if (dy0 == 1 && node.canWalkThrough()) {
248
- return true;
249
- }
250
- switch (node.meshType) {
251
- case 'none':
252
- if (belowMe.canWalkOn() || belowMe.isLadder()) {
253
- return true;
254
- }
255
- return false;
256
- case 'ladder':
257
- if (dy == 0) {
258
- if (belowMe.canWalkOn()) {
259
- return true;
260
- }
261
- }
262
- return false;
263
- case 'wedge':
264
- if (dy0 == 0) { // same level
265
- if (belowMe.canWalkOn()) {
266
- // if the stair is pointing to me
267
- if (dx0 == -FORWARD_RY_WEDGE_MAPPING[node.ry].x && dz0 == -FORWARD_RY_WEDGE_MAPPING[node.ry].z) {
268
- return true;
269
- }
270
- return false;
271
- }
272
- }
273
- return false;
274
- case 'aabb':
275
- return false;
276
- case 'verysoft':
277
- return false;
278
-
279
- }
280
- break;
281
-
282
- case 'ladder':
283
- if (dy == 1 && node.canWalkThrough()) {
284
- return true;
285
- }
286
- switch (node.meshType) {
287
- case 'none':
288
- if (dy == 0) {
289
- if (belowMe.canWalkOn()) {
290
- return true;
291
- }
292
- }
293
- if (dy == 1) {
294
- if (node.canWalkThrough()) {
295
- return true;
296
- }
297
- }
298
- return false;
299
- case 'ladder':
300
- if (dy == 1) {
301
- return true;
302
- }
303
- if (belowMe.canWalkOn() && belowOther.canWalkOn()) {
304
- return true;
305
- }
306
- return false;
307
- case 'wedge':
308
- return false; // wrong but this should never happen wtf :sob:
309
- case 'aabb':
310
- return false;
311
- }
312
- break;
313
-
314
- // stairs
315
- case 'wedge':
316
- // console.log(`I'm a wedge at ${stringifyCircular(this.position)}`)
317
- /*console.log(`Following the RY mapping, my bottom points to ${this.x - FORWARD_RY_WEDGE_MAPPING[this.ry].x
318
- }, ${this.y
319
- }, ${this.z - FORWARD_RY_WEDGE_MAPPING[this.ry].z
320
- }`)*/
321
- switch (node.meshType) {
322
- case 'none':
323
- case 'wedge':
324
- // if i'm pointing to it and dy0 = -1, i can walk to it (above)
325
- // if i'm reverse pointing and dy0 = 0, i can walk to it (level)
326
- // if i'm reverse pointing and dy0 = 1, i can walk to it (below)
327
- if (this.x + FORWARD_RY_WEDGE_MAPPING[this.ry].x == node.x && this.z + FORWARD_RY_WEDGE_MAPPING[this.ry].z == node.z) {
328
- if (this.y + 1 == node.y) {
329
- return true;
330
- }
331
- return false;
332
- }
333
- if (this.x - FORWARD_RY_WEDGE_MAPPING[this.ry].x == node.x && this.z - FORWARD_RY_WEDGE_MAPPING[this.ry].z == node.z) {
334
- if (this.y == node.y) {
335
- return true;
336
- }
337
- if (this.y - 1 == node.y) {
338
- return true;
339
- }
340
- // console.log(`Wedge at ${stringifyCircular(this.position)} can't walk to wedge/air at ${stringifyCircular(node.position)}`);
341
- return false;
342
- }
343
- return false;
344
- case 'ladder':
345
- return false; // same as above, should never happen
346
- case 'aabb':
347
- case 'verysoft':
348
- return false;
215
+ if (dy0 === 1 && node.canWalkThrough()) return true;
216
+ if (belowMe.canWalkOn() || belowMe.isLadder()) {
217
+ if (node.meshType === 'none' || (node.meshType === 'ladder' && dy === 0) || (node.meshType === 'wedge' && dy0 === 0 && dx0 === -FORWARD_RY_WEDGE_MAPPING[node.ry].x && dz0 === -FORWARD_RY_WEDGE_MAPPING[node.ry].z)) {
218
+ return true;
219
+ }
349
220
  }
350
- break;
351
-
352
- // the various random weird shapes, sometimes block most of a block, often can either be walked over or not at all
353
- case 'aabb':
354
221
  return false;
355
222
 
356
- // things like trees
357
- case 'verysoft':
223
+ case 'ladder':
224
+ if (dy === 1 && node.canWalkThrough()) return true;
225
+ if (dy === 0 && belowMe.canWalkOn()) return true;
226
+ if (node.meshType === 'ladder' && (dy === 1 || (belowMe.canWalkOn() && belowOther.canWalkOn()))) return true;
358
227
  return false;
359
228
 
360
- // usually an intenral thing? like where the spatula is supposed to go
361
- case 'oob':
229
+ case 'wedge':
230
+ if (this.x + FORWARD_RY_WEDGE_MAPPING[this.ry].x === node.x && this.z + FORWARD_RY_WEDGE_MAPPING[this.ry].z === node.z && this.y + 1 === node.y) return true;
231
+ if (this.x - FORWARD_RY_WEDGE_MAPPING[this.ry].x === node.x && this.z - FORWARD_RY_WEDGE_MAPPING[this.ry].z === node.z && (this.y === node.y || this.y - 1 === node.y)) return true;
362
232
  return false;
363
- }
364
233
 
365
- /*if (this.isAir() && node.isAir()) {
366
- if (dy == 0) {
367
- if (belowMe.isSolid() || belowMe.isLadder()) {
368
- if (belowOther.isSolid()) { // if there is a solid block below both of us, we can travel
369
- return true;
370
- } else if (belowOther.canWalk()) { // if we can fall off a corner, we can travel
371
- return true;
372
- } else {
373
- return false; // prevent falling multiple blocks (i think?) may not be necessary
374
- }
375
- }
376
- } else {
377
- if (dy0 == 1) { // if we are above the other node, we can travel
378
- return true;
379
- }
234
+ default:
380
235
  return false;
381
- }
382
- }
383
-
384
- if (!belowMe.isSolid()) {
385
- if (this.y - node.y == 1) { // i can fall down one node
386
- return true;
387
- } else {
388
- return false; // if there's air beneath me, we can't move side to side
389
- }
390
- }
391
-
392
- if (this.isLadder() && node.isLadder() && dy == 1 && dx + dz == 0) { // we can climb up and down ladders
393
- return true;
394
236
  }
395
-
396
- if (belowMe.isSolid() && node.isStair() && dy == 0) { // we can walk onto stairs but the stair needs to be pointing to me
397
- if (dz0 == FORWARD_RY_WEDGE_MAPPING[node.ry].z && dx0 == FORWARD_RY_WEDGE_MAPPING[node.ry].x) {
398
- return true;
399
- }
400
- return false;
401
- }
402
-
403
- if (this.isStair()) {
404
- if (dx + dz > 1) {
405
- return false;
406
- }
407
- if (dy == 1) { // node is below me
408
- if (dx0 == FORWARD_RY_WEDGE_MAPPING[this.ry].x && dz0 == FORWARD_RY_WEDGE_MAPPING[this.ry].z) { // if i'm pointing to it
409
- const inTheWay = list.at(this.x + FORWARD_RY_WEDGE_MAPPING[this.ry].x, this.y, this.z + FORWARD_RY_WEDGE_MAPPING[this.ry].z);
410
- if (inTheWay && inTheWay.isSolid()) {
411
- return false;
412
- }
413
- return true;
414
- }
415
- return false;
416
- } else if (dy == 0) { // node is level with me
417
- if (dx0 == FORWARD_RY_WEDGE_MAPPING[this.ry].x && dz0 == FORWARD_RY_WEDGE_MAPPING[this.ry].z) { // if i'm pointing to it
418
- return true;
419
- }
420
- return false;
421
- } else { // node is above me
422
- if (dx0 == FORWARD_RY_WEDGE_MAPPING[this.ry].x && dz0 == FORWARD_RY_WEDGE_MAPPING[this.ry].z) { // if i'm pointing to it
423
- const inTheWay = list.at(this.x, this.y + 1, this.z);
424
- if (inTheWay && inTheWay.isSolid()) {
425
- return false;
426
- }
427
- return true;
428
- }
429
- return false;
430
- }
431
- }*/
432
- // console.log('My meshtype, below meshtype: ', this.meshType, belowMe.meshType, 'Other meshtype, below other meshtype: ', node.meshType, belowOther.meshType);
433
- // console.log('My ry, other ry: ', this.ry, node.ry);
434
- // console.log('dx0, dy0, dz0: ', dx0, dy0, dz0);
435
- // console.error(`Unrecognized node meshType, me: ${stringifyCircular(this)}, other: ${stringifyCircular(node)}, below me: ${stringifyCircular(belowMe)}, below other: ${stringifyCircular(belowOther)}\n\nThis is NOT your fault. This is an internal error related to pathfinding.\nIf you need an immediate fix and don't use pathfinding features, remove the "PATHFINDING" intent.\n\nPlease paste this full error to our support server and **include the map the bot is on**.`);
436
- return false;
437
237
  }
438
238
 
439
239
  trueCenter() {