Beispiel #1
0
        private Cell[] EvaluateBottomLine()
        {
            Cell[] newline = new Cell[dimension];
              Cell[] currentLine = gameState[0];
              Cell[] secondLine = gameState[1];

              for (int j = 0; j < dimension; j++) //iterer ud af x aksen
              {
            Cell origValue = currentLine[j];

            //første element i nederste række evalueres
            if (j == 0)
            {
              newline[j] = origValue.Evaluate(new Cell[]{currentLine[0], secondLine[1], currentLine[1]});
            }

            //sidste element i nederste række evalueres
            else if (j == dimension - 1)
            {
              newline[j] = origValue.Evaluate(new Cell[]{secondLine[dimension - 1], secondLine[dimension - 2], currentLine[dimension - 2]});
            }

            //evaluere resten
            else
            {
              newline[j] = origValue.Evaluate(new Cell[]{currentLine[j - 1], currentLine[j + 1], secondLine[j - 1], secondLine[j], secondLine[j + 1]});
            }
              }
              return newline;
        }
Beispiel #2
0
        public Cell Evaluate(Cell[] neighbors)
        {
            int sumOfNeighbors = neighbors.Sum(c => c.Value);
              switch (cellstate)
              {
            case CellState.Alive:
              if (sumOfNeighbors < 2)
            return DeadCell;

              if (sumOfNeighbors < 4)
            return AliveCell;

              return DeadCell;

            case CellState.Dead:
              return sumOfNeighbors == 3 ? AliveCell : DeadCell;
              }

              return null;
        }
Beispiel #3
0
        public Life(int width, int height, float tick)
        {
            if (width <= 10 || height <= 10) throw new ArgumentOutOfRangeException("You need to give life a chance choose bigger numbers");

            grid = new Cell[height,width];
            newGrid = new Cell[height, width];

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    grid[i, j] = new Cell();
                    newGrid[i, j] = new Cell();
                }
            }

            _width = width - 1;
            _height = height - 1;
            _tick = tick;
        }
Beispiel #4
0
        private Cell[] EvaluateMiddelLines(int rowIndex)
        {
            Cell[] newline = new Cell[dimension];
              Cell[] currentLine = gameState[rowIndex];
              Cell[] lineBelow = gameState[rowIndex - 1];
              Cell[] lineAbove = gameState[rowIndex + 1];
              for (int j = 0; j < dimension; j++) //iterer ud af x aksen
              {
            Cell origValue = currentLine[j];

            //første element i rækken evalueres
            if (j == 0)
            {
              newline[0] = origValue.Evaluate(new Cell[]{lineBelow[0], lineBelow[1], currentLine[1], lineAbove[1], lineAbove[0]});
            }

            //sidste element i rækken evalueres
            else if (j == dimension - 1)
            {
              newline[dimension - 1] = origValue.Evaluate(new Cell[]{lineBelow[j], lineBelow[j - 1], currentLine[j - 1], lineAbove[j - 1], lineAbove[j]});
            }

            //evaluere resten
            else
            {
              newline[j] = origValue.Evaluate(new Cell[]{lineBelow[j - 1], lineBelow[j], lineBelow[j + 1], currentLine[j + 1], lineAbove[j + 1], lineAbove[j], lineAbove[j - 1], currentLine[j - 1]});
            }
              }
              return newline;
        }
Beispiel #5
0
 private void purgeNewGrid()
 {
     for (int i = 0; i < _height; i++)
     {
         for (int j = 0; j < _width; j++)
         {
             newGrid[i, j] = new Cell();
         }
     }
 }