ZenScript main repository
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930
  1. public class Cell {
  2. public var alive as bool;
  3. private var row as usize;
  4. private var column as usize;
  5. public this(row as usize, column as usize) {
  6. this(row, column, false);
  7. }
  8. public this(row as usize, column as usize, alive as bool) {
  9. this.row = row;
  10. this.column = column;
  11. this.alive = alive;
  12. }
  13. public getCellNextTick(currentGrid as ConwayGrid) as Cell {
  14. //+2 because upperbound exclusive
  15. var range = currentGrid[(row - 1) .. (row + 2), (column - 1) .. (column + 2)];
  16. var aliveCellsIn3x3Grid = range.filter(element => element.alive).length;
  17. if(!alive) {
  18. return new Cell(row, column, aliveCellsIn3x3Grid == 3);
  19. }
  20. //2. Any live cell with two or three live neighbours lives on to the next generation.
  21. return new Cell(row, column, aliveCellsIn3x3Grid == 3 || aliveCellsIn3x3Grid == 4);
  22. }
  23. }