diff --git a/.gitignore b/.gitignore index 1a7548c..38c6ebc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .vscode/ .DS_Store +out/ diff --git a/cypress/integration/spec.js b/cypress/integration/spec.js index a340bcd..cd502a4 100644 --- a/cypress/integration/spec.js +++ b/cypress/integration/spec.js @@ -6,6 +6,7 @@ describe("game should", () => { cy.get(".div0.hole").should("be.visible") cy.get(".div1.pole").should("be.visible") cy.get(".div2.pole").should("be.visible").click() + cy.get(".div2.pick").should("be.visible") cy.get(".div0.dest").should("be.visible").click() cy.get(".div0.pole").should("be.visible") cy.get(".div1.hole").should("be.visible") @@ -31,6 +32,7 @@ describe("game should", () => { cy.get(".div8.pole").click() cy.get(".div6.dest").click() cy.get(".div12.pole").click() + cy.get(".div5.dest").should("be.visible") cy.get(".div7.dest").click() cy.get(".div13.pole").click() cy.get(".div8.dest").click() @@ -43,4 +45,40 @@ describe("game should", () => { cy.get("@game-over").should("be.be.visible") }) + + it("display victory", () => { + cy.visit("/") + cy.get("[data-cy=victory]").as("victory").should("not.be.visible") + + cy.get(".div2.pole").click() + cy.get(".div0.dest").click() + cy.get(".div11.pole").click() + cy.get(".div2.dest").click() + cy.get(".div3.pole").click() + cy.get(".div1.dest").click() + cy.get(".div9.pole").click() + cy.get(".div2.dest").click() + cy.get(".div0.pole").click() + cy.get(".div9.dest").click() + cy.get(".div13.pole").click() + cy.get(".div8.dest").click() + cy.get(".div14.pole").click() + cy.get(".div11.dest").click() + cy.get(".div1.pole").click() + cy.get(".div3.dest").click() + cy.get(".div5.pole").click() + cy.get(".div12.dest").click() + cy.get(".div12.pole").click() + cy.get(".div7.dest").click() + cy.get(".div4.pole").click() + cy.get(".div2.dest").click() + cy.get(".div2.pole").click() + cy.get(".div9.dest").click() + cy.get(".div8.pole").click() + cy.get(".div13.dest").click() + + cy.get("@victory").should("be.visible") + }) + + // 2>0 11>2 3>1 9>2 0>9 13>8 14>11 1>3 5>12 12>7 4>2 2>9 8>13 }) diff --git a/src/App.svelte b/src/App.svelte index 37ef8b5..3b64192 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -8,13 +8,16 @@ fallback: scale, }) + const MAX_STEPS = 13 const pole = 0 const hole = 1 const pick = 2 const dest = 3 let circles = [] - let playing + let steps = 0 + let gameover + let victory let bold let adjcs let jumps @@ -24,7 +27,9 @@ jumps = new Graph() circles = [] - playing = true + steps = 0 + gameover = false + victory = false bold = false const numCircles = 15 @@ -155,10 +160,19 @@ if (circles[curr] == dest) { jumpOver(circles, prev, curr) clearDests() + steps++ + console.log(steps) + + if (steps == MAX_STEPS) { + bold = true + victory = true + + return + } const hints = getHints(circles) if (hints.length == 0) { - playing = false + gameover = true bold = true } @@ -171,20 +185,22 @@ } } - class TT { - constructor(src, des) { - this.SRC = src - this.DES = des - this.xx = [] + class Tree { + constructor(solution, depth) { + this.depth = depth + this.solution = solution + this.children = [] } } onMount(() => { restart() - let shadow = [...circles] - const start = 0 - const moves = new TT(start, undefined) + let depth = 0 + let solutions = [] + let shadow = [...circles] + const MAX_DEPTH = 13 + const moves = new Tree("", depth) const recurse = move => { const hints = getHints(shadow) @@ -193,18 +209,25 @@ } hints.forEach(hint => { - getDests(shadow, hint).forEach(des => { - const last = move.xx.push(new TT(hint, des)) - 1 - jumpOver(shadow, hint, des) - recurse(move.xx[last], last) - jumpReverse(shadow, hint, des) + getDests(shadow, hint).forEach(destination => { + const solution = `${move.solution} ${hint}>${destination}` + const child = new Tree(solution, depth) + const lastIndex = move.children.push(child) - 1 + jumpOver(shadow, hint, destination) + depth = depth + 1 + + if (depth == MAX_DEPTH) { + solutions.push(solution) + } + recurse(move.children[lastIndex]) + depth = depth - 1 + jumpReverse(shadow, hint, destination) }) }) } - recurse(moves) - console.log(moves) - + // recurse(moves) + // console.log(solutions) }) @@ -299,12 +322,21 @@ padding: 15px; } + span { + display: none; + } + .restart { + display: inline; cursor: pointer; } - .playing { - visibility: hidden; + .gameover { + display: inline; + } + + .victory { + display: inline; } .bold { @@ -315,7 +347,8 @@
RESTART GAME - | GAME OVER + | GAME OVER + | VICTORY
{#each circles as _, i}