void reverseTokens(lookDirection theWantedDirection) { // FOR CALCULATE REVERSE int indexCaseCheckHorizontal = 0; int indexCaseCheckVertical = 0; //lookDirection theWantedDirection = lookDirection.right; switch (theWantedDirection) { case lookDirection.right: //int nextCaseCheck = theField[theRow,incre + 1]; indexCaseCheckHorizontal = +1; break; case lookDirection.left: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckHorizontal = -1; break; case lookDirection.up: //int nextCaseCheck = theField[theRow,incre + 1]; indexCaseCheckVertical = +1; break; case lookDirection.down: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckVertical = -1; break; //Diagonal case lookDirection.diagUpRight: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckHorizontal = +1; indexCaseCheckVertical = +1; break; case lookDirection.diagUpLeft: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckHorizontal = -1; indexCaseCheckVertical = +1; break; case lookDirection.diagDownRight: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckHorizontal = +1; indexCaseCheckVertical = -1; break; case lookDirection.diagDownLeft: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckHorizontal = -1; indexCaseCheckVertical = -1; break; } //Clear it before use scannedTokensCoord.Clear(); //Get the number of rows int theNumRows = (theField.Length / 8); //We set the rows for (int theRow = 0; theRow < theNumRows; theRow++) { //We check each entry for (int incre = 0; incre < 8; incre++) { //print ("&&: " + theTileNames[theRow, incre]); //Check for the location of the newest token if (theTileNames[theRow, incre] == newTokenLocation) { //print ("We got the location of the new TOKEN " + newTokenLocation); ////////////////////////// //<!> Safety ////////////////////////// //Its a good patch if ((theRow + indexCaseCheckVertical) < 0 || (theRow + indexCaseCheckVertical) > 7) { indexCaseCheckVertical = 0; //print ("ROW UNDER 0 "); } if ((incre + indexCaseCheckHorizontal) < 0 || (incre + indexCaseCheckHorizontal) > 7) { indexCaseCheckHorizontal = 0; //print ("INCRE UNDER 0 "); } // print ("AFTERPATCH: " + theWantedDirection +" ### V: "+ (theRow + indexCaseCheckVertical) +" ### H: "+ (incre + indexCaseCheckHorizontal)); ////////////////////////// //Its a good patch ////////////////////////// //We start looking on its right if (theField[theRow + indexCaseCheckVertical, incre + indexCaseCheckHorizontal] == 0) { //print(" Nothing on the " + theWantedDirection+" side!!!! " + theField[theRow + indexCaseCheckVertical, incre + indexCaseCheckHorizontal] + " " + theTileNames[theRow + indexCaseCheckVertical, incre +indexCaseCheckHorizontal ] ); } else { //If there is something we check what it is //print(" There is something: " + theWantedDirection+" side!!!! " + theField[theRow + indexCaseCheckVertical, incre + indexCaseCheckHorizontal] + " " + theTileNames[theRow + indexCaseCheckVertical, incre +indexCaseCheckHorizontal ] ); //If int the position we found and opponenent token we raise the scope and look for the next position if (theField[theRow + indexCaseCheckVertical, incre + indexCaseCheckHorizontal] == opponentSlctColor) { ////////////////////////// //<!> Safety ////////////////////////// //print (); /*if((incre + pullTempHorizontal) > 7 || (incre + pullTempHorizontal) < 0){ * * break; * print ("H BIGGER THAN 8"); * pullTempHorizontal = 0; * } * * if((theRow + pullTempVertical) > 7 || (theRow + pullTempVertical) < 0){ * * break; * print ("V BIGGER THAN 8"); * pullTempVertical = 0; * } */ ////////////////////////// //Its a good patch ////////////////////////// int pullTempVertical = indexCaseCheckVertical; int pullTempHorizontal = indexCaseCheckHorizontal; while (theField[theRow + pullTempVertical, incre + pullTempHorizontal] != 0) { //We check if tis the same color as the current player if (theField[theRow + pullTempVertical, incre + pullTempHorizontal] == playerSlctColor) { //We pull out the last Token info until none is left //print ("<X> pull me out: " + theField[theRow + pullTempVertical, incre + pullTempHorizontal] + " " + theTileNames[theRow + pullTempVertical, incre +pullTempHorizontal ]); } //We raise the scope and check what is beyond that. pullTempHorizontal += indexCaseCheckHorizontal; pullTempVertical += indexCaseCheckVertical; ////////////////////////// //<!> Safety ////////////////////////// //print (); if ((incre + pullTempHorizontal) > 7 || (incre + pullTempHorizontal) < 0) { pullTempHorizontal = 0; //print ("H BIGGER THAN 8"); break; } if ((theRow + pullTempVertical) > 7 || (theRow + pullTempVertical) < 0) { pullTempVertical = 0; //print ("V BIGGER THAN 8"); break; } ////////////////////////// //Its a good patch ////////////////////////// } //We raise the scope and check what is beyond that. //indexCaseCheckHorizontal += indexCaseCheckHorizontal; //print ("INSVESTIGATE MORE!!! SCOPE: " + (theRow + indexCaseCheckVertical) + " " + (incre + indexCaseCheckHorizontal) + " " + theTileNames[theRow + indexCaseCheckVertical, incre + indexCaseCheckHorizontal] ); //print ("<%> V: " + (theRow + indexCaseCheckVertical) + " H: " + (incre + indexCaseCheckHorizontal)); //print ("== V: " + (theRow + indexCaseCheckVertical) + " H: " + (incre + indexCaseCheckHorizontal)); //print ("== WWW: " + theTileNames[theRow + indexCaseCheckVertical, incre + indexCaseCheckHorizontal] + " " + theField[theRow + indexCaseCheckVertical, incre + indexCaseCheckHorizontal] ); int anotherVertical = indexCaseCheckVertical; int anotherHorizontal = indexCaseCheckHorizontal; /*scannedTokenValue.Add(theField[theRow + anotherVertical, incre + anotherHorizontal]); * scannedTokensCoord.Add(theTileNames[theRow + anotherVertical, incre + anotherHorizontal]); */ //We check until we find an empty space || Or until we change rows. while (theField[theRow + anotherVertical, incre + anotherHorizontal] != 0) { //print ("entry: " + theTileNames[theRow + anotherVertical, incre + anotherHorizontal] + " " + theField[theRow + anotherVertical, incre + anotherHorizontal]); scannedTokensCoord.Add(theTileNames[theRow + anotherVertical, incre + anotherHorizontal]); scannedTokenValue.Add(theField[theRow + anotherVertical, incre + anotherHorizontal]); if (theField[theRow + anotherVertical, incre + anotherHorizontal] == playerSlctColor) { //print("WE stop at " + theTileNames[theRow + anotherVertical, incre + anotherHorizontal]); //We remove the last entry scannedTokensCoord.Remove(theTileNames[theRow + anotherVertical, incre + anotherHorizontal]); //If the last entry is the opponent we clear this up if (theField[theRow + anotherVertical, incre + anotherHorizontal] == opponentSlctColor) { scannedTokensCoord.Clear(); } //DIsplay to confirm foreach (string itemsHeld in scannedTokensCoord) { //print ("WE HELD: " + itemsHeld ); } changeColor(scannedTokensCoord); break; } //We raise the scope and check what is beyond that. anotherHorizontal += indexCaseCheckHorizontal; anotherVertical += indexCaseCheckVertical; ////////////////////////// //<!> Safety ////////////////////////// //print (); if ((incre + anotherHorizontal) > 7 || (incre + anotherHorizontal) < 0) { anotherHorizontal = 0; break; } if ((theRow + anotherVertical) > 7 || (theRow + anotherVertical) < 0) { anotherVertical = 0; break; } ////////////////////////// //Its a good patch ////////////////////////// } //END While Loop /*print("#ITEMS in " + scannedTokenValue.Count); * print ("WE BREAK OUT: " + theTileNames[theRow + anotherVertical, incre + anotherHorizontal] + " " + theField[theRow + anotherVertical, incre + anotherHorizontal] ); * print ("La case FIN: " + theTileNames[theRow + anotherVertical - indexCaseCheckVertical, incre + anotherHorizontal - indexCaseCheckHorizontal] + " " + theField[theRow + anotherVertical - indexCaseCheckVertical, incre + anotherHorizontal - indexCaseCheckHorizontal] ); * * * print("LAST MOTHER F****R " + scannedTokensCoord[(scannedTokensCoord.Count-1)] +" "+ scannedTokenValue[(scannedTokenValue.Count-1)] ); * */ /* * * foreach( string scanItemz in scannedTokensCoord){ * * * //Get the number of rows * int theNumRowsEnd = (theField.Length/8); * * //We set the rows * for(int theRowEnd = 0 ; theRowEnd < theNumRowsEnd; theRowEnd++){ * * //We check each entry * for(int increEnd = 0; increEnd < 8; increEnd++){ * if(scanItemz == theTileNames[theRowEnd,increEnd]){ * print ("00000000000000000000000: " + scanItemz); * if(theField[theRowEnd,increEnd] == playerSlctColor){ * //changeColor(scannedTokensCoord); * print ("SEGA"); * //break; * } * } * * } * } * * * }*/ //print ("####### LAST COORD: " + theField[theRow + indexCaseCheckVertical, incre + indexCaseCheckHorizontal] + " " + theTileNames[theRow + indexCaseCheckVertical, incre + indexCaseCheckHorizontal]); //changeColor(scannedTokensCoord); } //End if raise scope pos //Make a while we dont reach 0 } //END ELSE } //We print the names for a test. //print ("So I lived: " + theTileNames[theRow,incre ] + "##" + newTokenLocation); } } //End Generating //We get the position of the latest token placed by the user by accessing the replaceTokenScript 竏 ///We loopthrough each case and check the infront and behind the tokens. 竏 //We check for what is on the right if its empty we check on the left until we find an empty spot //We check for patterns like these: B W B and change it for B B B . //We also need to check for patterns like that too: B W W W B -> B B B B B //Actually we need to check for the first Token in the chain [B] W W W W B until we get an empty space [_] (or until we moved to the next row?) 竏 //Then, we go back one case [B] W W W W (B) [_] 竏 //Everything within this line becomes [B] : [B] B B B B (B) [_] 竏 //Once complete we use the same algorithm for up and down.竏 }
} //End StartChecking void lookForAvailable(lookDirection theWantedDirection, int theRow, int incre, int firstTkenLocation) { int indexCaseCheckHorizontal = 0; int indexCaseCheckVertical = 0; switch (theWantedDirection) { case lookDirection.right: //int nextCaseCheck = theField[theRow,incre + 1]; indexCaseCheckHorizontal = +1; break; case lookDirection.left: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckHorizontal = -1; break; case lookDirection.up: //int nextCaseCheck = theField[theRow,incre + 1]; indexCaseCheckVertical = +1; break; case lookDirection.down: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckVertical = -1; break; //Diagonal case lookDirection.diagUpRight: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckHorizontal = +1; indexCaseCheckVertical = +1; break; case lookDirection.diagUpLeft: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckHorizontal = -1; indexCaseCheckVertical = +1; break; case lookDirection.diagDownRight: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckHorizontal = +1; indexCaseCheckVertical = -1; break; case lookDirection.diagDownLeft: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckHorizontal = -1; indexCaseCheckVertical = -1; break; } int posTempVertical = indexCaseCheckVertical; int posTempHorizontal = indexCaseCheckHorizontal; /*print ("VEC: " + (theRow + posTempVertical)); * print ("HOR: " + (incre + posTempHorizontal));*/ ////////////////////////// //<!> Safety ////////////////////////// //print (); if ((incre + posTempHorizontal) > 7 || (incre + posTempHorizontal) < 0) { //print ("H BIGGER THAN 8"); posTempHorizontal = 0; } if ((theRow + posTempVertical) > 7 || (theRow + posTempVertical) < 0) { //print ("V BIGGER THAN 8"); posTempVertical = 0; } ////////////////////////// //Its a good patch ////////////////////////// //OK we found a token first we need to check what is behind this token, with a while loop while (theField[theRow + posTempVertical, incre + posTempHorizontal] != 0) { print("<@> In the loop!!!"); if (theField[theRow + posTempVertical, incre + posTempHorizontal] == playerSlctColor) { break; } //We loop backward to see what is there. posTempVertical += indexCaseCheckVertical; posTempHorizontal += indexCaseCheckHorizontal; /*print ("<!> posVertical" + (theRow + posTempVertical)); * print ("<!> posHorizontal" + (incre + posTempHorizontal)); */ ////////////////////////// //<!> Safety ////////////////////////// //print (); if ((incre + posTempHorizontal) > 7 || (incre + posTempHorizontal) < 0) { break; print("H BIGGER THAN 8"); posTempHorizontal = 0; } if ((theRow + posTempVertical) > 7 || (theRow + posTempVertical) < 0) { break; print("V BIGGER THAN 8"); posTempVertical = 0; } ////////////////////////// //Its a good patch ////////////////////////// //If the spot is not empty we leave it as it is. if (theField[theRow + posTempVertical, incre + posTempHorizontal] != 0) { } else { //print("<!>Potential Pos: " + theTileNames[theRow + posTempVertical ,incre + posTempHorizontal] + " " + theField[theRow + posTempVertical ,incre + posTempHorizontal]); registerToken(theTileNames[theRow + posTempVertical, incre + posTempHorizontal]); print(" <--//*//--> Shirley Straberry <--//*//-->"); print("<#> We REGISTER a token <#> "); //We check the number of created token if its equal to 0 we know that no token has been created. print("# # # # # # # # # # # #: " + isAllTokenPlaced() + " " + nbCheckedTokens); } /*if( isAllTokenPlaced() == 0){ * print("</+/+/+/+/> No tokens has been created. Player is unable to move. We should end the turn."); * }else{ * print("<_______> Its ok."); * }*/ } //End While //***** //We need to add a way to check that the task is complete. Once complete we need to check if there is any token that has been placed. If not, we skip the turn. //***** //We check the number of created token if its equal to 0 we know that no token has been created. // print ("= = = = = = =: " + isAllTokenPlaced() + " " + nbCheckedTokens); /*if( nbCheckedTokens == isAllTokenPlaced() ){ * print("</M/> We Checked all the tokens"); * * }else{ * * if(nbCheckedTokens == 0){ * print("</+/+/+/+/> No tokens has been created. Player is unable to move. We should end the turn."); * //skipTurn = true; * * GameObject theItem = GameObject.Find("txtSkipTurn"); * //theItem.GetComponent<showSkip>().displaySkip(); * } * }*/ }
//void lookForAvailable(lookDirection theWantedDirection ,int theRow, int incre, int firstTkenLocation){ void lookForMatches(string theCubeWeFound, int theCubeWeFoundValue, lookDirection decidedDir) { //IEnumerator lookForMatches( string theCubeWeFound, int theCubeWeFoundValue, lookDirection decidedDir){ int indexCaseCheckHorizontal = 0; int indexCaseCheckVertical = 0; //We declare it before use lookDirection theWantedDirection; //theWantedDirection = lookDirection.left; //theWantedDirection = decidedDir; theWantedDirection = lookDirection.up; switch (theWantedDirection) { case lookDirection.right: //int nextCaseCheck = theField[theRow,incre + 1]; indexCaseCheckHorizontal = -1; break; case lookDirection.left: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckHorizontal = +1; break; case lookDirection.up: //int nextCaseCheck = theField[theRow,incre + 1]; indexCaseCheckVertical = +1; break; case lookDirection.down: //int nextCaseCheck = theField[theRow,incre - 1]; indexCaseCheckVertical = -1; break; } /*int posTempVertical = indexCaseCheckVertical; * int posTempHorizontal = indexCaseCheckHorizontal;*/ int theIncreV = indexCaseCheckVertical; int theIncreH = indexCaseCheckHorizontal; /*print ("INCREV " +theIncreV); //Why does this shows up as empty? * print ("INCREH " +theIncreH);*///Why does this shows up as empty? int theNumRows = (createField.theField.Length / 10); for (int theRow = 0; theRow < theNumRows; theRow++) { //print("##################"); //We populate the rows for (int incre = 0; incre < 11; incre++) { //We try to recover the location, if (createField.theTileNames[theRow, incre] == theCubeWeFound) { /* print (" "); * print (" "); * print (" "); * print ("THE CUBE FOUND: " + theCubeWeFound + " " + theCubeWeFoundValue );*/ memCubeCombi.Clear(); //------------START LINE RESOLUTION /////// //int dummyIncre = 0; int matchCounter = 0; // < Left and Right > We look through the items with a forward movement. //while( createField.theField[theRow, incre+ dummyIncre] != 0 ){ for (int dummyIncre = 0; dummyIncre < 11; dummyIncre++) { // print("|||==========||| " + createField.theTileNames[theRow, incre+ dummyIncre] + " " + createField.theField[theRow, incre+ dummyIncre]); /*if( createField.theField[theRow, incre + dummyIncre] == 0){ * print ("<Q> LOG OUT <Q>"); * break; * } */ //Add each value in the // print ("<!> Check Dummy:" + dummyIncre + " " +createField.theTileNames[theRow, incre + dummyIncre]); //memCubeCombi.Add( createField.theTileNames[theRow, incre + dummyIncre]); // print("We are adding:" + createField.theTileNames[theRow, incre + dummyIncre] + " " + createField.theField[theRow, incre + dummyIncre] ); //print(" Table lenght: " + memCubeCombi.Count); // < !!! > This one goes from right to left and gathers the cube all together if (createField.theField[theRow, incre + dummyIncre] != theCubeWeFoundValue) { // print ("<!> Not same Leave:" + dummyIncre); //We check which cubes are getting deleted. foreach (string tempItem in memCubeCombi) { // print ("---- > " + tempItem); } //------------------------------------------------------------------------------------ // print ("<P> We are now starting the deleting process: " + matchCounter ); if (/* dummyIncre >= 3 */ matchCounter >= 3) { // print ("<!-!> OK We Copy to Final: " + dummyIncre + "Started with: " + theCubeWeFound + ": " + theCubeWeFoundValue); // // print(" Table lenght: " + memCubeCombi.Count); finalMemCubeCombi = memCubeCombi; //We can try here to delete the unrelated cubes. for (int t = 0; t < memCubeCombi.Count; t++) { //if(memCubeCombi[t] == createField.theTileNames //for(int search = 0; search < createField.theTileNames.Length; search++){ //Loop until we recover the position of the current index [t] int someNumRows = (createField.theField.Length / 10); for (int someTheRow = 0; someTheRow < theNumRows; someTheRow++) { for (int someIncre = 0; someIncre < 11; someIncre++) { //We check if the position held by the table matches the index in the loop. If so we delete the info from the main table. if (memCubeCombi[t] == createField.theTileNames[someTheRow, someIncre]) { //The data value held i the temp table has been recovered. // print ("<!> ==> We delete the data at position <== <!>" + createField.theTileNames[someTheRow,someIncre]+ " " + createField.theField[someTheRow,someIncre]); //We delete the information contained in the real table createField.theField[someTheRow, someIncre] = 0; // <note>The system automatically handles the vitual update. //We Contact the scoreManager and update the score upon each cube delete. scoreManager theActualScore = GetComponent <scoreManager>(); //theActualScore.scoreValue +=1; theActualScore.raiseScore(); } //End If } //End for } //EndFor } //End For //Small For each that check the output foreach (string tempItem in memCubeCombi) { print("==> " + tempItem); } //memCubeCombi.Clear(); break; } //------------------------------------------------------------------------------------ memCubeCombi.Clear(); //dummyIncre = 0; break; } else { //We add the cube in the temporary memory. memCubeCombi.Add(createField.theTileNames[theRow, incre + dummyIncre]); //Raise the number of match matchCounter += 1; } //dummyIncre+= indexCaseCheckHorizontal; // +1 to the left <- // print ("<CHECK> value of dummy " + dummyIncre + " " + createField.theTileNames[theRow, incre + dummyIncre] + " " + createField.theField[theRow, incre + dummyIncre] ); if (createField.theField[theRow, incre + dummyIncre] == 0) { // print (" <&&&&> OMG!!!!!! " + createField.theTileNames[theRow, incre + dummyIncre]); // } } // print(" < VVVVVVVVVVVVV > Process should be done in here < VVVVVVVVVVVVV >"); //***************************************** //////// //------------END LINE RESOLUTION //yield return new WaitForSeconds(0); //****** // FROM TOP TO BOTTOM DETECTION //Will make the same thing as the previous one but taht will take care of gathering the cubes from bottom to top //int dummyIncre = 0; /* int matchCounter2 = 0; * * // < Left and Right > We look through the items with a forward movement. * //while( createField.theField[theRow, incre+ dummyIncre] != 0 ){ * for(int dummyIncreUp = 0; dummyIncreUp < 7; dummyIncreUp ++ ){ * * * * * print("|||==========||| " + createField.theTileNames[ dummyIncreUp, incre] + " " + createField.theField[ dummyIncreUp, incre]); * //print("||| NEXT BELOW ||| " + createField.theTileNames[ dummyIncreUp, incre] + " " + createField.theField[ dummyIncreUp, incre]); * * //We check if the next item is the same as the cube we found. * if(createField.theField[ dummyIncreUp, incre] != theCubeWeFoundValue){ * * //We check which cubes are getting deleted. * foreach (string tempItemOther in memCubeCombiOther){ * print ("---- > " + tempItemOther ); * } * * if( matchCounter2 >=3 ){ * * finalMemCubeCombiOther = memCubeCombiOther; * * for( int t = 0; t < memCubeCombiOther.Count; t++){ * * * * * * * * //Loop until we recover the position of the current index [t] * int someNumRowsOther = (createField.theField.Length/10); * for(int someTheRowOther = 0; someTheRowOther < theNumRows; someTheRowOther++){ * for(int someIncre = 0; someIncre < 11; someIncre++){ * * //We check if the position held by the table matches the index in the loop. If so we delete the info from the main table. * if(memCubeCombiOther[t] == createField.theTileNames[someTheRowOther, someIncre]){ * * //The data value held i the temp table has been recovered. * print ("<!> ==> We delete the data at position <== <!>" + createField.theTileNames[someTheRowOther, someIncre]+ " " + createField.theField[someTheRowOther, someIncre]); * * //We delete the information contained in the real table * createField.theField[someTheRowOther,someIncre] = 0; * * // <note>The system automatically handles the vitual update. * * //We Contact the scoreManager and update the score upon each cube delete. * scoreManager theActualScore = GetComponent<scoreManager>(); * //theActualScore.scoreValue +=1; * theActualScore.raiseScore(); * * * * }//End If * * * }//End for * }//EndFor * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }//End For * * * * //Small For each that check the output * foreach (string tempItemOther in memCubeCombiOther){ * print ("==> " + tempItemOther); * } * //memCubeCombi.Clear(); * break; * * * * } * * memCubeCombiOther.Clear(); * //dummyIncre = 0; * break; * * }else{ * * //We add the cube in the temporary memory. * print ("< ### > What is being saved in the memory !!!! " + createField.theTileNames[ dummyIncreUp, incre ] ); * memCubeCombiOther.Add( createField.theTileNames[ dummyIncreUp, incre] ); * //Raise the number of match * matchCounter2 += 1; * * } * * * * * * * * * * * * * * * * * * * // print("|||==========||| " + createField.theTileNames[theRow + dummyIncreUp, incre] + " " + createField.theField[theRow + dummyIncreUp, incre]); * * * * * if( (incre + theRow) < 7 ){ * // print("|||==========||| " + createField.theTileNames[incre+ theRow, dummyIncreUp] + " " + createField.theField[incre+ theRow, dummyIncreUp]); * } * * * * }*/ /* print(" " ); * print(" " ); * print(" " );*/ //***************************************** } } } }