简体   繁体   English

将对象从点(X,Y)移至点(X,Y)的C#路径算法

[英]C# Pathing algorithm for moving a object from point(X, Y) to point(X, Y)

Given a object which may move forward, backward, left and right at a given X,Y point. 给定一个对象,它可以在给定的X,Y点处向前,向后,向左和向右移动。 How to efficiently direct the object to a X,Y point using the given movement mechanics in the most efficient and human natural way. 如何使用给定的运动机制以最有效,最自然的方式将对象有效地指向X,Y点。

The object is available for movement in real time, you may tell them to "startMoving|Direction|()" and "stopMoving|Direction|()". 该对象可实时移动,您可以告诉它们“ startMoving | Direction |()”和“ 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. 对象的位置以500-1秒的间隔在单独的线程中更新。 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. 像requestAndWaitForCoordUpdate()这样的事情是完全可以接受的,但是可能不需要。

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. 可以安全地假设,目标和源之间的距离的1/4应为给定直接路径上的宽度。

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. 我还要提到的是,我不确定A *是否适用于这种情况,如果确实存在不确定性,我不确定如何实现它。 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.
}

To calculate the optimal route you should use A* algorithm. 要计算最佳路线,您应该使用A *算法。 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. A *不是随机的,而是有效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM