Check for duplicates in rows and columns for Hitori
parent
9c14be4f3c
commit
01b59ef59d
|
@ -87,6 +87,18 @@ class Nikoli.Cell
|
||||||
0 <= @x < @game.length && 0 <= @y < @game[@x].length &&
|
0 <= @x < @game.length && 0 <= @y < @game[@x].length &&
|
||||||
(!value? || value < 0 && @game[@x][@y] < 0 || value >= 0 && @game[@x][@y] >= 0)
|
(!value? || value < 0 && @game[@x][@y] < 0 || value >= 0 && @game[@x][@y] >= 0)
|
||||||
|
|
||||||
|
duplicatesIn: (array) ->
|
||||||
|
array.filter((cell) => cell == @value).length > 1
|
||||||
|
|
||||||
|
columnDuplicates: ->
|
||||||
|
column = []
|
||||||
|
column.push @game[i][@y] for i in [0...@game.length]
|
||||||
|
|
||||||
|
@duplicatesIn column
|
||||||
|
|
||||||
|
rowDuplicates: ->
|
||||||
|
@duplicatesIn @game[@x]
|
||||||
|
|
||||||
class Nikoli.Stream
|
class Nikoli.Stream
|
||||||
constructor: (@game) ->
|
constructor: (@game) ->
|
||||||
@cells = []
|
@cells = []
|
||||||
|
|
|
@ -18,7 +18,9 @@ class Nikoli.Hitori extends Nikoli.Game
|
||||||
|
|
||||||
if !white_stream.include(cell)
|
if !white_stream.include(cell)
|
||||||
errors.push {row: i, column: j, message: 'The stream must be continuous'}
|
errors.push {row: i, column: j, message: 'The stream must be continuous'}
|
||||||
# TODO check for duplicates in rows and columns
|
|
||||||
|
if cell.rowDuplicates() || cell.columnDuplicates()
|
||||||
|
errors.push {row: i, column: j, message: 'The number appears more than once in the row or column.'}
|
||||||
else
|
else
|
||||||
if cell.adjacentCells().some((adj_cell) -> adj_cell.valid(-1))
|
if cell.adjacentCells().some((adj_cell) -> adj_cell.valid(-1))
|
||||||
errors.push {row: i, column: j, message: 'Adjacent filled-in cells'}
|
errors.push {row: i, column: j, message: 'Adjacent filled-in cells'}
|
||||||
|
|
Loading…
Reference in New Issue