问题
Given a object which may move forward, backward, left and right at a given X,Y point. How to efficiently direct the object to a X,Y point using the given movement mechanics in the most efficient and human natural way.
The object is available for movement in real time, you may tell them to "startMoving|Direction|()" and "stopMoving|Direction|()". Though as a additional twist and the part I am having trouble with, is the facing of the object is never known, only its current location is known, so the algorithm must "detect" direction. The location of the object is updated in a separate thread in 500-1second intervals. A "Request" to update the location within the algorithm made be made at any point, but it is not immediately available and the algorithm must keep that in consideration. Doing something like requestAndWaitForCoordUpdate() is perfectly acceptable, however likely not needed.
In addition, no obstacles appear, it can be assumed you are on a MOSTLY open plane, stray to far from the direct straight line between the paths and you may run into obstacles. It is safe to assume that 1/4th the distance between a target and source, should be available in width on a given direct path.
I would also mention I am not sure A* applys in this scenario, if it does I am unsure how to implement it given the constraints. The only real variable here is the facing of the object.
Here is some example code:
public int[] currentCoords;
public void movement() {
currentCoords[0] = 1005; // starting y coord
currentCoords[1] = 1007; // starting x coord
moveTo(1050, 1025);
}
public void moveTo(int x, int y) {
... how?
}
public void threadUpdatingCoords() {
... periodically check for source coord updates
... between 200ms and 1000ms apart.
}
回答1:
To calculate the optimal route you should use A* algorithm. However to do it in the most human way, you just let it walk and take random directions. Unless it's a smart human, he'll just stick his right hand to the wall and keep walking without losing touch: eventually you will reach your destination.
Human isn't efficient, it's random. A* isn't random, it's efficient.
来源:https://stackoverflow.com/questions/5383833/c-sharp-pathing-algorithm-for-moving-a-object-from-pointx-y-to-pointx-y