Re: Conway's game of life

2015-02-03 Thread Paul via Digitalmars-d-learn
On Monday, 2 February 2015 at 16:58:43 UTC, bearophile wrote: The quality of the D GC is not important for a simple Life implementation, you just need two arrays. Here's my 30 minute sandwich-break version, sorry it's not very arractive 'D'... import std.stdio; import std.random; void

Re: Conway's game of life

2015-02-03 Thread Paul via Digitalmars-d-learn
On Tuesday, 3 February 2015 at 13:35:37 UTC, Paul wrote: On Monday, 2 February 2015 at 16:58:43 UTC, bearophile wrote: The quality of the D GC is not important for a simple Life implementation, you just need two arrays. Here's my 30 minute sandwich-break version, sorry it's not very

Re: Conway's game of life

2015-02-03 Thread Paul via Digitalmars-d-learn
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

Re: Conway's game of life

2015-02-03 Thread bearophile via Digitalmars-d-learn
Paul: Regarding the immutable loop variable, I've conditioned myself never to interfere with loop control values But adding immutable you don't risk modifying the variable by mistake. It's another design mistake of D. Variables (like foreach loop indexes) must be immutable by default

Re: Conway's game of life

2015-02-03 Thread bearophile via Digitalmars-d-learn
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

Re: Conway's game of life

2015-02-02 Thread FG via Digitalmars-d-learn
On 2015-02-02 at 12:23, FG wrote: Cell(0,3) is not a neighbour bit fits the (diff1 == 1 || diff2 == 1) criterion. s/bit/but/

Re: Conway's game of life

2015-02-02 Thread FG via Digitalmars-d-learn
Bloody Thunderbird has sent a reply to the OP and not to the NG. On 2015-02-02 at 11:45, gedaiu wrote: I don't think that the line of code is wrong. If use the function will check for neighbours only on diagonals. Having || allows the search on the vertical and horizontal axis and diagonals.

Re: Conway's game of life

2015-02-02 Thread gedaiu via Digitalmars-d-learn
Uf... you are right! I've fixed it. Thanks! On Monday, 2 February 2015 at 11:23:17 UTC, FG wrote: Bloody Thunderbird has sent a reply to the OP and not to the NG. On 2015-02-02 at 11:45, gedaiu wrote: I don't think that the line of code is wrong. If use the function will check for

Re: Conway's game of life

2015-02-02 Thread gedaiu via Digitalmars-d-learn
I don't think that the line of code is wrong. If use the function will check for neighbours only on diagonals. Having || allows the search on the vertical and horizontal axis and diagonals. There are some tests that check the function: unittest { CellList world = [ Cell(0,0), Cell(0,1),

Re: Conway's game of life

2015-02-02 Thread gedaiu via Digitalmars-d-learn
It's true that I have to change that function. Thanks for the notice! Why do you think that D's GC is crap? On Sunday, 1 February 2015 at 21:54:43 UTC, Foo wrote: On Sunday, 1 February 2015 at 21:00:07 UTC, gedaiu wrote: Hi, I implemented Conway's game of life in D. What do you think

Re: Conway's game of life

2015-02-02 Thread bearophile via Digitalmars-d-learn
gedaiu: https://github.com/gedaiu/Game-Of-Life-D A bare-bones implementation: http://rosettacode.org/wiki/Conway%27s_Game_of_Life#Faster_Version The quality of the D GC is not important for a simple Life implementation, you just need two arrays. Bye, bearophile

Re: Conway's game of life

2015-02-01 Thread Tobias Pankrath via Digitalmars-d-learn
1. I prefer alias CellList = Cell[]; over alias Cell[] CellList; 2. Do you really need to create a complete new CellList for every single removal? If so, you'd know the size of the new list in advance and can allocate it directly at the correct size. I get the impression that you think

Re: Conway's game of life

2015-02-01 Thread FG via Digitalmars-d-learn
On 2015-02-01 at 22:00, gedaiu wrote: I implemented Conway's game of life in D. I think you are playing a different game here. /// Count cell neighbours long neighbours(Cell myCell, CellList list) { long cnt; foreach(cell; list) { auto diff1 = abs(myCell.x

Re: Conway's game of life

2015-02-01 Thread Foo via Digitalmars-d-learn
On Sunday, 1 February 2015 at 21:00:07 UTC, gedaiu wrote: Hi, I implemented Conway's game of life in D. What do you think that I can improve to this program to take advantage of more D features? https://github.com/gedaiu/Game-Of-Life-D Thanks, Bogdan For each remove you create a new array.

Re: Conway's game of life

2015-02-01 Thread data man via Digitalmars-d-learn
On Sunday, 1 February 2015 at 21:00:07 UTC, gedaiu wrote: Hi, I implemented Conway's game of life in D. What do you think that I can improve to this program to take advantage of more D features? https://github.com/gedaiu/Game-Of-Life-D Thanks, Bogdan If the subject of the game Life is