insert victory info

master
Peter Babič 3 years ago
parent bc2d51109a
commit 4a977d0bf6
Signed by: peter.babic
GPG Key ID: 4BB075BC1884BA40
  1. 1
      .gitignore
  2. 38
      cypress/integration/spec.js
  3. 77
      src/App.svelte

1
.gitignore vendored

@ -3,3 +3,4 @@
.vscode/ .vscode/
.DS_Store .DS_Store
out/

@ -6,6 +6,7 @@ describe("game should", () => {
cy.get(".div0.hole").should("be.visible") cy.get(".div0.hole").should("be.visible")
cy.get(".div1.pole").should("be.visible") cy.get(".div1.pole").should("be.visible")
cy.get(".div2.pole").should("be.visible").click() 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.dest").should("be.visible").click()
cy.get(".div0.pole").should("be.visible") cy.get(".div0.pole").should("be.visible")
cy.get(".div1.hole").should("be.visible") cy.get(".div1.hole").should("be.visible")
@ -31,6 +32,7 @@ describe("game should", () => {
cy.get(".div8.pole").click() cy.get(".div8.pole").click()
cy.get(".div6.dest").click() cy.get(".div6.dest").click()
cy.get(".div12.pole").click() cy.get(".div12.pole").click()
cy.get(".div5.dest").should("be.visible")
cy.get(".div7.dest").click() cy.get(".div7.dest").click()
cy.get(".div13.pole").click() cy.get(".div13.pole").click()
cy.get(".div8.dest").click() cy.get(".div8.dest").click()
@ -43,4 +45,40 @@ describe("game should", () => {
cy.get("@game-over").should("be.be.visible") 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
}) })

@ -8,13 +8,16 @@
fallback: scale, fallback: scale,
}) })
const MAX_STEPS = 13
const pole = 0 const pole = 0
const hole = 1 const hole = 1
const pick = 2 const pick = 2
const dest = 3 const dest = 3
let circles = [] let circles = []
let playing let steps = 0
let gameover
let victory
let bold let bold
let adjcs let adjcs
let jumps let jumps
@ -24,7 +27,9 @@
jumps = new Graph() jumps = new Graph()
circles = [] circles = []
playing = true steps = 0
gameover = false
victory = false
bold = false bold = false
const numCircles = 15 const numCircles = 15
@ -155,10 +160,19 @@
if (circles[curr] == dest) { if (circles[curr] == dest) {
jumpOver(circles, prev, curr) jumpOver(circles, prev, curr)
clearDests() clearDests()
steps++
console.log(steps)
if (steps == MAX_STEPS) {
bold = true
victory = true
return
}
const hints = getHints(circles) const hints = getHints(circles)
if (hints.length == 0) { if (hints.length == 0) {
playing = false gameover = true
bold = true bold = true
} }
@ -171,20 +185,22 @@
} }
} }
class TT { class Tree {
constructor(src, des) { constructor(solution, depth) {
this.SRC = src this.depth = depth
this.DES = des this.solution = solution
this.xx = [] this.children = []
} }
} }
onMount(() => { onMount(() => {
restart() restart()
let shadow = [...circles]
const start = 0 let depth = 0
const moves = new TT(start, undefined) let solutions = []
let shadow = [...circles]
const MAX_DEPTH = 13
const moves = new Tree("", depth)
const recurse = move => { const recurse = move => {
const hints = getHints(shadow) const hints = getHints(shadow)
@ -193,18 +209,25 @@
} }
hints.forEach(hint => { hints.forEach(hint => {
getDests(shadow, hint).forEach(des => { getDests(shadow, hint).forEach(destination => {
const last = move.xx.push(new TT(hint, des)) - 1 const solution = `${move.solution} ${hint}>${destination}`
jumpOver(shadow, hint, des) const child = new Tree(solution, depth)
recurse(move.xx[last], last) const lastIndex = move.children.push(child) - 1
jumpReverse(shadow, hint, des) 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) // recurse(moves)
console.log(moves) // console.log(solutions)
}) })
</script> </script>
@ -299,12 +322,21 @@
padding: 15px; padding: 15px;
} }
span {
display: none;
}
.restart { .restart {
display: inline;
cursor: pointer; cursor: pointer;
} }
.playing { .gameover {
visibility: hidden; display: inline;
}
.victory {
display: inline;
} }
.bold { .bold {
@ -315,7 +347,8 @@
<main> <main>
<div> <div>
<span class="restart" class:bold on:click={restart}>RESTART GAME</span> <span class="restart" class:bold on:click={restart}>RESTART GAME</span>
<span data-cy="game-over" class:playing> | GAME OVER</span> <span data-cy="game-over" class:gameover> | GAME OVER</span>
<span data-cy="victory" class:victory> | VICTORY</span>
</div> </div>
<div class="triangle"> <div class="triangle">
{#each circles as _, i} {#each circles as _, i}

Loading…
Cancel
Save