Conway's game of life

Paul via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 3 06:25:51 PST 2015


On Tuesday, 3 February 2015 at 14:01:51 UTC, bearophile wrote:
> Paul:
>
>> 	enum WORLDSIZE = 20;
>> 	enum INITIALPOP = 70;	//experimental
>> 	enum DEAD = 0;
>> 	enum ALIVE = 1;
>
> D enums don't need to be ALL UPPERCASE :-)
>
>
>> 	int world[WORLDSIZE][WORLDSIZE];
>
> Don't forget to compile with warnings active (it's a design 
> error of the D compiler to have them disabled by default).
>
>
>> 	foreach(i; 0..INITIALPOP){
>
> It's less bug-prone to make that index immutable:
>
>         foreach(immutable i; 0 .. initialPop) {
>
> Bye,
> bearophile

Thanks for the comments. The all-caps enums is just habit. I 
don't get any warnings using the dmd -w switch, I take it you 
mean use int[size][size] var instead?

Regarding the immutable loop variable, I've conditioned myself 
never to interfere with loop control values - it gives me the 
same bad feeling as goto/continue (and to a lesser extent 
'break').




More information about the Digitalmars-d-learn mailing list