Have a closer look at your logic operations:
neighbours(row,col)==2||3
which is not an error, but it does not do what you think it does!. That line is actually equivalent to this (note the grouping parentheses that I added for clarity):
(neighbours(row,col)==2) || 3
which because all non-zero values are considered true is equivalent to
(neighbours(row,col)==2) || true
which is clearly equivalent to
which is equivalent to
Your mistake was to ignore the clearly documented operator precedence, which states clearly the priorities of the two operators that you are using: "8. Less than (<), less than or equal to (<=), greater than (>), greater than or equal to (>=), equal to (==), not equal to (~=)"
...
"12. Short-circuit OR ()"
TIP: check your code as you write it. Read the documentation for each operation that you are using. Do not move on to the next line until you have tested and confirmed that the line does what you need it to do.
Best Answer