All files rule.js

100% Statements 49/49
100% Branches 8/8
100% Functions 5/5
100% Lines 49/49

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 504x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 336x 336x 75x 75x 144x 144x 75x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x  
class Rule {
  /** @member {number[]} */
  #birth = [];
 
  /** @member {number[]} */
  #survival = [];
 
  /**
   *
   * @param {string} ruleBS - MCell-style rule formatted as {Bb0...bm/Ss0...sn}
   *                          s.t. all b are unique, all s are unique, and 0 <= m,n < 9
   */
  constructor(ruleBS) {
    const bs = ruleBS.split('/', 2);
    let b = bs[0].substring(1);
    let s = bs[1].substring(1);
 
    this.#birth = b.split('').map((i) => parseInt(i, 10));
    this.#survival = s.split('').map((i) => parseInt(i, 10));
  }
 
  get birthCounts() {
    return this.#birth;
  }
 
  get survivalCounts() {
    return this.#survival;
  }
}
 
class WellKnownRules {
  static REPLICATOR = new Rule('B1357/S1357');
  static FREDKIN = new Rule('B1357/S02468');
  static SEEDS = new Rule('B2/S');
  static LIVE_FREE_OR_DIE = new Rule('B2/S0');
  static LIFE_WITHOUT_DEATH = new Rule('B3/S012345678');
  static FLOCK = new Rule('B3/S12');
  static MAZECTRIC = new Rule('B3/S1234');
  static MAZE = new Rule('B3/S12345');
  static GAME_OF_LIFE = new Rule('B3/S23');
  static TWO_BY_TWO = new Rule('B36/S125');
  static HIGH_LIFE = new Rule('B36/S23');
  static MOVE = new Rule('B368/S245');
  static DAY_AND_NIGHT = new Rule('B3678/34678');
  static DRY_LIFE = new Rule('B37/S23');
  static PEDESTRIAN_LIFE = new Rule('B38/S23');
}
 
export { Rule, WellKnownRules };