From 80297b7ac4c6b07cec9b4077c6fbe27a33d80d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Babi=C4=8D?= Date: Sun, 3 Jan 2021 18:58:23 +0100 Subject: [PATCH] fix impossible picks --- src/App.svelte | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 496b2d2..5962c1e 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -74,21 +74,22 @@ const change = curr => { const prev = state.indexOf(pick) - const emptyHoles = [...state.keys()].filter(i => state[i] == hole) - const possibleDests = jumps.adjacencyList[curr].filter(jump => - emptyHoles.includes(jump) - ) - if (state[curr] == pole && prev == -1 && possibleDests.length > 0) { - state[curr] = pick + if (state[curr] == pole && prev == -1) { + let destExists = false jumps.adjacencyList[curr].forEach(jump => { const jumpedOver = commonBetween(curr, jump) if (state[jump] == hole && state[jumpedOver] == pole) { state[jump] = dest + destExists = true } }) + if (destExists) { + state[curr] = pick + } + return }