java老版手机游戏剑魂_剑魂自动训练第3部分

java老版手机游戏剑魂

In this article, we will finally put an end to the “Automating Swords & Souls” series (thank God!). We will continue from where we left off in the previous post and solve the last three mini-games, namely the Accuracy, Dodge, and Critical training, all in this one article. The reason for not separating the tutorial into further posts (e.g. one exclusively for Accuracy training, etc.) is the fact that these training are not vital (unlike the previously covered ones), hence not that important to automate. It is only because of the weird fusion of my masochist and perfectionist sides that I even bothered dealing with coding and fine-tuning (at least to a certain degree) these scripts. But hey, all is good when automating is considered, right?

在本文中,我们最终将结束剑与魂的自动化”系列(感谢上帝!)。 在一篇文章中,我们将继续从上一篇文章中停止的地方开始,并解决最后三款迷你游戏,即准确性,道奇和关键训练。 之所以没有将教程分成更多的职位(例如专门针对准确性培训的职位等),是因为这些培训并不重要(与之前介绍的培训不同),因此自动化并不那么重要。 只是由于受虐狂和完美主义者的奇怪融合,我什至不愿处理这些脚本的编码和微调(至少在一定程度上)。 但是,考虑到自动化,一切都很好,对吗?

准确性 (Accuracy)

By pumping stat points into Accuracy, you can increase your character’s ranged damage and his chance to perform ranged attacks (at the beginning of a given turn), hence increasing his overall damage output. But is it necessary to do so, when you can train your character (with the script provided in the previous article) to basically one-hit any enemy? Well, it ain’t, but I guess we can all agree that dealing 100k+ damage with your sword while tickling your enemy with a measly 100-ish bow damage is more than embarrassing. So let’s solve this dilemma!

通过将统计点输入到Accuracy中,您可以增加角色的远程伤害和他进行远程攻击的机会(在给定回合开始时),从而增加其总体伤害输出。 但是,当您可以训练角色(使用上一篇文章中提供的脚本)来基本上击中任何敌人时,是否有必要这样做? 好吧,不是,但是我想我们都可以同意,用剑对敌人造成100k +的伤害,同时对敌人造成可怜的100 ish的弓箭伤害,还真是令人尴尬。 因此,让我们解决这个难题!

Image for post
Source: https://imgur.com/gallery/Puathti
资料来源: https : //imgur.com/gallery/Puathti

The Accuracy training is quite simple. Targets continuously pop up on different parts of the screen and all you need to do is shoot arrows at them. If you hit them, great. Your combo increases. If you don’t hit them, not so great. Your combo breaks. If you manage to hit the center of the target, you even get a star for your efforts. A couple of extra details:

精度训练非常简单。 目标不断在屏幕的不同部分弹出,您所要做的就是向它们发射箭头。 如果你打他们,那就太好了。 您的连击增加。 如果您不打他们,那就不会那么好。 您的连击中断。 如果您设法击中目标的中心,您甚至会为自己的努力赢得一颗星。 一些额外的细节:

  • the size and location of the targets are completely random

    目标的大小和位置是完全随机的
  • some targets move in a given direction, making hitting them harder.

    一些目标朝着给定的方向移动,使打击更加困难。
Image for post
Swords & Souls. Swords&Souls 》中的精度训练迷你游戏。

We will use a multi scale template matcher from pyimagesearch to ensure that our agent can detect the objects independently of their sizes. I won’t explain the theory in great detail, since Adrian’s post provides every piece of information one would need if you are interested. Plus the only important thing we need to know to solve this mini-game is that this matcher can detect the given object on the image regardless of its size and position, making it the perfect option for us. Now we just need to integrate this into our code and we are practically done!

我们将使用pyimagesearch多尺度模板匹配器,以确保我们的代理可以独立于其大小检测对象。 我不会详细解释该理论,因为Adrian的帖子提供了您感兴趣时需要的每条信息。 加上我们需要解决的小游戏唯一重要的事情是,该匹配器可以检测图像上的给定对象,而不管其大小和位置如何,从而使其成为我们的理想选择。 现在我们只需要将其集成到我们的代码中就可以完成了!

