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
e820ec1905264ab87ef541c08f96d687aa8a3901
parent
3755e2417dd6fff84fa40809755d54c521535865
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-01-02 10:49
detect cycles

Diffstat

M scenarios/03_symbiosis.js 2 +-
M scenarios/04_glider_01.js 2 +-
M scenarios/05_glider_02.js 2 +-
M scenarios/09_gun.js 2 +-
M src/constants.js 2 ++
M src/logic.js 12 ++++++++++++

6 files changed, 18 insertions, 4 deletions


diff --git a/scenarios/03_symbiosis.js b/scenarios/03_symbiosis.js

@@ -8,6 +8,6 @@ export default {
    8     8     "board": scenBoard,
    9     9     "winCondition": function(state) {
   10    10         if(logic.countPlayer(state.game.board, 3) === 0) return false;
   11    -1         if (state.game.turnCounter >= 50) return true;
   -1    11         if (state.game.turnCounter >= 50 || logic.hasCycle(state.game.board)) return true;
   12    12     },
   13    13 }
   13    13 
\ No newline at end of file

diff --git a/scenarios/04_glider_01.js b/scenarios/04_glider_01.js

@@ -12,7 +12,7 @@ export default {
   12    12         if (logic.countPlayer(state.game.board, 2) === 0) {
   13    13             return true;
   14    14         }
   15    -1         if (state.game.turnCounter >= 300) {
   -1    15         if (state.game.turnCounter >= 300 || logic.hasCycle(state.game.board)) {
   16    16             return true;
   17    17         }
   18    18     },

diff --git a/scenarios/05_glider_02.js b/scenarios/05_glider_02.js

@@ -12,7 +12,7 @@ export default {
   12    12         if (logic.countPlayer(state.game.board, 2) === 0) {
   13    13             return true;
   14    14         }
   15    -1         if (state.game.turnCounter >= 300) {
   -1    15         if (state.game.turnCounter >= 300 || logic.hasCycle(state.game.board)) {
   16    16             return true;
   17    17         }
   18    18     },

diff --git a/scenarios/09_gun.js b/scenarios/09_gun.js

@@ -9,7 +9,7 @@ export default {
    9     9         if (logic.countPlayer(state.game.board, 3) === 0) {
   10    10             return false;
   11    11         }
   12    -1         if (state.game.turnCounter >= 300) {
   -1    12         if (state.game.turnCounter >= 300 || logic.hasCycle(state.game.board)) {
   13    13             return true;
   14    14         }
   15    15     },

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

@@ -9,3 +9,5 @@ export const height = 40;
    9     9 export const width = 60;
   10    10 
   11    11 export const playTimeout = 200;
   -1    12 
   -1    13 export const maxCycleLength = 3;

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

@@ -1,4 +1,5 @@
    1     1 import * as constants from './constants.js';
   -1     2 import {clone} from './utils.js';
    2     3 
    3     4 export const setupBoard = function() {
    4     5     const board = [];
@@ -100,4 +101,15 @@ export const countPlayer = function(board, player) {
  100   101         }
  101   102     }
  102   103     return count;
   -1   104 };
   -1   105 
   -1   106 export const hasCycle = function(board) {
   -1   107     let futureBoard = clone(board);
   -1   108     for (let i = 0; i < constants.maxCycleLength; i++) {
   -1   109         calculateNextGen(futureBoard);
   -1   110         if (compareBoards(board, futureBoard)) {
   -1   111             return i + 1;
   -1   112         }
   -1   113     }
   -1   114     return 0;
  103   115 }
  103   115 
\ No newline at end of file