Conway's Game of Life: Difference between revisions
Content added Content deleted
imported>Arakov |
No edit summary |
||
Line 7,283: | Line 7,283: | ||
to_int_board board |
to_int_board board |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic"> |
|||
Short a(4, 4), c(4, 4) // Array of cells and working copy |
|||
void local fn initialize |
|||
Short x, y |
|||
// Fill three cells |
|||
a(1, 2) = 1 : a(2, 2) = 1 : a(3, 2) = 1 |
|||
// Draw the array |
|||
for y = 0 to 4 : for x = 0 to 4 |
|||
print a(x, y); |
|||
next : print : next : print |
|||
end fn |
|||
void local fn calculate |
|||
Short x, y, dx, dy, n |
|||
// Calculate next generation on temporary board |
|||
for y = 1 to 3 : for x = 1 to 3 // Not the border cells |
|||
c(x, y) = 0 |
|||
n = -a(x, y) // Don't count center cell |
|||
for dy = -1 to 1 : for dx = -1 to 1 |
|||
n += a(x + dx, y + dy) // Count the neighbours |
|||
next : next |
|||
c(x, y) = ( n == 3 ) or ( n == 2 and a(x, y) ) // Rule |
|||
next : next |
|||
// Copy temp array to actual array and draw |
|||
for y = 0 to 4 : for x = 0 to 4 |
|||
a(x, y) = c(x, y) // Copy |
|||
print a(x, y); // Draw |
|||
next : print : next : print |
|||
end fn |
|||
fn initialize |
|||
fn calculate |
|||
fn calculate |
|||
handleevents |
|||
</syntaxhighlight> |
|||
<pre> |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |