示例#1
0
 //returns the neighborState array in the same format as the rules
 public int getNeighborhoodState(Cell[,] grid)
 {
     setNeighbors(grid);
     String neighborhoodState = Convert.ToInt32(this.currentState).ToString() +
         Convert.ToInt32(neighbors[1].getCurrentState()).ToString() +
         Convert.ToInt32(neighbors[2].getCurrentState()).ToString() +
         Convert.ToInt32(neighbors[3].getCurrentState()).ToString() +
         Convert.ToInt32(neighbors[4].getCurrentState()).ToString();
     return Convert.ToInt32(neighborhoodState);
 }
示例#2
0
        //sets up the neighbors of the cells and puts them into
        //the neighborState array
        public void setNeighbors(Cell[,] grid)
        {
            //handle toporidal thing
            int leftOfX = xPosition - 1;
            int rightOfX = xPosition + 1;
            int bottomOfY = yPosition + 1;
            int topOfY = yPosition - 1;

            if (leftOfX == CellularAutomataConstants.BELOW_GRID)
                leftOfX = grid.GetUpperBound(0);
            if (rightOfX == CellularAutomataConstants.GRID_WIDTH)
                rightOfX = 0;
            if (bottomOfY == CellularAutomataConstants.GRID_HEIGHT)
                bottomOfY = 0;
            if (topOfY == CellularAutomataConstants.BELOW_GRID)
                topOfY = grid.GetUpperBound(1);

            neighbors[0] = this;
            neighbors[1] = grid[xPosition, topOfY];
            neighbors[2] = grid[rightOfX, yPosition];
            neighbors[3] = grid[xPosition, bottomOfY];
            neighbors[4] = grid[leftOfX, yPosition];
        }