游戏中的遗传算法

发布于 2024-09-26 12:01:46 字数 431 浏览 0 评论 0原文

我必须做一个关于遗传算法的学期项目,我想到了调整第一人称射击机器人的特征(即要使用的武器等)。例如,我会以字符串的形式表示特征,前 10 位表示选择武器 1 的概率,接下来的 10 位表示选择武器 2 的概率,依此类推。因此我会得到最佳字符串,从而能够算出我应该使用什么最佳武器。

我面临的明显问题是如何找到适应度值。我的想法是,如果我想找到一根绳子的适合度,我会强制机器人使用相应的武器并与其进行游戏,并使用机器人的最终分数作为适合度。问题是我需要玩大量游戏。

我可以做某种模拟吗?例如,我能否以某种方式获得一个函数 f ,在其中输入机器人的特征(例如:武器等),并且它会返回相应的适应度值?开源FPS游戏有提供这样的库吗?

另一种选择是进入游戏的源代码,然后继续模拟各种场景并记录每个场景的得分。我不希望因为进入游戏源代码而增加复杂性,因为这是一个短期(1 个月)的项目。

谢谢。

I have to do a term project on Genetic Algorithms, and I had the idea of tuning the traits (i.e. weapons to be used , etc) of a first person shooter bot. For example, I would represent the traits in the form of a string, with first 10 bits representing probability of choosing weapon1, next 10 bits representing probability of choosing weapon2, etc. I would thus get the optimal string and thus be able to figure out what should be the optimal set of weapons i should use.

The obvious problem that I am facing is how to find the fitness values. My idea would be that if I want to find the fitness of a string, I force the bot to use the corresponding weapons and play a game against it and use the final score of the bot as the fitness. The problem is that I would need to play a LARGE no of games.

Is there some sort of simulation that I can do? For example, can i somehow get a function f where I would feed in the bot's traits (ex : weapons, etc) and it would return the corresponding fitness values? Do open source FPS games provide such a library?

The other option would be to go into the source code of the game and then keep on simulating various scenarios and noting the score in each scenario. I would prefer not to have the added complexity of going into the source of the game, since this is a short(1 month) project.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

↘紸啶 2024-10-03 12:01:46

我认为你的项目对于一个月的项目来说非常复杂。

这并不是那么令人兴奋,但也许您可以看看棋盘游戏或纸牌游戏的策略。这是一个简单得多的情况,并且许多游戏可以轻松快速地进行模拟,从而使您可以使用遗传算法来找到良好的游戏策略。它将教您遗传算法的原理,而不要求您了解模拟第一人称射击游戏所需的大量源代码。

I think your project is very complex for a one month project.

It's not quite so exciting but perhaps you could look at playing strategies for a board game or card game instead. This is a much simpler situation and and many games can easily and quickly be simulated allowing you to use a genetic algorithm to find a good playing strategy. It will teach you the principles of genetic algorithms without requiring you to understand the huge body of source code that would be necessary to simulate a first person shooter.

三生池水覆流年 2024-10-03 12:01:46

我同意 Mark Byers 的观​​点,对于一个为期 1 个月的项目来说,这有点太雄心勃勃了。

无论如何,您可能想看看 NERO(神经进化机器人操作员),这是一款基于 Ken Stanley 算法的游戏NEAT(增强拓扑的神经进化)。

您可能还想看看 Stanley 的论文:

针对不同语言存在多种 NEAT 实现,因此这可能是一个开始。

I agree with Mark Byers, it's a bit too ambitious for a 1-month project.

Anyways, you may want to check out NERO (Neuro-Evolving Robotic Operatives), which is a game based on Ken Stanley's algorithm NEAT (NeuroEvolution of Augmenting Topologies).

You may also want to have a look at Stanley's papers:

Several implementations of NEAT exist for different languages, so that may be a start.

独行侠 2024-10-03 12:01:46

如果有可用且可行的话,您可以使用现有的机器人来生成数据。

或者,您可以使用 Autohotkey(搜索 google)生成一系列按键和鼠标按下操作,并使机器人以某种愚蠢的方式自动播放。

You could use an already existing bot to generate data, if one is available and if this is possible.

Alternatively, you could use Autohotkey (search google) to generate a sequence of key&mouse presses and make the bot somehow play automatically in a dumb way.

吖咩 2024-10-03 12:01:46

您的适应度函数可以是给定机器人对抗坐鸭对手的 DPS。例如让机器人攻击玩家,并且不反击。

您可以记住适合度,因此不必重新测试重复的个体。


或者,你也可以将 2 个人分到相反的队伍中,看看谁能杀死谁,从而真正实现适者生存。

因为从技术上讲,你不需要适应度函数,只需要一种比较个体的方法。

为了减少比较次数,可以通过锦标赛的方式对每一代的个体进行比较,即

A 
  }-> A
B
        }-> C
C
  }-> C
D

前两名个体是C,然后是A。

Your fitness function can be how much DPS a given bot deals against a sitting duck opponent. E.g. have the bot attack the player, and don't fight back.

You can memoize the fitness, so duplicate individuals don't have to be retested.


Alternatively, you can make survival of the fittest be literal by putting 2 individuals on opposite teams and seeing who kills who.

Because technically you don't need a fitness function, just a way to compare individuals.

In order to reduce the number of comparisons, the individuals from each generation can be compared via a tournament, like

A 
  }-> A
B
        }-> C
C
  }-> C
D

which shows that the top two individuals are C, then A.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文