public override LifeNode ExpandUniverse() { LeafLifeNode emptySpace = LeafLifeNode.CreateNode(0); // Subnodes for nw, ne, sw, se LeafLifeNode[] subNodes = new LeafLifeNode[] { emptySpace, emptySpace, emptySpace, emptySpace }; // New nw will have old nw value in its se corner if ((this.bits & 0x01) == 0x01) { subNodes[0] = LeafLifeNode.CreateNode(0x08); } // New ne will have old ne in its sw corner if ((this.bits & 0x02) == 0x02) { subNodes[1] = LeafLifeNode.CreateNode(0x04); } if ((this.bits & 0x04) == 0x04) { subNodes[2] = LeafLifeNode.CreateNode(0x02); } if ((this.bits & 0x08) == 0x08) { subNodes[3] = LeafLifeNode.CreateNode(0x01); } return(LifeNode.CreateNode(subNodes[0], subNodes[1], subNodes[2], subNodes[3])); }
public static LifeNodeBase EmptySpace(int dimension) { Debug.Assert(dimension > 1); Debug.Assert(Utils.IsPowerOfTwo(dimension)); if (dimension == 2) { return(LeafLifeNode.CreateNode(0)); } LifeNodeBase next = EmptySpace(dimension / 2); return(LifeNode.CreateNode(next, next, next, next)); }
public LifeNodeBase TemporaryCenterCenterNode() { LifeNodeBase retval = null; if (this.NW.IsOneStepLargerThanLeaf) { bool nwbit = this.nw.SE.IsAlive(1, 1); bool nebit = this.ne.SW.IsAlive(0, 1); bool swbit = this.sw.NE.IsAlive(1, 0); bool sebit = this.se.NW.IsAlive(0, 0); retval = LeafLifeNode.CreateNode(nwbit, nebit, swbit, sebit); } else { retval = LifeNode.CreateNode(this.nw.SE.SE, this.ne.SW.SW, this.sw.NE.NE, this.se.NW.NW); } return(retval); }
// Create new LifeNode from central bits of nw, ne, sw, se public static LifeNodeBase CreateCenterNode(LifeNodeBase nw, LifeNodeBase ne, LifeNodeBase sw, LifeNodeBase se) { LifeNodeBase retval = null; if (nw.IsLeaf) { bool nwsebit = nw.IsAlive(1, 1); bool neswbit = ne.IsAlive(0, 1); bool swnebit = sw.IsAlive(1, 0); bool senwbit = se.IsAlive(0, 0); retval = LeafLifeNode.CreateNode(nwsebit, neswbit, swnebit, senwbit); } else { retval = LifeNode.CreateNode(nw.SE, ne.SW, sw.NE, se.NW); } return(retval); }
// Given two nodes, n and s, pull out these bits // XX|XX|XX|XX // XX|XX|XX|XX // XX|XX|XX|XX // XX|NW|NE|XX //------------- // XX|SW|SE|XX // XX|XX|XX|XX // XX|XX|XX|XX // XX|XX|XX|XX public static LifeNodeBase TemporaryCenterYNode(LifeNodeBase n, LifeNodeBase s) { Debug.Assert(n.Dimension == s.Dimension); LifeNodeBase retval = null; if (n.IsOneStepLargerThanLeaf) { bool nwbit = n.SW.IsAlive(1, 1); bool nebit = n.SE.IsAlive(0, 1); bool swbit = s.NW.IsAlive(1, 0); bool sebit = s.NE.IsAlive(0, 0); retval = LeafLifeNode.CreateNode(nwbit, nebit, swbit, sebit); } else { retval = LifeNode.CreateNode(n.SW.SE, n.SE.SW, s.NW.NE, s.NE.NW); } return(retval); }
// Given two nodes, w and e, pull out these bits // XX|XX|XX|XX||XX|XX|XX|XX // XX|XX|XX|NW||NE|XX|XX|XX // XX|XX|XX|SW||SE|XX|XX|XX // XX|XX|XX|XX||XX|XX|XX|XX public static LifeNodeBase TemporaryCenterXNode(LifeNodeBase w, LifeNodeBase e) { Debug.Assert(w.Dimension == e.Dimension); LifeNodeBase retval = null; if (w.IsOneStepLargerThanLeaf) { bool nwbit = w.NE.IsAlive(1, 1); bool nebit = e.NW.IsAlive(0, 1); bool swbit = w.SE.IsAlive(1, 0); bool sebit = e.SW.IsAlive(0, 0); retval = LeafLifeNode.CreateNode(nwbit, nebit, swbit, sebit); } else { retval = LifeNode.CreateNode(w.NE.SE, e.NW.SW, w.SE.NE, e.SW.NW); } return(retval); }
public static LeafLifeNode CreateNode(bool nw, bool ne, bool sw, bool se) { int bits = 0; if (nw) { bits++; } if (ne) { bits += 0x02; } if (sw) { bits += 0x04; } if (se) { bits += 0x08; } return(LeafLifeNode.CreateNode(bits)); }
private LeafLifeNode calcNewLeaf() { Debug.Assert(this.IsOneStepLargerThanLeaf); newLeafs++; int newBits = 0; if (this.calcNewCell(1, 1)) { newBits += 1; } if (this.calcNewCell(2, 1)) { newBits += 2; } if (this.calcNewCell(1, 2)) { newBits += 4; } if (this.calcNewCell(2, 2)) { newBits += 8; } return(LeafLifeNode.CreateNode(newBits)); }
public static LifeNodeBase RandomSpace(int dimension) { return(InitSpace(dimension, () => LeafLifeNode.CreateNode(randomGenerator.Next(15)))); }