This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* csv reader * Update puzzles.js * fixed to await * fix * grabs a selection of puzzles * added return * fix infinite loop * syntax * added board creator * syntax * added movement functionality * Update puzzles.js * syntax fix * Update puzzles.js * syntax fix * Added initialisation and made puzzle move checker * added menu element for puzzles * syntax error fixed * fixed interaction with fenfurnace * puzzles fix * added moves per colour * fixed correct move issue todo: add exception case handling for promotion * error fix * window -> global * Update puzzles.js * added button to move to next puzzle * fixed await * flips board to correct position * cleared message on puzzle completion * add difficulty slider * move data file * Update readme.md * formatting * Update index.html * pass through data folder * display title and next properly * clear move log when done * move next puzzle button * Update puzzles.js * added puzzles icon * Update index.html * Fix ingame status not being reset * Add hint button * highlight hinted square instead * Filter with difficulty * sort puzzles iteratively until list is usable * fix merge artefact * display failed attempts * copyedit * unhide failed move count * copyedit * reset puzzle attempts on puzzle change * fix randomiser * state promotion piece * clear highlighting on puzzle change * Add option to load specific puzzle * expanded amount of puzzles * NEW AND IMPROVED PUZZLES * remove unnecessary data from puzzle list Co-authored-by: Nixinova <[email protected]> Co-authored-by: nimitoburrito <[email protected]>
- Loading branch information
1 parent
133535c
commit 08b7fd3
Showing
14 changed files
with
1,553 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
permalink: /menu/puzzles/ | ||
layout: menu.njk | ||
--- | ||
|
||
<form action="/play" method="GET"> | ||
|
||
<h2>Puzzles</h2> | ||
<div> | ||
<label class="hide"> | ||
<strong>Puzzles</strong> | ||
<input type="checkbox" checked name="puzzles"> | ||
</label> | ||
</div> | ||
|
||
<div> | ||
<div style="width: 100%;"> | ||
<label> | ||
<strong>Difficulty</strong><br> | ||
<input type="range" autocomplete="off" name="difficulty" value="1700" min="1000" max="2400" id="puzzles-level"> | ||
</label> | ||
<label> | ||
<strong>Starting Puzzle</strong><br> | ||
<input type="text" maxlength="5" name="puzzlename" placeholder="Random"> | ||
</label> | ||
</div> | ||
</div> | ||
|
||
<div id="nav-buttons"> | ||
<a href="/" id="back" class="card wide" title="Return to menu"> | ||
Back | ||
</a> | ||
<button type="submit" id="play" class="card wide"> | ||
Play | ||
</button> | ||
</div> | ||
|
||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
let savedPuzzles; | ||
let movesToMake; | ||
let puzzleColour; | ||
let puzzlePosition = 0; | ||
|
||
function processData(allText) { | ||
const allTextLines = allText.split(/\r\n|\n/); | ||
const headers = allTextLines[0].split(','); | ||
let lines = []; | ||
|
||
for (let i = 1; i < allTextLines.length; i++) { | ||
const data = allTextLines[i].split(','); | ||
if (data.length === headers.length) { | ||
let textArray = []; | ||
for (let j = 0; j < headers.length; j++) { | ||
textArray.push(headers[j] + ":" + data[j]); | ||
} | ||
lines.push(textArray); | ||
} | ||
} | ||
return lines; | ||
} | ||
|
||
async function getPuzzles(start) { | ||
const puzzleCache = 10; | ||
|
||
// fetch puzzle data | ||
let fileData = await fetch('/data/puzzles.csv').then(data => data.text()); | ||
let puzzleList = processData(fileData); | ||
puzzleList = puzzleList.map(array => Object.fromEntries(array.map(item => item.split(':')))); // convert to array of objects | ||
|
||
// attempt to filter to current difficulty | ||
let sortedPuzzles = puzzleList; | ||
for (let i = 200; i < 800; i += 200) { | ||
sortedPuzzles = puzzleList.filter(obj => Math.abs(obj.ELO - gameOptions.difficulty) < i); | ||
if (sortedPuzzles.length >= 10) break; | ||
} | ||
puzzleList = sortedPuzzles; | ||
|
||
// cache list of puzzles | ||
let selection = []; | ||
for (let i = 1; i <= puzzleCache; i++) { | ||
selection.push(puzzleList[random(0, puzzleList.length - 1)]); | ||
} | ||
savedPuzzles = selection; | ||
|
||
// set first puzzle if explicitly specified | ||
if (start) { | ||
const customPuzzle = puzzleList.find(obj => obj.ID === start); | ||
if (customPuzzle) savedPuzzles.unshift(customPuzzle); | ||
} | ||
} | ||
|
||
function puzzleMove() { | ||
const [, start, end, promotion] = movesToMake[0].toUpperCase().match(/^(..)(..)(.?)/); | ||
if (promotion) global.promotionPiece = promotion; | ||
hasClicked(start); | ||
hasClicked(end); | ||
movesToMake.shift(); | ||
} | ||
|
||
function setBoard(item) { | ||
$.id('current-puzzle-name').innerText = savedPuzzles[item].ID; | ||
createBoardFromFen(savedPuzzles[item].FEN); | ||
movesToMake = savedPuzzles[item].Moves.split(' '); | ||
alignBoard(); | ||
flipBoard(); | ||
puzzleColour = global.currentTurn; | ||
setTimeout(puzzleMove, 1000); | ||
} | ||
|
||
function nextPuzzle() { | ||
window.ingame = true; | ||
window.failedPuzzleAttempts = 0; | ||
$.id('puzzle-attempts-value').innerText = window.failedPuzzleAttempts; | ||
$$('td').forEach(elem => elem.setAttribute('class', '')); | ||
if (puzzlePosition === 9) { | ||
puzzlePosition = 0; | ||
getPuzzles().then(setBoard(puzzlePosition)); | ||
} else { | ||
puzzlePosition++; | ||
setupBoard(); | ||
setBoard(puzzlePosition); | ||
} | ||
$.id('next-puzzle').classList.add('hide'); | ||
$.id('winner').innerHTML = 'Find the best move'; | ||
} | ||
|
||
function showPuzzleHint() { | ||
$.id(movesToMake[0].slice(0, 2).toUpperCase())?.classList.add('valid'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters