state = {
hopButton;
let state = this || {
currentHole: firstHoleToCheck,
rabbitPosition: start,
message: "Not started..."
};
if (paused) return yield state;
for (; state.currentHole < length; ++state.currentHole) {
await Promises.delay(delay);
if (state.rabbitPosition === state.currentHole) {
state.message = `Found bunny at hole ${state.currentHole} ⛳🐰`;
return yield state;
}
if (state.rabbitPosition === length - 1) {
state.rabbitPosition -= 1;
} else if (state.rabbitPosition === 0) {
state.rabbitPosition += 1;
} else {
const hop = randomHop();
state.rabbitPosition += hop;
}
state.message =
state.currentHole === length - 1
? `Last hole (${state.currentHole}) and bunny not found 🐇`
: `Bunny not found in hole ${state.currentHole} 🕳️`;
yield state;
}
}