public void Expand() { //foreach (PixelNode temp in choices) //{ // choices.RemoveAt(0); //} //System.Windows.Forms.MessageBox.Show(myCoord[0] + " " + myCoord[1]); Form1.maze.SetPixel(myCoord[0], myCoord[1], Color.Green); for (int i = 0; i < 9; i++) { if (i == 4) { continue;//don't need to expand same pixel; } PixelPath temp = new PixelPath(myPixel.path[i].getCoord()[0], myPixel.path[i].getCoord()[1], Form1.dimensions); PixelNode choice = new PixelNode(temp, this); if (choice.myPixel.checker[i] == true) { choice.depth = this.depth + 1;//add partial path cost increment in here choice.myF.incPCost();; choices.Add(choice); } else { //not a valid expansion choice, continue continue; } } }
public PixelNode(PixelPath pixel, PixelNode prevPixel) { myPixel = pixel; myCoord = pixel.path[4].getCoord(); myF = new FCost(myCoord); prev = prevPixel; }
//HashSet<int[]> track = new HashSet<int[]>(); public PixelNode GSearch(int x, int y) { MessageBox.Show(x + " " + y); int[] temp = { x, y }; // track.Add(temp); PixelPath myPath = new PixelPath(x, y, dimensions); pixel choice = new pixel(myPath.path[4].getCoord(), Color.Black); if (myPath.path[4].getCoord()[0] == endX && myPath.path[4].getCoord()[1] == endY) { return(new PixelNode(myPath)); } else if (x < 0 || y < 0) { return(null); } Heuristic fCost = new Heuristic(); for (int i = 0; i < 9; i++) { // if(track.Contains(myPath.path[i].getCoord())) //{ // continue; // } Heuristic tempCost = new Heuristic(myPath.path[i].getCoord()); if (i == 4) { continue; //center pixel is the first pixel we account for and we don't want to stay there. } if (fCost.getHCost() > tempCost.getHCost()) { if (myPath.checker[i] == true) { choice = myPath.path[i]; } else { //invald pixel location, Skip! } } } int[] currentCoord = { choice.getCoord()[0], choice.getCoord()[1] }; if (currentCoord[0] == endX && currentCoord[1] == endY) { PixelPath end = new PixelPath(currentCoord[0], currentCoord[1], dimensions); PixelNode myNode = new PixelNode(end); return(myNode); } else if (choice.Equals(myPath.path[4])) { MessageBox.Show("We are not moving"); return(null); } else { return(GSearch(currentCoord[0], currentCoord[1])); } }
int depthLimit = 1000; //change for deeper or shallower search public PixelNode ASearch() { Frontier myQueue = new Frontier(); PixelPath beginPixel, endPixel; beginPixel = new PixelPath(startX, startY, dimensions); endPixel = new PixelPath(endX, endY, dimensions); HashSet <int[]> explored = new HashSet <int[]>(); PixelNode startNode = new PixelNode(beginPixel); if (beginPixel.Equals(endPixel)) {//start and end is the same place. This line is here for satisfying the //alogorithm rather than consistent application. I don't know if there is a situation that a pixel could be marked as red and blue return(startNode); } myQueue.Add(startNode); while (!myQueue.IsEmpty()) { PixelNode temp = myQueue.PopTop(); if (temp == null || temp.depth == depthLimit) { MessageBox.Show("TempInvalid"); return(null); } else { if (explored.Contains(temp.myCoord)) { continue; //no reason to do anything, this pixel has been explored } else { //unexplored if (temp.IsEnd()) { //We found the end! return(temp); } else {//start processing pixelNode temp.Expand(); foreach (PixelNode child in temp.choices) { if (!(myQueue.Contains(child))) {//add children not in Queue myQueue.Add(child); } } explored.Add(temp.myCoord); } } } } MessageBox.Show("We didn't find it"); return(null); }