A.I.可导航随机生成的2D城市 [英] A.I. that can navigate a randomly generated 2D city

查看:157
本文介绍了A.I.可导航随机生成的2D城市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在iOS游戏(使用UIView的),它有一个随机生成的二维城市。 我需要攻击的AI,这将需要一个智能的路径来寻找球员(不与建筑物相撞)。 有人点我在正确的方向,以什么样的算法,我会用它来实现这一目标?

I'm writing an iOS game (Using UIView), which has a randomly generated 2D city. I need attacking A.I., that will take an intelligent path to find the player (without colliding with buildings). Can someone point me in the right direction as to what kind of algorithms I would use to achieve this?

编辑:我已经决定使用A *。我会在地图上创建一个网格,测试每个网格交叉点,如果该点是在建筑物内,我会失效的地步。攻击A.I.然后播放器将在当前位置移动,到一个有效的网格点,这是更接近其目标(其位置的特定半径范围内)。

I've decided to use A*. I will create a grid on the map, test every grid intersection point, if that point is inside a building, I'll invalidate the point. The attacking A.I. player will then move from its current location, to a valid grid point, which is closer to its goal (within a certain radius of its location).

推荐答案

您正在寻找一类算法称为寻路算法。有许多方法可以使用​​。

You are looking for a class of algorithms called pathfinding algorithms. There are many approaches you can use.

经典算法这里 Dijkstra算法和的 A *搜索,可以指导对象从一个位置到另一个位置沿着最佳路径。这些算法的工作由2D世界的建模为图表,然后找到从对象的起始位置的最短路径在该图中的目标位置。这两种算法被广泛应用于AI和寻路,我会强烈建议投资时间来阅读更多关于他们。有关于可在网上,如果你想A *搜索一个坚实的教程。

The classic algorithms here are Dijkstra's algorithm and A* search, which can guide an object from one location to another along the optimal path. These algorithms work by modeling the 2D world as a graph and then finding the shortest path from the object's start location to the destination location in that graph. These two algorithms are used extensively in AI and pathfinding, and I would strongly suggest investing the time to read more about them. There is a solid tutorial on A* search available online if you'd like.

如果你有很多需要移动到目标,而不干预对象的不同,你可能要考虑潜在的领域,这给了一个简单而灵活的框架,有多个对象接近目标。这种方法是使用伯克利主宰星际争霸AI ,并经常在机器人运动规划使用。直观地看,这种方法的工作原理是分配一个势的价值每一个位置,然后有对象不断从高电位移到低电位,直到命中目标。这种方法是有点棘手得到的权利,但一旦它的工作原理也容易导致灵活,可定制AI的行为智能。

If you have many different objects that need to move to a target without interfering, you may want to look into potential fields, which give a simple and flexible framework for having multiple objects approach a target. This approach was used by the Berkeley "Overmind" StarCraft AI, and is often used in robot motion planning. Intuitively, this approach works by assigning a "potential" value to each location, then having the objects keep moving from high potential to low potential until they hit the target. This approach is a bit trickier to get right, but once it works it tends to lead to flexible, customizable AI that behaves intelligently.

希望这有助于!

这篇关于A.I.可导航随机生成的2D城市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