Added typedef for SudokuStates
Removed unnecessary parameter
This commit is contained in:
parent
48e0e90caa
commit
2edeb893a4
@ -21,20 +21,24 @@ function randInt(min, max) {
|
||||
}
|
||||
|
||||
class SudokuPuzzle extends EventTarget {
|
||||
/**
|
||||
* @typedef {(number|null|undefined)[]} SudokuState
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {(number|null)[][]}
|
||||
* @type {SudokuState[]}
|
||||
*/
|
||||
#state = []
|
||||
/**
|
||||
*
|
||||
* @type {(number|null|undefined)[]}
|
||||
* @type {SudokuState}
|
||||
*/
|
||||
#activeState = new Array(SUDOKU_GRID_SIZE)
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {(number|null|undefined)[]}
|
||||
* @returns {SudokuState}
|
||||
*/
|
||||
get grid() {
|
||||
const gridValue = [...this.#activeState]
|
||||
@ -61,7 +65,7 @@ class SudokuPuzzle extends EventTarget {
|
||||
/**
|
||||
*
|
||||
* @param serializedState {string}
|
||||
* @returns {((number|null|undefined))[]}
|
||||
* @returns {SudokuState}
|
||||
*/
|
||||
static #stateFromString(serializedState) {
|
||||
let cellIndex = 0
|
||||
@ -86,7 +90,7 @@ class SudokuPuzzle extends EventTarget {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param stateToSample {(number|null|undefined)[]}
|
||||
* @param stateToSample {SudokuState}
|
||||
* @returns {undefined|number}
|
||||
*/
|
||||
#sampleRandomEmptyField(stateToSample = this.#activeState) {
|
||||
@ -98,7 +102,7 @@ class SudokuPuzzle extends EventTarget {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param states {...(number|null|undefined)[][]}
|
||||
* @param states {...SudokuState[]}
|
||||
*/
|
||||
static collapseStates(...states) {
|
||||
return Array.from({ length: SUDOKU_GRID_SIZE }, (_, i) => {
|
||||
@ -113,7 +117,7 @@ class SudokuPuzzle extends EventTarget {
|
||||
/**
|
||||
*
|
||||
* @param slot {number}
|
||||
* @param state {(number|null|undefined)[]}
|
||||
* @param state {SudokuState}
|
||||
* @return {Set<number>}
|
||||
*/
|
||||
#boxGetValues(slot, state = this.#activeState) {
|
||||
@ -137,7 +141,7 @@ class SudokuPuzzle extends EventTarget {
|
||||
/**
|
||||
*
|
||||
* @param slot {number}
|
||||
* @param state {(number|null|undefined)[]}
|
||||
* @param state {SudokuState}
|
||||
* @return {Set<number>}
|
||||
*/
|
||||
#crossGetValues(slot, state = this.#activeState) {
|
||||
@ -176,7 +180,7 @@ class SudokuPuzzle extends EventTarget {
|
||||
/**
|
||||
*
|
||||
* @param slot {number}
|
||||
* @param state {(number|null|undefined)[]}
|
||||
* @param state {SudokuState}
|
||||
* @return {Set<number>}
|
||||
*/
|
||||
getValues(slot, state = this.#activeState) {
|
||||
@ -189,7 +193,7 @@ class SudokuPuzzle extends EventTarget {
|
||||
*
|
||||
* @param value {number}
|
||||
* @param slot {number}
|
||||
* @param state {(number|null|undefined)[]}
|
||||
* @param state {SudokuState}
|
||||
* @return boolean
|
||||
*/
|
||||
isValueValidForSlot(value, slot, state = this.#activeState) {
|
||||
@ -200,7 +204,7 @@ class SudokuPuzzle extends EventTarget {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param newState {(number|null|undefined)[]}
|
||||
* @param newState {SudokuState}
|
||||
*/
|
||||
fillRandomFieldInState(newState = Array.from({ length: SUDOKU_GRID_SIZE })) {
|
||||
const inProgressState = SudokuPuzzle.collapseStates(
|
||||
@ -222,7 +226,7 @@ class SudokuPuzzle extends EventTarget {
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {(number|null|undefined)[]}
|
||||
* @returns {SudokuState}
|
||||
*/
|
||||
#generateRandomState() {
|
||||
const newState = Array.from({ length: SUDOKU_GRID_SIZE })
|
||||
@ -235,7 +239,7 @@ class SudokuPuzzle extends EventTarget {
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {(number|null|undefined)[]}
|
||||
* @returns {SudokuState}
|
||||
*/
|
||||
get baseState() {
|
||||
return this.#state[0]
|
||||
@ -253,7 +257,7 @@ class SudokuPuzzle extends EventTarget {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param newState {(number|null|undefined)[]}
|
||||
* @param newState {SudokuState}
|
||||
*/
|
||||
applyState(newState) {
|
||||
this.#state.push(newState)
|
||||
@ -367,7 +371,7 @@ class SudokuHost extends HTMLElement {
|
||||
})
|
||||
|
||||
this.#keyProcessors.set("m", () => {
|
||||
for (const [_, cell] of this.#selectedCells) {
|
||||
for (const [, cell] of this.#selectedCells) {
|
||||
cell.classList.toggle("marked")
|
||||
cell.classList.remove("selected")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user