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/
.DS_Store
out/

@ -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
})

@ -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)
})
</script>
@ -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 @@
<main>
<div>
<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 class="triangle">
{#each circles as _, i}

Loading…
Cancel
Save