Sudoku review #1

Open
BordedDev wants to merge 19 commits from BordedDev/sudoku:main into main
Showing only changes of commit ce5dead2cb - Show all commits

View File

@ -32,6 +32,10 @@ class SudokuPuzzle extends EventTarget {
*/ */

This contains a stack of states, essentially the initial state + all steps

This contains a stack of states, essentially the initial state + all steps
#activeState = new Array(9 * 9) #activeState = new Array(9 * 9)

Ooooh, magic numbers :P Did i have that too?

Ooooh, magic numbers :P Did i have that too?

Dang it I missed it, it's meant to be SUDOKU_GRID_SIZE. You did with the new Puzzle(9)

Dang it I missed it, it's meant to be `SUDOKU_GRID_SIZE`. You did with the `new Puzzle(9)`
/**
*
* @returns {(number|null|undefined)[]}
*/
get grid() { get grid() {
const gridValue = [...this.#activeState] const gridValue = [...this.#activeState]
Object.freeze(gridValue) Object.freeze(gridValue)
@ -216,6 +220,10 @@ class SudokuPuzzle extends EventTarget {
return newState return newState
} }
/**
*
* @returns {(number|null|undefined)[]}
*/
#generateRandomState() { #generateRandomState() {
const newState = Array.from({ length: SUDOKU_GRID_SIZE }) const newState = Array.from({ length: SUDOKU_GRID_SIZE })
for (let i = 0; i < 17; i++) { for (let i = 0; i < 17; i++) {
@ -225,6 +233,10 @@ class SudokuPuzzle extends EventTarget {
return newState return newState
} }
/**
*
* @returns {(number|null|undefined)[]}
*/
get baseState() { get baseState() {
return this.#state[0] return this.#state[0]
} }
@ -239,6 +251,10 @@ class SudokuPuzzle extends EventTarget {
) )
} }
/**
*
* @param newState {(number|null|undefined)[]}
*/
applyState(newState) { applyState(newState) {
this.#state.push(newState) this.#state.push(newState)
this.#activeState = SudokuPuzzle.collapseStates(...this.#state) this.#activeState = SudokuPuzzle.collapseStates(...this.#state)