1
0
This repository has been archived on 2025-03-31. You can view files and clone it, but cannot push or open issues or pull requests.
js-sudoku-solver/coffee/SudokuCell.class.coffee

57 lines
1.3 KiB
CoffeeScript

class @SudokuCell
constructor: (initVal, boardObj) ->
@boardObj = boardObj
@changed = false
@original = false
@value = 0
@set = (1 << @boardObj.dim2) - 1 # all
@setValue(initVal) # init cell
setMask: (newSet) ->
if newSet isnt @set
@set = newSet
@changed = true
@boardObj.changed = true
setValue: (newValue) ->
return false if newValue is @value
setidx = @boardObj.set.indexOf(newValue)
if setidx isnt -1
@value = newValue
@setMask(1 << setidx)
@changed = true
@boardObj.changed = true
return true
else if newValue is -1
@value = 0
@setMask((1 << @boardObj.dim2) - 1) # all
@changed = true
@boardObj.changed = true
return false
getValue: ->
return '.' if @value is 0
return @value
getMask: ->
return @set
getUnknownsCount: ->
result = 0
for n in [0...@boardObj.dim2] by 1
result++ if ((1 << n) & @set)
return result
hasChanged: ->
return @changed
resetChangeFlag: ->
@changed = false
setOriginal: (newValue) ->
@original = newValue
isOriginal: ->
return @original