예제 #1
0
 /// <summary>
 /// Initialize the cell grid array
 /// </summary>
 private void InitializeCells()
 {
     // Create 2D cell array and initialize its elements
     cells = new Cell[COLS, ROWS];
     GridLoopParallel((x, y) =>
     {
         cells[x, y] = new Cell(this, new IVec2(x, y));
     });
 }
예제 #2
0
        /// <summary>
        /// Execute the automata on every cell
        /// </summary>
        /// <param name="rule">The rule function</param>
        private void RunAutomata(Cell.RuleDelegate rule, bool randomize)
        {
            // Compute the next state for each cell concurrently,
            // do not apply yet
            GridLoopParallel((x, y) =>
            {
                cells[x, y].ComputeNextState(rule, randomize);
            });

            // Apply the temp. states after computation is complete
            GridLoop((x, y) =>
            {
                cells[x, y].ApplyTempState();
            });
        }
예제 #3
0
        /// <summary>
        /// Gets the cell that is a neighbor to the specified cell
        /// </summary>
        /// <param name="cell">The cell for which to find a neighbor</param>
        /// <returns>The neighbor at the specified offset from the cell</returns>
        public Cell GetNeighborFor(Cell cell, int offsetX, int offsetY)
        {
            // Obtain the 'world wrapped' cell coordinates
            int wrappedX = Utility.WrapModulo(cell.position.x + offsetX, CellGrid.COLS);
            int wrappedY = Utility.WrapModulo(cell.position.y + offsetY, CellGrid.ROWS);

            // Obtain the cell
            return cells[wrappedX, wrappedY];
        }