示例#1
0
 private char[][] CreateNextGeneration(SavedBoard board) {
     var newGen = new char[board.Layout.Length][];
     for (var yAxis = 0; yAxis < board.Layout.Length; yAxis++) {
         newGen[yAxis] = new char[board.Layout[0].Length];
         AddCellToNewGen(board, yAxis, newGen);
     }
     return newGen;
 }
示例#2
0
 private void AddCellToNewGen(SavedBoard board, int yAxis, char[][] newGen) {
     var neighbors = new char[3][];
     for (var xAxis = 0; xAxis < board.Layout[0].Length; xAxis++) {
         CreateArrayAroundCell(board, neighbors, yAxis, xAxis);
         newGen[yAxis][xAxis] = FindNextCellsNextState(neighbors);
         board.AliveCells += CheckIfStateChanged(board, yAxis, xAxis, newGen);
     }
 }
示例#3
0
 private bool CheckForBorders(SavedBoard board, int yAxis, int xAxis, int neighborY, int neighborX) {
     bool isCrossingTopBorder = neighborY + yAxis - 1 < 0;
     bool isCorssingBottomBorder = neighborY + yAxis > board.Layout.Length;
     bool isCrossingLeftBorder = neighborX + xAxis - 1 < 0;
     bool isCrossingRightBorder = neighborX + xAxis > board.Layout[0].Length;
     bool isNotInBorders = isCrossingTopBorder || isCorssingBottomBorder || isCrossingLeftBorder ||
                           isCrossingRightBorder;
     return isNotInBorders;
 }
示例#4
0
 private int CheckIfStateChanged(SavedBoard board, int yAxis, int xAxis, char[][] newGen) {
     char prevState = board.Layout[yAxis][xAxis];
     if (prevState == newGen[yAxis][xAxis]) {
         return 0;
     }
     if (prevState == 'X') {
         return -1;
     }
     return 1;
 }
示例#5
0
 private void CreateArrayAroundCell(SavedBoard board, char[][] neighbors, int yAxis, int xAxis) {
     for (var neighborY = 0; neighborY <= 2; neighborY++) {
         neighbors[neighborY] = new char[3];
         for (var neighborX = 0; neighborX <= 2; neighborX++) {
             bool isNotInBorders = CheckForBorders(board, yAxis, xAxis, neighborY, neighborX);
             if (isNotInBorders) {
                 neighbors[neighborY][neighborX] = ' ';
             } else {
                 neighbors[neighborY][neighborX] = board.Layout[neighborY + yAxis - 1][neighborX + xAxis - 1];
             }
         }
     }
 }
示例#6
0
 public void ChangeBoardState(SavedBoard board) {
     board.Generation++;
     board.Layout = CreateNextGeneration(board);
 }