The flow of the code must feel similar to you at this point, especially if you’ve been following the series from part 1. We basically:

此时的代码流必须与您相似,尤其是如果您一直在遵循第1部分中的系列内容时。 我们基本上:

  1. capture the screen

    捕捉屏幕
  2. crop the part that is important to us (in this case the whole game window)

    裁剪对我们来说很重要的部分(在这种情况下,整个游戏窗口)
  3. filter the object pixels (this will be explained in detail in the next paragraph)

    过滤对象像素(这将在下一段中详细说明)
  4. apply the multi scale template matcher

    应用多尺度模板匹配器
  5. click on the object (if there is any)

    单击对象(如果有)
  6. repeat from step 1.

    从步骤1开始重复。

Now the reason for step 3 is actually quite simple. I’ve tried applying the multi scale matcher directly to the whole input image (the pixels of the game window) but it did not work. It detected some parts of the image as targets even after fine-tuning and tailoring the matcher script to better suit this mini-game. After several failed attempts, I decided to ditch the pixels that negatively affect the performance of our agent by simply filtering out the red pixels representing the target signs with the help of the RGB codes. I noticed that these pixels tend to have 0 green and blue values, and relatively big (220+) red values, making the filtering process quite simple and easy when using numpy’s built-in where function.

现在,执行第3步的原因非常简单。 我尝试将多比例匹配器直接应用到整个输入图像(游戏窗口的像素),但是没有用。 即使在微调和调整匹配脚本以使其更适合此迷你游戏之后,它仍将图像的某些部分检测为目标。 经过几次失败的尝试后,我决定放弃这些对代理性能有负面影响的像素,方法是借助RGB代码简单地滤除代表目标符号的红色像素。 我注意到这些像素往往具有0的绿色和蓝色值,以及相对较大的(220+)红色值,这使得在使用numpy的内置where函数时,过滤过程非常简单容易。

There is however another little tweak that I needed to administer to improve the performance of the agent. This is due to the fact that a sign tends to be recognized multiple times, even if it was already hit some time before. I’ve tried modifying the filtering function to counter this, by filtering the pixels that are too bright (signaling a target that has been hit) but that did not fully eliminate the issue. The solution was to use a simple deque. This way, I could store the coordinates of the previous n targets and stop the agent from shooting any arrows in a given vicinity of these areas. Once the agent shoots a target, the oldest element is removed from this deque, and the current position is added to it. Before shooting, the agent obviously iterates over these coordinates and if any one of these is close enough to the point at which it wants to shoot, it simply does not do so. It’s as simple as that!

但是,我还需要进行其他一些微调,以提高代理的性能。 这是由于这样的事实,即使一个符号已经被击中了一段时间,它也往往会被多次识别。 我试图修改过滤功能以解决此问题,方法是过滤太亮的像素(对已命中的目标发出信号),但不能完全消除问题。 解决的办法是使用简单的双端队列。 这样,我可以存储先前n个目标的坐标,并阻止特工在这些区域的给定附近射击任何箭头。 一旦特工射击了目标,就会从此双端队列中移除最旧的元素,并向其添加当前位置。 在射击之前,特工显然会遍历这些坐标,并且如果其中任何一个坐标足够接近要射击的点,它就不会这样做。 就这么简单!

Image for post
As you can see, the perfect combo breaks, but the overall results are still good. (The agent hits the targets, even those that are moving.)
如您所见,完美的组合会中断,但是总体效果还是不错的。 (特工击中目标,即使是正在移动的目标。)

