//starting prototype for online robot search public void MoveThruCourse(List <Points> list, Points start, Points end, int mapNumber) { WriteToFile(">>>>>>> Greedy best-first search for map " + mapNumber + "<<<<<<<<<<"); int moves = 0; while (true) { Points upPoints = new Points((this.position.xCoord) - 1, this.position.yCoord); Points downPoints = new Points((this.position.xCoord) + 1, this.position.yCoord); Points rightPoints = new Points(this.position.xCoord, (this.position.yCoord) + 1); //give each point a value Console.WriteLine(upPoints.ToString()); Console.WriteLine(downPoints.ToString()); Console.WriteLine(rightPoints.ToString()); var doubleList = new List <double>(); double upPointsValue = (double)upPoints.PointValue(end); double downPointsValue = (double)downPoints.PointValue(end); double rightPointsValue = (double)rightPoints.PointValue(end); //check if move is on no contact list or a prior move (stops repeat evaluations) there is a //better way, however, with time contraints, I used this. if ((upPoints.NotOnList(list)) && (upPoints.NotOnList(moveList))) { doubleList.Add(upPointsValue); } if ((downPoints.NotOnList(list)) && (downPoints.NotOnList(moveList))) { doubleList.Add(downPointsValue); } if ((rightPoints.NotOnList(list)) && (rightPoints.NotOnList(moveList))) { doubleList.Add(rightPointsValue); } doubleList.Sort(); //add to move history moveList.Add(position); WriteToFile("upValue: " + upPointsValue + " downValue: " + downPointsValue + " rightValue: " + rightPointsValue); WriteToFile("current position: " + position.ToString()); if ((doubleList[0]) == rightPointsValue) { MoveRight(); } else if ((doubleList[0]) == downPointsValue) { MoveDown(); } else if ((doubleList[0]) == upPointsValue) { MoveUp(); } else { Console.WriteLine("I'm STUCK....HELP!!!!"); } if ((position.xCoord == end.xCoord) && (position.yCoord == end.yCoord)) { Console.WriteLine("Congrats. Goal reached!!!!! \n" + "number of moves: " + moves); WriteToFile("Congrats. Goal reached!!!!! \n" + "number of moves: " + moves); return; } moves++; } }
public Robot(Points startingPoint) { this.position = new Points(startingPoint.xCoord, startingPoint.yCoord); this.history = new List <Points>(); this.moveList = new List <Points>(); }