Conway's Game of Life: Difference between revisions

m
imported>Arakov
Line 5,588:
 
=={{header|Elena}}==
ELENA 56.0, using cellular library
<syntaxhighlight lang="elena">import extensions;
import system'threading;
import system'text;
import cellular;
 
Line 5,600 ⟶ 5,601:
sealed class Model
{
Space theSpace_space;
RuleSet theRuleSet_ruleSet;
bool started_started;
 
event Func<Space, object> OnUpdate : event;
constructor newRandomset(RuleSet transformSet)
{
theSpace_space := new IntMatrixSpace.allocate(maxY, maxX, randomSet);
 
theRuleSet_ruleSet := transformSet;
started_started := false
}
private onUpdate()
constructor newLoaded(RuleSet initSet, RuleSet transformSet)
{
OnUpdate.?(theSpace_space)
theSpace := IntMatrixSpace.allocate(maxY, maxX, initSet);
}
theRuleSet := transformSet;
started := false
}
private onUpdate()
{
OnUpdate.?(theSpace)
}
run()
{
if (started_started)
{
theSpace_space.update(theRuleSet_ruleSet)
}
else
{
started_started := true
};
self.onUpdate()
}
}
 
singleton gameOfLifeRuleSet : RuleSet
{
int proceed(Space s, int x, int y, ref int retVal)
{
int cell := s.at(x, y);
int number := s.LiveCell(x, y, 1); // NOTE : number of living cells around the self includes the cell itself
if (cell == 0 && number == 3)
{
retVal :=^ 1
}
else if (cell == 1 && (number == 4 || number == 3))
{
retVal :=^ 1
}
else
{
retVal :=^ 0
}
}
}
 
public extension presenterOp : Space
{
print()
{
console.setCursorPosition(0, 0);
int columns := self.Columns;
int rows := self.Rows;
auto for(int iline := 0,new i < rows, i += 1TextBuilder();
for(int i {:= 0, i < rows, i += 1)
{
for(int j := 0, j < columns, j += 1)
{line.clear();
for(int j := 0, j < columns, intj cell :+= self.at(i, j1);
{
int console.write((cell =:= 0)self.iifat("i, ","o")j);
};
line.write((cell == 0).iif(" ","o"));
console.writeLine()};
}
console.writeLine(line.Value)
}
{ }
}
}
 
Anonymous user