summary refs log tree commit diff stats
path: root/tests/manyloc
Commit message (Collapse)AuthorAgeFilesLines
* made some tests greenAraq2014-09-213-39/+39
|
* further adaptationsAraq2014-08-297-22/+22
|
* renamed babelcmd to nimblecmd; config files are now nim.cfg; other renamingsAraq2014-08-296-0/+0
|
* some progress for jester+asyncAraq2014-06-278-0/+7503
|
* attempt to make some tests greenAraq2014-04-213-7/+3
|
* keine_schweine test is not platform dependentAraq2014-02-243-12/+16
|
* nil->discardAraq2014-02-151-2/+2
|
* the compiler can now deal with multiple modules of the same nameAraq2013-09-265-0/+32
|
* fixes #531Araq2013-07-2413-0/+662
|
* fixes --os:standaloneAraq2013-06-301-1/+3
|
* --os:standalone works againAraq2013-06-303-0/+25
|
* improvements for 'not nil' checkingAraq2013-06-131-2/+4
|
* manyloc test should be green againAraq2013-06-043-30/+22
|
* fixes #385Araq2013-06-031-0/+494
|
* revert new scope for 'if'Araq2013-05-022-0/+170
|
* bugfixes mostly JS relatedAraq2013-05-013-1/+2
|
* made some tests greenAraq2013-04-221-0/+1
|
* added manyloc test suite; --path now relative to project dir if not absoluteAraq2013-04-1349-0/+9271
|
* Fixed bug with xmltree.attrs when attributes have not been initialisedDominik Picheta2013-03-235-690/+0
| | | | yet.
* better error message when C compilation failsAraq2013-03-191-0/+1
|
* tester supports large testsAraq2013-03-185-0/+689
069bd7'>56ac343 ^
ee93710 ^
ee93710 ^
011cbe7 ^






56ac343 ^
011cbe7 ^










56ac343 ^
011cbe7 ^











56ac343 ^
011cbe7 ^
56ac343 ^

011cbe7 ^

56ac343 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
                                     
                                                 




                                 
 
                                                                                          
                                                      
                                                          

                        

                                                                                       
                                                                                          
                                                                  

                           

                                                                                                         


                   
 
                     
                                                                                                              

                             
                                                                    
                                                       



                                                                                                          

                                                                      
    
 
 











                                                                                       
 
 






                      
                           










                                    
                            











                                    
                           
 

                                                             

  
                          
function countNeighbors(grid, x, y) {
  // Define the offsets for the neighboring cells
  const neighborOffsets = [
      [-1, -1], [-1, 0], [-1, 1],
      [0, -1],           [0, 1],
      [1, -1],  [1, 0],  [1, 1]
  ];

  // Use reduce to iterate over the neighborOffsets and count the number of live neighbors
  return neighborOffsets.reduce((count, [dx, dy]) => {
      // Calculate the coordinates of the neighboring cell
      const nx = x + dx;
      const ny = y + dy;

      // Check if the neighboring cell is within the grid boundaries and if it is alive
      if (nx >= 0 && ny >= 0 && nx < grid.length && ny < grid[0].length && grid[nx][ny]) {
          // If the neighboring cell is alive, increment the count
          return count + 1;
      }

      // If the neighboring cell is not alive or is outside the grid boundaries, return the current count
      return count;
  }, 0);
}

function step(grid) {
  // Use map to iterate over each cell in the grid and calculate the next state based on the rules of the game
  return grid.map((row, x) =>
      row.map((cell, y) => {
          // Count the number of live neighbors for the current cell
          const neighbors = countNeighbors(grid, x, y);

          // Apply the rules of the game to determine the next state of the cell
          // If the cell has 3 live neighbors or has 2 live neighbors and is already alive, it stays alive
          // Otherwise, it becomes dead
          return neighbors === 3 || (neighbors === 2 && cell) ? 1 : 0;
      })
  );
}

function printGrid(grid) {
  grid.forEach(row => console.log(row.map(cell => cell ? '🟢' : '⚪️').join('')));
  console.log('\n');
}

function simulate(initial, steps) {
  let grid = initial;
  Array.from({ length: steps }).forEach(() => {
      printGrid(grid);
      grid = step(grid);
  });
}


const initialBoard = [
  [0, 1, 0],
  [0, 0, 1],
  [1, 1, 1],
  [0, 0, 0],
];

simulate(initialBoard, 10);

const rpentomino = [
  [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
  [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
];

// simulate(rpentomino, 10);

// big glider
const bigGlider = [
  [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
  [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
];

// simulate(bigGlider, 10);

const randomBoard = Array.from({ length: 22 }, () =>
  Array.from({ length: 22 }, () => Math.round(Math.random()))
);

simulate(randomBoard, 50);