//check no matches by default public BoardModel(int numTypes, int numRows, int numCols, int numMoves, int targetScore, int chainBaseScore) { this.numTypes = numTypes; this.numRows = numRows; this.numCols = numCols; this.numMoves = numMoves; this.targetScore = targetScore; this.chainBaseScore = chainBaseScore; tiles = new List <List <TileModel> >(numRows); for (int i = 0; i < numRows; i++) { // adds a row tiles.Add(new List <TileModel>(numCols)); // creating a 2D array for (int j = 0; j < numCols; j++) { TileModel t = new TileModel(i, j, Random.Range(0, numTypes)); // selecting a location for the tile to add //TODO avoid infinite loop here handling while (isMatch3Horizontalleft(i, j, t.type) || isMatch3VerticalDown(i, j, t.type)) { t.type = Random.Range(0, this.numTypes); // replacing so that no 3 tiles are similar at the start of the game } // adding elements in tiles tiles[i].Add(t); } } comparer = new TileOnBoardEqualityComparer(numRows, numCols); }
//check no matches by default public BoardModel(int numTypes, int numRows, int numCols, int numMoves, int targetScore, int chainBaseScore) { this.numTypes = numTypes; this.numRows = numRows; this.numCols = numCols; this.numMoves = numMoves; this.targetScore = targetScore; this.chainBaseScore = chainBaseScore; tiles = new List <List <TileModel> >(numRows); for (int i = 0; i < numRows; i++) { tiles.Add(new List <TileModel>(numCols)); for (int j = 0; j < numCols; j++) { TileModel t = new TileModel(i, j, Random.Range(0, numTypes)); int maxIters = this.numTypes * 100; int k = 0; while ((k < maxIters) && (isMatch3Horizontalleft(i, j, t.type) || isMatch3VerticalDown(i, j, t.type))) { t.type = Random.Range(0, this.numTypes); ++k; } if (k == maxIters) { Debug.LogError("Problem with design data supplied,please fix data"); } tiles[i].Add(t); } } comparer = new TileOnBoardEqualityComparer(numRows, numCols); }
//check no matches by default public BoardModel(int numTypes, int numRows, int numCols, int numMoves, int targetScore, int chainBaseScore) { this.numTypes = numTypes; this.numRows = numRows; this.numCols = numCols; this.numMoves = numMoves; this.targetScore = targetScore; this.chainBaseScore = chainBaseScore; tiles = new List <List <TileModel> >(numRows); for (int i = 0; i < numRows; i++) { tiles.Add(new List <TileModel>(numCols)); for (int j = 0; j < numCols; j++) { TileModel t = new TileModel(i, j, Random.Range(0, numTypes)); //TODo avoid infinite loop here handling while (isMatch3Horizontalleft(i, j, t.type) || isMatch3VerticalDown(i, j, t.type)) { t.type = Random.Range(0, this.numTypes); } tiles[i].Add(t); } } comparer = new TileOnBoardEqualityComparer(numRows, numCols); }