June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,137 @@
import extensions.
import cellular.
import system'routines.
import system'threading.
import system'text.
const int maxX = 48.
const int maxY = 28.
type listener_func = ListenerFunc.
limited class ListenerFunc
{
action eval space:space []
}
sealed class Model
{
space theSpace.
ruleset theRuleSet.
bool started.
listener_func event onUpdate :: theListener.
constructor newRandomset ruleset:transformSet
[
theSpace := IntMatrixSpace new int:maxY int:maxX ruleset:randomSet.
theRuleSet := transformSet.
started := false.
]
constructor newLoaded ruleset:initSet ruleset:transformSet
[
theSpace := IntMatrixSpace new int:maxY int:maxX ruleset:initSet.
theRuleSet := transformSet.
started := false.
]
$onUpdate
[
if ($nil != theListener)
[ theListener eval space:theSpace ].
]
init
[
$self $onUpdate.
]
run
[
if (started)
[ theSpace update ruleset:theRuleSet. ];
[ started := true. ].
$self $onUpdate.
]
}
const int DELAY = 50.
symbol testSet = ((0,1,0),
(0,1,0),
(0,1,0)).
class gameOfLifeRuleSet = BaseRuleSet::
{
proceed space:s int:x int:y vint:retVal
[
int cell := s getAt int:x int:y.
int number := s getLiveCell int:x int:y int:1. // NOTE : number of living cells around the self includes the cell itself
if ((cell == 0) && (number == 3))
[
retVal int := 1
];
if ((cell == 1) && ((number == 4) || (number == 3)))
[
retVal int := 1
];
[
retVal int := 0
]
]
}.
extension space presenterOp
{
print
[
console setCursorPosition int:0 int:0.
int columns := self columns.
int rows := self rows.
int i := 0.
int j := 0.
while (i < rows)
[
j := 0.
while (j < columns)
[
int cell := self getAt int:i int:j.
console write((cell == 0)iif(" ","o")).
j := j + 1.
].
i := i + 1.
console writeLine.
].
]
}
program =
[
console clear.
var model := Model newRandomset ruleset:gameOfLifeRuleSet.
model onUpdate listener_func(&space:sp)[ sp print ].
until (console isKeyAvailable)
[
model run.
thread sleep:DELAY.
].
console readChar.
].