Now a last note before moving on to the Dodge section. During analyzing the errors of the agent, I found that sometimes it did not let go of the bow, even though it was programmed to do so. That is why I’ve tried looking around by playing the mini-game manually. After a while, I noticed that if you click too fast (meaning that you don’t hold down the mouse button for a long enough period), the character simply won’t shoot the arrow. Due to this, I had to put a relatively big (around 0.5 second) time.sleep before releasing the mouse button. This, however, led to worse gameplay, because sometimes the targets show up too fast and these delays make it impossible to catch these targets. So if you find your agent missing some targets when trying out the script, it is highly likely that it is due to this phenomenon.

现在,在继续进行“道奇”部分之前,请注意最后一个提示。 在分析代理的错误时,我发现有时即使它被编程为这样做也不会放开弓。 这就是为什么我尝试通过手动玩迷你游戏环顾四周的原因。 过了一会儿,我注意到如果单击得太快(意味着您没有长时间按住鼠标按钮),角色根本不会射出箭头。 由于这个原因,我不得不松开鼠标按钮之前,把一个比较大的(约0.5秒)time.sleep。 但是,这导致了较差的游戏玩法,因为有时目标显示得太快,并且这些延迟使得无法捕捉到这些目标。 因此,如果您发现代理在尝试脚本时缺少某些目标,则很可能是由于这种现象。

躲闪 (Dodge)

Increasing your Dodge stat gives your character some health points and increases the chances of him dodging an incoming attack (well, obviously). Now again, we don’t really need to bother with this, since thanks to the script introduced in part 1, we have top-notch defensive abilities and a ton of health points, but hey, why not automate this training, too, while we’re at it? During this training, you need to look out for the angry straw dummy and dodge its attacks… Or else you will draw the short straw… Okay, I’ll see myself out.

增加道奇的属性可以使角色获得一些健康点,并增加其躲避来袭攻击的机会(很明显)。 再说一次,我们真的不需要为此烦恼,因为多亏了第1部分中介绍的脚本,我们才拥有一流的防御能力和大量的健康要点,但是,为什么不同时使这种训练自动化我们在吗? 在这次培训中,您需要警惕愤怒的稻草假人并躲避它的攻击……否则您将抽出短...好的,我会自己解决的。

Image for post
Swords & Souls. Swords&Souls中的道奇迷你游戏。

Jokes aside, there are three different types of attacks that the dummy can perform: a headbutt, an arm swing, and a leg swing. Each of these actions has a different animation, making it extremely easy to apply template matching. And that is exactly what we will do: we will define three different template matchers, each with their own templates which correspond to these three actions. At every timestep, we will try to detect these actions and will do everything we can to avoid the incoming attacks. For the headbutt, we will make the character step backward, for the arm swing, we will make him crouch down and as for the leg swing, we will make him jump up. That’s all there is to it! As simple template search was covered already in the previous articles, I won’t drag this section out for too long. Instead, let’s have a look at the results right away to see how this method performs and then move on to the last mini-game!

除了玩笑,假人可以执行三种不同类型的攻击:头撞,手臂摆动和腿部摆动。 这些动作中的每个动作都有不同的动画,因此可以轻松地应用模板匹配。 这正是我们要做的事情:我们将定义三个不同的模板匹配器,每个匹配器都有与这三个动作相对应的自己的模板。 在每个时间步长,我们都将尝试检测这些动作,并尽一切可能避免传入的攻击。 对于头撞,我们将使角色向后退一步;对于手臂摇摆,将使他蹲下;对于腿挥动,我们将使他跳起来。 这里的所有都是它的! 由于以前的文章已经介绍了简单的模板搜索,因此我不会将这一部分拖出太长时间。 取而代之的是,让我们立即查看结果,以了解此方法的执行情况,然后继续进行最后的迷你游戏!

Image for post
The overall results are quite good. However, there are times when the combo breaks somewhere over 75–90, which may need a little bit of further engineering.
总体效果还不错。 但是,有时组合会在75-90以上的范围内折断,这可能需要进一步的工程设计。

危急 (Critical)

