Solve a Hidato puzzle: Difference between revisions

added comments for better understanding
No edit summary
(added comments for better understanding)
Line 33:
 
int neighbors(int c, int *p)
/*
@c cell
@p list of neighbours
@return amount of neighbours
*/
{
int i, j, n = 0;
Line 50 ⟶ 55:
 
void flood_fill(int c)
/*
fill all free cells around @c with “1” and write output to variable “flood”
@c cell
*/
{
int i, n[8], nei;
 
nei = neighbors(c, n);
for (i = 0; i < nei; i++) { // for all neighbours
if (board[n[i]] || flood[n[i]]) continue; // if cell is not free, choose another neighbour
 
flood[n[i]] = 1;
Line 71 ⟶ 80:
memset(flood, 0, sizeof(flood[0]) * w * h);
for (c = lowerbound + 1; c <= top; c++)
if (known[c]) flood_fill(known[c]); // mark all free cells around known cells
 
for (c = 0; c < w * h; c++)
if (!board[c] && !flood[c]) // if there are free cells which could not be reached from flood_fill
return 0;
 
1

edit