我想编写一个应用程序,它可以模仿在线游戏中的玩家。
游戏简介: 这是一款策略游戏,你可以:
- 训练你的军队(你必须有足够的资源,然后点击一个单位,点击训练)
- 建造建筑物(地雷、军械库、房屋……)
- 攻击敌人(选择一个单位,选择一个敌人,单击攻击)
- 在建筑物之间运输资源
- 进行研究(经济,军事,技术......)
这是一个简化的列表,只是一个例子。最主要的是,如果你想前进,你必须进行大量的点击...
我已经有了应用程序的“导航”部分(我使用了 Watin 库 - http://watin.sourceforge.net/)。这意味着,我可以使用高级对象并操纵它们,例如:
Soldiers soldiers = Navigator.GetAllSoldiers();
soldiers.Move(someLocation);
现在我想采取下一步 - 编写一种人工智能,它可以模拟我的游戏风格。为此,我有两个想法(我不喜欢其中任何一个):
- 登录游戏,然后循环执行一堆 if 语句(检查是否有人攻击我,检查我是否可以构建某些东西,检查是否我可以攻击某人,循环)
- 设计一种脚本语言并为其编写一个编译器。这样我就可以编写简单的脚本并运行它们(Login();CheckForAnAttack();BuildSomething();...)
还有其他想法吗?
PS:有些人可能会认为这是作弊,而且可能确实如此,但我将其视为一个学习项目,它永远不会出版或转售。
I'd like to write an application, which would imitate a player in an online game.
About the game: it is a strategy, where you can:
- train your army (you have to have enough resources, then click on a unit, click train)
- build buildings (mines, armories, houses,...)
- attack enemies (select a unit, select an enemy, click attack)
- transport resources between buildings
- make researches (economics, military, technologic,...)
This is a simplified list and is just an example. Main thing is, that you have to do a lot of clicking, if you want to advance...
I allready have the 'navigational' part of the application (I used Watin library - http://watin.sourceforge.net/). That means, that I can use high level objects and manipulate them, for example:
Soldiers soldiers = Navigator.GetAllSoldiers();
soldiers.Move(someLocation);
Now I'd like to take the next step - write a kind of AI, which would simulate my gaming style. For this I have two ideas (and I don't like either of them):
- login to the game and then follow a bunch of if statements in a loop (check if someone is attacking me, check if I can build something, check if I can attack somebody, loop)
- design a kind of scripting language and write a compiler for it. This way I could write simple scripts and run them (Login(); CheckForAnAttack(); BuildSomething(); ...)
Any other ideas?
PS: some might take this as cheating and it probably is, but I look on this as a learning project and it will never be published or reselled.
发布评论
评论(5)
如果策略不是太复杂,一堆 if 语句是最好的选择。然而,该解决方案的扩展性不太好。
制作一种脚本语言(或者现在人们所说的领域特定语言)并不会给你带来太多好处。你不会让其他人创建人工智能代理吧?为此,您可以更好地使用您的编程语言。
如果策略涉及更多,您可能需要查看贝叶斯信念网络或决策图。它们擅长以结构化和明确的方式在不确定的环境中寻找最佳行动。如果你用谷歌搜索这些术语,你会发现大量的信息和库可供使用。
A bunch of if statements is the best option if the strategy is not too complicated. However, this solution does not scale very well.
Making a scripting language (or, domain specific language as one would call that nowadays) does not buy you much. You are not going to have other people create AI agents are you? You can better use your programming language for that.
If the strategy gets more involved, you may want to look at Bayesian Belief Networks or Decision Graphs. These are good at looking for the best action in an uncertain environment in a structured and explicit way. If you google on these terms you'll find plenty of information and libraries to use.
听起来你想要一个有限状态机。我在机器人编码中使用它们并取得了不同程度的成功。根据你正在玩的游戏,你可能最好编写一个可以学习的人工智能,但听起来你的很简单,不需要那么复杂。
不要创建一种新语言,只需创建一个可以从状态机调用的函数库即可。
Sounds like you want a finite state machine. I've used them to various degrees of success in coding bots. Depending on the game you're botting you could be better off coding an AI that learns, but it sounds like yours is simple enough not to need that complexity.
Don't make a new language, just make a library of functions you can call from your state machine.
大多数策略游戏人工智能都使用“分层”方法,与您已经描述的方式大致相同:定义相对独立的行动领域(即决定要研究的内容基本上独立于寻路),然后创建一个人工智能层来处理那个域。然后有一个“顶级”人工智能层来指导中间层执行任务。
每个中间层如何工作(以及“通用”层如何工作)都可以单独确定。您可能会为“研究内容”层提出一些相当严格和直接的方法(根据您的偏好),但您可能需要为“常规”层提供更复杂的方法(这可能是指导和响应其他层)。
Most strategy game AIs use a "hierarchical" approach, much in the same way you've already described: define relatively separate domains of action (i.e. deciding what to research is mostly independent from pathfinding), and then create an AI layer to handle just that domain. Then have a "top-level" AI layer that directs the intermediate layers to perform tasks.
How each of those intermediate layers work (and how your "general" layer works) can each determined separately. You might come up with something rather rigid and straightforward for the "What To Research" layer (based on your preferences), but you may need a more complicated approach for the "General" layer (which is likely directing and responding to inputs of the other layers).
你有游戏背后的源代码吗?如果不是,那么追踪你正在对抗的每个CPU(在你的例子中是你的计算机)的位置将是一件困难的事情。你必须开发某种可以做到这一点的插件,因为从它的声音来看,你正在处理某种类型的 RTS;这需要评估许多不同 CPU 之间的许多不同位置场景。
如果你想模拟你的动作,你可以使用一些 WinAPI 很容易地跟踪你的鼠标。您还可以在玩游戏时录制屏幕(这可能不会有太大帮助,但如果您有足够的决心,可能会有所帮助。)。
说实话,对于你正在玩的游戏类型来说,你想要做的事情几乎是不可能的。你似乎还没有想清楚这一点。编程是一项有用的技能,但它不是魔法。
查看 MIT Battlecode 上的一些内容(如果你能找到的话)。就此类事情的编程而言,这可能正合你的胃口。
Do you have the sourcecode behind the game? If not, it's going to be kind of hard tracing the positions of each CPU you're (your computer in your case) is battling against. You'll have to develop some sort of plugin that can do it because from the sound of it, you're dealing with some sort of RTS of some sort; That requires the evaluation of a lot of different position scenarios between a lot of different CPUs.
If you want to simulate your movements, you could trace your mouse using some WinAPI quite easily. You can also record your screen as you play (which probably won't help much, but might be of assistance if you're determined enough.).
To be brutally honest, what you're trying to do is damn near impossible for the type of game you're playing with. You didn't seem to think this through yet. Programming is a useful skill, but it's not magic.
Check out some stuff (if you can find any) on MIT Battlecode. It might be up your alley in terms of programming for this sort of thing.
首先,我必须指出,这个项目(仅用于教育目的)对于一个人来说太大了,无法在合理的时间内完成。但是,如果你希望人工智能模仿你的个人游戏风格,你想到的另一种选择是神经网络:你经常玩游戏(真的很多)并记录你所做的所有动作并将这些数据输入到这样的网络中,并且如果一切顺利,人工智能应该会和你玩得大致相同。但我担心这只是您不喜欢的第三个想法,因为它需要花费大量的时间才能使其完美。
First of all I must point out that this project(which only serves educational purposes), is too large for a single person to complete within a reasonable amount of time. But if you want the AI to imitate your personal playing style, another alternative that comes to mind are neural networks: You play the game a lot(really a lot) and record all moves you make and feed that data to such a network, and if all goes well, the AI should play roughly the same as you do. But I'm afraid this is just a third idea you won't like, because it would take a tremendeous amount of time to get it perfect.