The more you have of the Critical stat, the more health points you have and obviously the more likely your character is to perform a critical strike that can seriously increase your overall damage output. Do we need this, when we have an overpowered character with lots of health and attack points? Not really. This is however the last mini-game in the game, so again, leaving this out and only having 4 out of 5 mini-games automated would simply feel meh… So let’s get this over with!

您拥有的暴击值越多,拥有的健康点就越多,很明显,您的角色执行暴击的可能性就越大,这可以严重增加您的整体伤害输出。 当我们拥有一个拥有大量生命值和攻击点的压倒性格时,我们需要这个吗? 并不是的。 然而,这是最后的迷你游戏,在游戏中,如此反复,剔除这一点,只具有4出5迷你游戏自动将只是觉得......因此,让我们在这个用!

Image for post
Swords & Souls. Swords&Souls 》中的关键训练迷你游戏。

The Critical training is by far the easiest mini-game in my opinion. I mean, we can even get some points if we just leave the character in AFK mode due to not clicking when the wrong sign is shown. While this sounds tempting, it would still require a lot of time to level up our Critical stats to a high enough level only by relying on this exploit. So what is the other option? Automating the training by clicking only when the right sign is shown. After the first sign, there is a brief moment when a second sign is shown. By clicking on this second sign, we can even get a star. Sounds pretty simple, right?

在我看来,Critical培训是迄今为止最简单的迷你游戏。 我的意思是,如果由于显示错误符号时未单击而将角色保留在AFK模式下,我们甚至可以获得一些积分。 尽管这听起来很诱人,但仅依靠此漏洞,仍需要大量时间才能将我们的关键统计数据升级到足够高的水平。 那么另一个选择是什么? 通过仅在显示正确的标志时单击才能自动进行培训。 在第一个标志之后,有一小段时间会显示第二个标志。 通过单击第二个标志,我们甚至可以获得一颗星星。 听起来很简单,对吧?

What are our options for solving this really simple mini-game? Well, for starters, we could use template search. The problem, however, is that the sign is interactive, meaning that some parts of it (like the mouse button) keep on changing (it keeps changing color), making it a tad bit harder to recognize. We have another option, though, which is even more simple than using a template matcher: pixel search. This is because the sign has a red outline, which color none of the other pixels in the training room have, meaning that we can base our decisions on whether we detect the existence of red pixels in a given frame or not. You could say that “bUt PiXeL SeArCh Is ToO sImPlE” and you would be right. However, I always prefer using the simplest method as long as it works reliably and delivers the performance I need. So yes, as long as it works, it does not matter whether we are talking about simple pixel search or a state-of-the-art neural network architecture specifically tailored for solving object detection in this mini-game.

解决这个非常简单的迷你游戏,我们有哪些选择? 好吧,对于初学者来说,我们可以使用模板搜索。 但是,问题在于该标志是交互式的,这意味着它的某些部分(例如鼠标按钮)不断变化(它不断变化的颜色),这使其很难识别。 不过,我们还有另一个选择,它比使用模板匹配器还要简单:像素搜索。 这是因为该标志具有红色轮廓,该颜色在训练室中没有其他像素具有,这意味着我们可以根据是否检测到给定帧中存在红色像素来做出决定。 您可能会说“错误的轴测是太过分了”,这是对的。 但是,我总是更喜欢使用最简单的方法,只要它可以可靠地工作并提供所需的性能即可。 因此,是的,只要它可行,我们在谈论简单的像素搜索还是专门为解决小型游戏中的目标检测而量身定制的最新神经网络架构都没有关系。

Image for post
Source: https://knowyourmeme.com/photos/1075794-fist-of-the-north-star
资料来源: https : //knowyourmeme.com/photos/1075794-fist-of-the-north-star

In fact, this method is so simple that the flow of the code can be summarized as:

