//determine whether "I" get win private bool win(){ bool won = false; ArrayList foundRowList; if (stepCount >= multi_init.totalLength) { //find start edge for (int i = 0; i < multi_init.totalLength; i++){ if(visitRow[i,0] == true){ foundRowList = new ArrayList (); Coordination cord = new Coordination(i,0); foundRowList.Add(cord); //won = findNextEdge(i,0,1,foundRowList); won = setPathArray(cord, foundRowList); if (won) { Camera.main.SendMessage("disableButtons"); ArrayList path = new ArrayList (); //set first path Coordination coor = (Coordination)foundRowList[0]; addPath (coor.getX (), coor.getY (), path); addPath (coor.getX (), coor.getY ()+1, path); Coordination c = new Coordination (coor.getX (), coor.getY ()+1); setPathArray (c, path); character.winAnimation(path); break; } } } } return won; }
private bool win(){ Debug.Log ("<color=green>check win</color>"); bool won = false; ArrayList foundRowList; int length = 0; if (SceneManager.GetActiveScene ().name == "scene_multi") length = multi_init.totalLength; else if (SceneManager.GetActiveScene ().name == "scene_ai") length = aiMode_init.totalLength; if (stepCount >= length) { //find start edge for (int i = 0; i < length; i++){ if(visitCol[0,i] == true){ foundRowList = new ArrayList (); Coordination cord = new Coordination(0,i); foundRowList.Add(cord); //won = findNextEdge(0,i,1,foundRowList); won = setPathArray(cord, foundRowList, length, length, false); if (won) { //StartCoroutine(winAnimation (foundRowList)); //ch.SetActive(true); Camera.main.SendMessage("disableButtons"); ArrayList path = new ArrayList (); //set first path Coordination coor = (Coordination)foundRowList[0]; addPath (coor.getX (), coor.getY (), path); addPath (coor.getX ()+1, coor.getY (), path); Coordination c = new Coordination (coor.getX () + 1, coor.getY ()); setPathArray (c, path, length, length, false); if(aiMode_init.mustConnect) checkConnectBonusNode (path); character.winAnimation(path); break; } } } } Debug.Log ("<color=green>" + won + "</color>"); return won; }
public static int getCheckmateX(){ if (checkmatePath.Count >= 1) { /* Vector3 cm = (Vector3)checkmatePath [blueEdgeRespond.checkmatePath.Count - 1]; cm = new Vector3 (cm.x, cm.y-19.5f, cm.z); for (int i = 0; i < 6; i++) { for (int j = 0; j < 7; j++) { if (blueNodeArray [i, j] != null && blueNodeArray [i, j].GetComponent<RectTransform> ().anchoredPosition3D.Equals(cm)) return i; } } */ Coordination c = (Coordination)checkmatePath [checkmatePath.Count - 1]; //if (c.getX () == aiMode_init.totalLength) // return aiMode_init.maxRow; //else return c.getX (); //return -1; } else return -1; }
//find path almost connected //c -> starting coordinate | path -> arraylist to record checked path | length -> board size | skipped -> check if skipped once already private bool findCheckmatePath(Coordination c, ArrayList path, int length, int end, bool skipped, Coordination targetCoor){ //is the path found bool pathFound = false; bool preSkipped = skipped; //if path finding finished, return blank targetCoor if (c.getX () == end) { Debug.Log ("<color=red>Found end</color>"); path.Add (targetCoor); return true; } //find path upward if (!pathFound && c.getX () - 1 >= 0) { Coordination coor = new Coordination (c.getX () - 1, c.getY ()); if (visitCol [c.getX () - 1, c.getY ()] == true) { if (!checkCoorEqual(path, coor.getX(), coor.getY()) && targetCoor.Equals(coor) == false) { Debug.Log ("<color=orange>Check Coor: x," + coor.getX() + ", " + coor.getY() + "</color>"); path.Add (coor); pathFound = findCheckmatePath (coor, path, length, end, skipped, targetCoor); } } } //find path downward if (!pathFound && c.getX () + 1 <= (length)) { Coordination coor = new Coordination (c.getX () + 1, c.getY ()); if (visitCol [c.getX (), c.getY ()] == true) { if (!checkCoorEqual(path, coor.getX(), coor.getY()) && targetCoor.Equals(coor) == false) { Debug.Log ("<color=orange>Check Coor: x," + coor.getX() + ", " + coor.getY() + "</color>"); path.Add (coor); pathFound = findCheckmatePath (coor, path, length, end, skipped, targetCoor); } } } Debug.Log (pathFound); //find path at left if(pathFound == false && c.getY() - 1 >= 0){ Coordination coor = new Coordination (c.getX (), c.getY ()-1); if(visitRow[c.getX(), c.getY()-1] == true){ if (!checkCoorEqual(path, coor.getX(), coor.getY()) && targetCoor.Equals(coor) == false) { Debug.Log ("<color=orange>Check Coor: x," + coor.getX() + ", " + coor.getY() + "</color>"); path.Add (coor); pathFound = findCheckmatePath (coor, path, length, end, skipped, targetCoor); } } } //find path at right if(!pathFound && c.getY() + 1 <= (length-1)){ Coordination coor = new Coordination (c.getX (), c.getY ()+1); if(visitRow[c.getX(), c.getY()] == true){ if (!checkCoorEqual(path, coor.getX(), coor.getY()) && targetCoor.Equals(coor) == false) { Debug.Log ("<color=orange>Check Coor: x," + coor.getX() + ", " + coor.getY() + "</color>"); path.Add (coor); pathFound = findCheckmatePath (coor, path, length, end, skipped, targetCoor); } } } //Skip upward if (!pathFound && c.getX () - 1 >= 0) { Coordination coor = new Coordination (c.getX () - 1, c.getY ()); if (visitCol [c.getX () - 1, c.getY ()] != true) { if (!skipped && !checkCoorEqual (path, coor.getX (), coor.getY ()) && !blockedCol [c.getX () - 1, c.getY ()] && targetCoor.Equals(coor) == false) { Debug.Log ("<color=orange>Skip to Coor: x," + coor.getX () + ", " + coor.getY () + "</color>"); skipped = true; checkmateCol = false; skipLeft = false; skipUp = true; targetCoor = coor; pathFound = findCheckmatePath (coor, path, length, end, skipped, targetCoor); if (!pathFound) skipped = false; } } } //Skip downward if (!pathFound && c.getX () + 1 <= (length)) { Coordination coor = new Coordination (c.getX () + 1, c.getY ()); if (visitCol [c.getX (), c.getY ()] != true) { if (!skipped && !checkCoorEqual(path, coor.getX(), coor.getY()) && !blockedCol[c.getX(), c.getY()] && targetCoor.Equals(coor) == false) { Debug.Log ("<color=orange>Skip to Coor: x," + coor.getX() + ", " + coor.getY() + "</color>"); skipped = true; checkmateCol = false; skipLeft = false; skipUp = false; targetCoor = coor; pathFound = findCheckmatePath (coor, path, length, end, skipped, targetCoor); if (!pathFound) skipped = false; } } } //Skip left if(pathFound == false && c.getY() - 1 >= 0){ Coordination coor = new Coordination (c.getX (), c.getY ()-1); if(visitRow[c.getX(), c.getY()-1] != true){ if (!skipped && !checkCoorEqual(path, coor.getX(), coor.getY()) && !blockedRow[c.getX(), c.getY()-1] && targetCoor.Equals(coor) == false) { Debug.Log (pathFound); Debug.Log ("<color=orange>Skip to Coor: x," + coor.getX() + ", " + coor.getY() + "</color>"); skipped = true; checkmateCol = true; skipLeft = true; skipUp = false; targetCoor = coor; pathFound = findCheckmatePath (coor, path, length, end, skipped, targetCoor); if (!pathFound) skipped = false; } } } //Skip right if(!pathFound && c.getY() + 1 <= (length-1)){ Coordination coor = new Coordination (c.getX (), c.getY ()+1); if(visitRow[c.getX(), c.getY()] != true){ if (!skipped && !checkCoorEqual(path, coor.getX(), coor.getY()) && !blockedRow[c.getX(), c.getY()] && targetCoor.Equals(coor) == false) { Debug.Log ("<color=orange>Skip to Coor: x," + coor.getX() + ", " + coor.getY() + "</color>"); skipped = true; checkmateCol = true; skipLeft = false; skipUp = false; targetCoor = coor; pathFound = findCheckmatePath (coor, path, length, end, skipped, targetCoor); if (!pathFound) skipped = false; } } } //if path not connected yet, return a null coordination if (!pathFound) { Debug.Log ("<color=red>Remove Coor: x," + c.getX () + ", " + c.getY () + "</color>"); //path.Remove (c); //skipped = preSkipped; skipped = false; return false; } else return true; skipped = false; return false; }
//Find linked path start from c and fille the path to arraylist "path" //bool checkCM -> check checkmate private bool setPathArray(Coordination c, ArrayList path ,int length, int end, bool checkCM){ Debug.Log ("<color=yellow> Called with coor: x," + c.getX() + ", " + c.getY() + "</color>"); //if path found bool pathFound = false; //if path finding finished if (c.getX () == end) { if (checkCM) { if(end == 1) return blockedCol[c.getX()-1,c.getY()] != true; else return blockedCol[c.getX(),c.getY()] != true; }else return true; } //find path upward if (!pathFound && c.getX () - 1 >= 0) { if (visitCol [c.getX () - 1, c.getY ()] == true) { Vector3 pos = blueNodeArray [c.getX()-1, c.getY()].GetComponent<RectTransform> ().anchoredPosition3D; if (!path.Contains (new Vector3 (pos.x, pos.y + 19.5f, pos.z))) { addPath (c.getX () - 1, c.getY (), path); Coordination coor = new Coordination (c.getX () - 1, c.getY ()); pathFound = setPathArray(coor, path, length, end, checkCM); } } } //find path downward if (!pathFound && c.getX () + 1 <= (length)) { if (visitCol [c.getX (), c.getY ()] == true) { Vector3 pos = blueNodeArray [c.getX()+1, c.getY()].GetComponent<RectTransform> ().anchoredPosition3D; if (!path.Contains (new Vector3 (pos.x, pos.y + 19.5f, pos.z))) { addPath (c.getX () + 1, c.getY (), path); Coordination coor = new Coordination (c.getX () + 1, c.getY ()); pathFound = setPathArray(coor, path, length, end, checkCM); } } } //find path at left if(!pathFound && c.getY() - 1 >= 0){ if(visitRow[c.getX(), c.getY()-1] == true){ Vector3 pos = blueNodeArray[c.getX(), c.getY()-1].GetComponent<RectTransform>().anchoredPosition3D; if (!path.Contains (new Vector3 (pos.x, pos.y + 19.5f, pos.z))) { addPath (c.getX (), c.getY () - 1, path); Coordination coor = new Coordination (c.getX (), c.getY ()-1); pathFound = setPathArray(coor, path, length, end, checkCM); } } } //find path at right if(!pathFound && c.getY() + 1 <= (length-1)){ if(visitRow[c.getX(), c.getY()] == true){ Vector3 pos = blueNodeArray[c.getX(), c.getY()+1].GetComponent<RectTransform>().anchoredPosition3D; if (!path.Contains (new Vector3 (pos.x, pos.y + 19.5f, pos.z))) { addPath (c.getX (), c.getY () + 1, path); Coordination coor = new Coordination (c.getX (), c.getY ()+1); pathFound = setPathArray(coor, path, length, end, checkCM); } } } if (!pathFound) { Vector3 pos = blueNodeArray[c.getX(), c.getY()].GetComponent<RectTransform>().anchoredPosition3D; path.Remove (new Vector3 (pos.x, pos.y + 19.5f, pos.z)); Debug.Log ("<color=red>Remove Coor: x," + c.getX() + ", " + c.getY() + "</color>"); } return pathFound; }
public bool Equals(Coordination other){ if (this.x == other.getX () && this.y == other.getY ()) return true; else return false; }