game-of-death

antagonistic game of life  https://xi.github.io/game-of-death/
git clone https://git.ce9e.org/game-of-death.git

commit
3755e2417dd6fff84fa40809755d54c521535865
parent
7f7beea489b4696df2ae1063a68abad135ea0210
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-01-02 10:30
split calculateNextGen in board-logic and state-logic

Diffstat

M src/index.js 2 +-
M src/logic.js 11 +++++++----

2 files changed, 8 insertions, 5 deletions


diff --git a/src/index.js b/src/index.js

@@ -39,7 +39,7 @@ const play = function() {
   39    39             state.game.playing = false;
   40    40         }
   41    41     }
   42    -1     logic.calculateNextGen(state);
   -1    42     logic.step(state);
   43    43     render();
   44    44     const speed = document.querySelector('[name="speed"]').value;
   45    45     const timeout = 2000 * Math.pow(0.95, speed);

diff --git a/src/logic.js b/src/logic.js

@@ -11,9 +11,7 @@ export const setupBoard = function() {
   11    11     return board;
   12    12 };
   13    13 
   14    -1 export const calculateNextGen = function(state) {
   15    -1     state.game.turnCounter++;
   16    -1     const board = state.game.board;
   -1    14 export const calculateNextGen = function(board) {
   17    15     const calcBoard = [];
   18    16 
   19    17     // Calculate every player seperatly
@@ -54,6 +52,11 @@ export const calculateNextGen = function(state) {
   54    52             }
   55    53         }
   56    54     }
   -1    55 };
   -1    56 
   -1    57 export const step = function(state) {
   -1    58     state.game.turnCounter++;
   -1    59     calculateNextGen(state.game.board);
   57    60 
   58    61     // Scenariostuff
   59    62     if (state.game.winCondition) {
@@ -63,7 +66,7 @@ export const calculateNextGen = function(state) {
   63    66             state.game.playing = false;
   64    67         }
   65    68     }
   66    -1 };
   -1    69 }
   67    70 
   68    71 const getFriendlyNeighbors = function(board, x, y, p){
   69    72     let count = 0;