//Combo Checking public board CheckAllSquaresForCombo() //Identify comboable squares { ClearFlags(); int combosExisting = 0; for (int x = 0; x < board.Width; x++) { for (int y = 0; y < board.Height; y++) { for (int tempDir = 0; tempDir < dirCount; tempDir++) { boardStruct tempBoard = board.GetBoardStruct(); //Temp doesn't matter... Objects are reference types List <boardSquare> newMove = new List <boardSquare>(); foreach (boardSquare bs in RecurseComboCheck(x, y, (int)directions[tempDir, xCoordIndex], (int)directions[tempDir, yCoordIndex], tempBoard.StructCoreSquare[board.Get1DIndexFrom2D(x, y, board.Width)], tempBoard)) { newMove.Add(bs); foreach (boardSquare adjSq in CheckSquareForAdjacency(bs)) { newMove.Add(adjSq); } combosExisting++; //Debug.Log("Combos found so far : " + combosExisting); bs.Comboable = true; //10 million calls... why? bs.Destructable = true; } movesLists.Add(newMove); } } } return(board); }
public boardStruct GetBoardStruct() { boardStruct board = new boardStruct(); board.StructCoreSquare = coreSquares; board.TopStructCoreSquare = topSquares; board.LeftStructCoreSquare = leftSquares; board.BotStructCoreSquare = bottomSquares; board.RightStructCoreSquare = rightSquares; return(board); }
List <boardSquare> RecurseComboCheck(int x, int y, int dirX, int dirY, boardSquare originalSquare, boardStruct tempBoard, int counter, List <boardSquare> validSquares) { boardSquare nextSquare = tempBoard.StructCoreSquare[board.Get1DIndexFrom2D(x, y, board.Width)]; if (counter == 3) { //Debug.Log("Counter reached 3, returning true."); //board = existingBoard; return(validSquares); } else { //Check next space on board if ((x + dirX < board.Width && x + dirX >= 0) && (y + dirY < board.Height && y + dirY >= 0)) { if (CheckSquaresEqual(originalSquare, nextSquare)) { //Debug.Log("Gem " + x + ", " + y + " matches square " + originalSquare.gemX + ", " + originalSquare.gemY + "! Looking another square!"); counter += 1; //Debug.Log("Counter set to " + counter); validSquares.Add(nextSquare); //nextSquare.Targetable = true; return(RecurseComboCheck(x + dirX, y + dirY, dirX, dirY, originalSquare, tempBoard, counter, validSquares)); } //Debug.Log("Gems do not match. Counted " + counter + " matching gems."); //nextSquare.Targetable = false; validSquares.Clear(); return(validSquares); //Squares do not match } else { // Debug.Log("Recursion ended due to leaving board at square : " + x + ", " + y); //nextSquare.Targetable = false; validSquares.Clear(); return(validSquares); //Out of range } //return nextSquare.Targetable; } }
List <boardSquare> RecurseComboCheck(int x, int y, int dirX, int dirY, boardSquare originalSquare, boardStruct tempBoard, int counter, List <boardSquare> validSquares) { boardSquare nextSquare = tempBoard.StructCoreSquare[board.Get1DIndexFrom2D(x, y, board.Width)]; if (counter == 3) { return(validSquares); } else { //Check next space on board if ((x + dirX < board.Width && x + dirX >= 0) && (y + dirY < board.Height && y + dirY >= 0)) { if (CheckSquaresEqual(originalSquare, nextSquare)) { counter += 1; validSquares.Add(nextSquare); return(RecurseComboCheck(x + dirX, y + dirY, dirX, dirY, originalSquare, tempBoard, counter, validSquares)); } validSquares.Clear(); return(validSquares); //Squares do not match } else { validSquares.Clear(); return(validSquares); //Out of range } } }