GridState[,] getEmptyGrid(int x, int y)
 {
     GridState[,] grid = new GridState[x, y];
     for (int i = 0; i < grid.GetLength(0); i++) {
         for (int j = 0; j < grid.GetLength(1); j++) {
             grid[i, j] = GridState.FREE;
         }
     }
     return grid;
 }
Example #2
0
 void findField(GridState[,] grid, GridState state, out int x, out int y)
 {
     for (int i = 0; i < grid.GetLength(0); i++) {
         for (int j = 0; j < grid.GetLength(1); j++) {
             if (grid[i,j] == state) {
                 x = i;
                 y = j;
                 return;
             }
         }
     }
     x = 0;
     y = 0;
 }
Example #3
0
 void findRandomField(GridState[,] grid, GridState state, out int x, out int y)
 {
     List<Point2D> freeFields = new List<Point2D>();
     for (int i = 0; i < grid.GetLength(0); i++) {
         for (int j = 0; j < grid.GetLength(1); j++) {
             if (grid[i, j] == state) {
                 freeFields.Add(new Point2D(i, j));
             }
         }
     }
     if (freeFields.Count > 0) {
         Point2D point = freeFields[Random.Range(0, freeFields.Count - 1)];
         x = point.x;
         y = point.y;
     }
     else {
         x = 0;
         y = 0;
     }
 }