实际上,此方法非常简单,因此代码流可以总结为:

  1. capture the screen

    捕捉屏幕
  2. crop the part that is important to us (in this case any part of the game window that has the sign popping up)

    裁剪对我们来说很重要的部分(在这种情况下,游戏窗口中会弹出标志的任何部分)
  3. apply this simple pixel search to look for red pixels

    应用此简单像素搜索以查找红色像素
  4. click where the algorithm detects the red pixel (if there is any)

    单击算法检测到红色像素的位置(如果有)
  5. repeat step 1.

    重复步骤1。

And that’s it. In fact, the whole “apply simple pixel search” part looks like this (given that img is an RGB image):

就是这样。 实际上,整个“应用简单像素搜索”部分看起来像这样(假设img是RGB图像):

Image for post

And that’s all. No neural networks, no over-engineered template matchers, or complex algorithms. Just a plain and simple pixel search algorithm. And guess what; it just works!

就这样。 没有神经网络,没有过度设计的模板匹配器,也没有复杂的算法。 只是一个简单的像素搜索算法。 你猜怎么着; 它就是有效的

Image for post
The results for this min-game are really good. I didn’t observe any combo breaking even after 200 and the agent can even collect at least 90% of the stars.
这个小游戏的结果非常好。 我什至没有观察到200点后连击就破裂,而且该代理甚至可以收集至少90%的恒星。

So, I think the key takeaway from this mini-game is that you should never exclude methods based on their simplicity. Just think outside of the box, look for the simplest method, and try it. If it works, great! If not and you can’t think of any other simple methods, then go on to something more complex. Don’t make your job any harder than it should be.

因此,我认为从这个迷你游戏中获得的主要收获是,您永远不应基于其简单性来排除方法。 只需跳出框框思考,寻找最简单的方法,然后尝试一下。 如果有效,那就太好了! 如果没有,并且您无法想到任何其他简单的方法,继续进行更复杂的操作。 不要使您的工作比应该做的难。

结论 (Conclusion)

So with that, we have successfully automated all the mini-games inside this game. Hooray! If you’ve been following this series, then congratulations, you’ve successfully completed the tutorial phase of the Automating is Fun series! Now you have seen a few examples of how you can go about automating online games as well as some technical details, and lastly, you have seen why it is way harder to solve tasks this way. That’s because as an outsider, you don’t have access to the inner states of the environment in the game and therefore you have to “fight” to get these data by relying on computer vision, etc. and deal with delays, noises, and other real problems. Unlike when your script is a part of the environment and therefore has access to all the data you could possibly need. With that being said, in the next article, we will finally move on from this online game and solve a brand new task. So stay tuned!

因此,我们已经成功地自动化了该游戏中的所有迷你游戏。 万岁! 如果您一直在关注本系列,那么恭喜您,您已经成功完成了“自动化就是乐趣”系列的教程阶段! 现在,您已经看到了一些有关如何使网络游戏自动化的示例,以及一些技术细节,最后,您已经看到了为什么以这种方式解决任务更加困难。 这是因为作为局外人,您无权访问游戏中环境的内部状态,因此您必须“战斗”以依靠计算机视觉等来获取这些数据,并处理延迟,噪音和其他实际问题。 不同于脚本是环境的一部分,因此可以访问您可能需要的所有数据。 话虽如此,在下一篇文章中,我们最终将继续进行此在线游戏并解决一项全新的任务。 敬请期待!

Image for post
Source: http://www.quickmeme.com/meme/3p7ku7
资料来源: http : //www.quickmeme.com/meme/3p7ku7

(Code)

As usual, all the code related to this article can be found on my GitHub profile (https://github.com/automatingisfun), or you can directly go to the desired script by clicking on one of the following links:

与往常一样,与本文相关的所有代码都可以在我的GitHub个人资料( https://github.com/automatingisfun )上找到,或者您可以通过单击以下链接之一直接转到所需的脚本:

翻译自: https://medium.com/swlh/automating-swords-souls-training-part-3-25f09bd7e936

java老版手机游戏剑魂

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值