石头剪刀布机器人算法

发布于 2024-12-26 01:55:04 字数 125 浏览 4 评论 0原文

在我的学校,我们的老师正在举办石头剪刀布机器人比赛。我知道如何用 Python 编程,但我不知道如何编写一个比随机选择武器的机器人更有成功机会的机器人。我认为可以存储所有先前的动作,然后寻找模式以抵御攻击。我的方向正确吗?有什么想法吗?

In my school our teacher is holding a Rock, paper, scissors bot competition. I know how to program in Python, but I have no idea how to program a bot that would have a bigger chance of success than one that randomly selects its weapons. I think it is possible to store all previous moves and then look for patterns in order to defy attacks. Am I going in a right direction? Any ideas?

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

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

发布评论

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

评论(4

半窗疏影 2025-01-02 01:55:04

事实证明,对于剪刀石头布,随机机器人将位于每个等级的中间

因此,我创建一组机器人,每个机器人计算一个启发式并在后台并行运行。对于每个回合,每个机器人实际上都会“抽签”并检查他是否赢了或输了 - 是否会玩这个回合。每个机器人都会记录如果它玩的话它会赢多少场比赛,以及它会输多少场比赛。

这些机器人之一将是随机攻击者。

每次轮到你时:选择迄今为止获胜最多的机器人[贪婪] - 并使用它。

使用这种方法,您保证在班级中名列前茅! [当然要有足够的游戏轮数]

It is proven for rock-paper-scissors that a random bot will be at the median of each rank.

Therefore, I'd create a set of bots, each calculating one heuristic and running on the background on parallel. For each turn, each bot will virtually "draw" and check if he had won or lost - if it would have played this turn. Each bot will keep track on how many games it would have won if it played, and how many it would have lost.

One of these bots will be the random attacker.

Each time it is your turn: choose which bot won so far the most [greedy] - and use it.

Using this approach you are guaranteed to be at the top median of your class! [with enough rounds of games of course]

夏夜暖风 2025-01-02 01:55:04

如果你正在与人类对抗,那么你就走在正确的轨道上。存储以前的动作是关键。这里有两篇文章将对您有所帮助。 如何在石头、剪刀、布中取胜。以及维基百科关于策略和算法的条目。

If you are playing against humans, you are on the right track. Storing previous moves is key. Here are two articles that will prove helpful to you. How to win at rock, paper, scissors. And wikipedia's entry on strategy and algorithms.

云胡 2025-01-02 01:55:04

石头剪刀布编程竞赛网站包含大量的竞赛程序(甚至是用Python编写的)。

如果这是您的学校作业,则可能会被视为作弊,因为所有提交的来源都是公开的。但是,话又说回来,其他学生也可以使用它们。

Rock Paper Scissors Programming Competition site contains a large number of competing programs (they are even written in python).

If this is your school assignment, it may be considered cheating, because all submitted sources are publicly available. But, then again, they are available to other students too.

许仙没带伞 2025-01-02 01:55:04

尝试弄清楚其他机器人的策略可能会带来一些潜在的利润,例如,如果是强制参与,就会有一些懒惰的学生编造一个总是扔剪刀的机器人。

我提出了另一种策略(我在一些类似的比赛中听说过,但无法再追踪来源),假设你可以让几个机器人运行(如果没有,与你的一些同学合作运行这个策略)。

假设您有 4 个机器人 A、B、C、D,

想象每个机器人与其他机器人对战 100 次。让您的 B、C、D 机器人首先玩 10 次,玩一个策略,让其识别为您团队中的机器人,说“RPPSPPSSRS”,让您的 A 机器人玩一些其他策略,让它被识别由机器人 B、C、D 执行。

然后,在接下来的 90 轮中,让机器人 B、C、D 输给 A(“纸”),并随机与其他机器人进行比赛。让机器人 A 从 B、C、D 中获胜(“剪刀”),并随机与其他机器人进行比赛。

因此,机器人A获得了巨大的优势。

Where might be some potential profit in trying to figure out the strategies of the other bots, for instance, if it's a forced participation, there will be some lazy student who makes up a bot that would always throw up scissors.

I propose another strategy (I've heard about it on some similar competition, but can't track the source anymore), suppose that you could let several bots running (if not, cooperate with some of your classmates to run this strategy).

Let's say you have 4 bots A,B,C,D

Imagine each bot play 100 times against the others. Let your B,C,D bots play for the first let's say 10 times play a strategy that would let recognise it as a bot from your team, say 'RPPSPPSSRS', let your A bot play some other strategy that would let it be recognized by the bots B,C,D.

Then, in the next 90 round let the bots B,C,D lose ('paper') to the A and play random against the others. Let the bot A win ('scissors') from the B,C,D and play random against the others.

Thus, the bot A gets a huge advantage.

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