Check for pools in Nurikabe
parent
3342243fe4
commit
9c14be4f3c
|
@ -76,6 +76,13 @@ class Nikoli.Cell
|
||||||
new Cell(@x, @y - 1, @game)
|
new Cell(@x, @y - 1, @game)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
isPool: ->
|
||||||
|
[
|
||||||
|
new Cell(@x, @y + 1, @game),
|
||||||
|
new Cell(@x + 1, @y, @game),
|
||||||
|
new Cell(@x + 1, @y + 1, @game),
|
||||||
|
].every (cell) => cell.valid(@value)
|
||||||
|
|
||||||
valid: (value) ->
|
valid: (value) ->
|
||||||
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)
|
||||||
|
|
|
@ -18,7 +18,9 @@ class Nikoli.Nurikabe extends Nikoli.Game
|
||||||
black_stream.calculate(cell)
|
black_stream.calculate(cell)
|
||||||
else if !black_stream.include(cell)
|
else if !black_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 pools
|
|
||||||
|
if cell.isPool()
|
||||||
|
errors.push {row: i, column: j, message: 'There must be no pools.'}
|
||||||
else if cell.value > 0
|
else if cell.value > 0
|
||||||
if white_walls.some((wall) -> wall.include(cell))
|
if white_walls.some((wall) -> wall.include(cell))
|
||||||
errors.push {row: i, column: j, message: 'Each wall must contain exactly one numbered cell.'}
|
errors.push {row: i, column: j, message: 'Each wall must contain exactly one numbered cell.'}
|
||||||
|
|
Loading…
Reference in New Issue