WillFlame14 / hanabi-bot

A bot that plays on the hanab.live interface.
GNU General Public License v3.0
15 stars 9 forks source link

Prevent inBetween from crashing when giver and target coincide #316

Closed pedroteosousa closed 3 months ago

pedroteosousa commented 3 months ago

In this replay, the bot crashed before making their move. The stack trace was:

│ file:///app/src/tools/util.js:97
│     return [...new Array(end - start).keys()].map(num => num + start);
│                ^
│
│ RangeError: Invalid array length
│     at Module.range (file:///app/src/tools/util.js:97:13)
│     at inBetween (file:///app/src/conventions/h-group/hanabi-logic.js:174:15)
│     at file:///app/src/conventions/h-group/take-action.js:278:111
│     at Array.some (<anonymous>)
│     at HGroup.take_action (file:///app/src/conventions/h-group/take-action.js:278:56)
│     at Timeout._onTimeout (file:///app/src/action-handler.js:117:52)
│     at listOnTimeout (node:internal/timers:573:17)
│     at process.processTimers (node:internal/timers:514:7)

So, this line sometimes calls inBetween with giver == target. Maybe this is not the best solution, but to me it makes semantic sense to return false when giver == target.

WillFlame14 commented 3 months ago

Nice catch! I agree with your thoughts, though I've already got something a fix coming in the next update. Just haven't pushed it yet.