逻辑/概率问题:从袋子里挑选
我正在编写一个棋盘游戏,其中有一袋可能的棋子。每回合,玩家按照一定的规则从袋子中随机取出棋子。
对于我的实施来说,最初将包分成一个或多个玩家的池可能会更容易。这些池子将是随机选择的,但现在不同的玩家将从不同的袋子中挑选。这有什么不同吗?
如果一名玩家的包用完,更多的包会从总库存中随机放入。
I'm coding a board game where there is a bag of possible pieces. Each turn, players remove randomly selected pieces from the bag according to certain rules.
For my implementation, it may be easier to divide up the bag initially into pools for one or more players. These pools would be randomly selected, but now different players would be picking from different bags. Is this any different?
If one player's bag ran out, more would be randomly shuffled into it from the general stockpile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只要:
两种方法(“原始”使用一个大的普通袋,“修改”使用一个台球袋每个玩家的概率是相等的。
只有在游戏结束时,一些玩家的包是空的,才可以从 100% 仍在玩的物品中挑选,因此,他们应该这样做。两者都从他们挑选的袋子中挑选,并且[当然,盲目地]从所述袋子中挑选一件物品。
这个问题说明了概率的一个有趣特征,即概率与一个人对情况的了解程度有关
编辑:
尽管这两个过程完全等价的断言在数学上是有效的,但在包含机会成分的游戏中,感知是一个重要因素(特别是如果游戏还包含金钱部分)。为了避免不理解这个公平性的玩家的愤怒,你可以坚持原来的程序......
So long as:
The two approaches ("original" with one big common bag, "modified" with one pool bag per player are equivalent with regards to probabilities.
It only gets a bit tricky towards the end of the game, when some of players' bags are empty. The fairest to let pick from 100% of the items still in play, hence, they should both pick from which bag they pick and [blindly,of course] pick one item from said bag.
This problem illustrate an interesting characteristic of probabilities which is that probabilities are relative to the amount of knowledge one has about the situation. For example the game host may well know that the "pool" bag assigned to say player X does not include any say Letter "A" (thinking about scrabble), but so long as none of the players know this (and so long as the partitions into pool bag was fully random), the game remains fair, and player "X" still has to assume that his/her probably of hitting an "A" the next time a letter is drawn, is the same as if all remaining letters were available to him/her.
Edit:
Not withstanding the mathematical validity of the assertion that both procedures are fully equivalent, perception is an important factor in games that include a chance component (in particular if the game also includes a pecuniary component). To avoid the ire of players who do not understand this equity, you may stick to the original procedure...
根据游戏规则,@mjv 是对的,初始随机划分不会影响概率。这类似于 n 个玩家从面朝下的牌组中依次抽牌的游戏:牌组的初始洗牌是随机划分为每个玩家的牌“袋”。
但如果您在每次抽奖后更换物品,那么一袋或多袋都很重要。对于一个袋子,任何特定物品最终都会被任何玩家以相同的概率抽取。对于许多袋子,该物品只能由最初放置该物品的袋子的玩家绘制。
弹出到软件级别,如果游戏需要单个袋子,我建议只是这样编程:它应该是不比n袋困难,而且你不必证明新游戏与旧游戏等效。
Depending on the game rules, @mjv is right, the initial random division doesn't affect the probabilities. This is analogous to a game where n players draw cards in turn from a face down deck: the initial shuffle of the deck is the random division into the "bags" of cards for each player.
But if you replace the items after each draw, it does matter if there is one bag or many. With one bag any particular item will eventually be drawn by any player with the same probability. With many bags, that item can only be drawn by the player whose bag it was initially placed in.
Popping up to the software level, if the game calls for a single bag, I'd recommend just programming it that way: it should be no more difficult than n bags, and you don't have to prove the new game equivalent to the old.
我的直觉告诉我,将随机的事物集合划分为更小的随机子集将保持同样的随机性……无论玩家是从大池还是小池中进行选择(反过来,将自己放入大池中)
对于游戏来说,随机的恕我直言就足够了!
My intuition tells me that dividing a random collection of things into smaller random subsets would remains equally random... doesn't matter if a player picks from a big pool or a smaller one (that in turns, feed itself into the big one)
For a game it is enough random IMHO!
根据安全性的重要性,这可能没问题(如果涉及金钱(您或他们)不要这样做)。我不完全确定从无知的玩家的角度来看它的随机性会降低。
a) 不要指望他们无知,你的程序可能会被破解,然后他们就会知道会出现什么问题
b) 以不引入漏洞的方式填充袋子将非常棘手。例如,让我们采用简单的算法,随机挑选一个并将其放入第一个桶中,将其取出,然后对第二个桶执行相同的操作,依此类推。您只需确保如果有 N 个棋子,第一个玩家有 1/N 挑选给定棋子的概率,第二个玩家有 1/(N-1),第三个玩家有 1/(N-3) 和很快。然后,玩家可以分析已经玩过的棋子,以计算出其他玩家持有某些棋子的概率。
我认为下面的算法可能会更好,但几乎所有人在第一次想出新算法时都会犯概率错误。不要使用这个,只要明白它可能覆盖了我谈到的安全漏洞:
为每个玩家标记的物品数量(注意:根据 N 和 P,可能需要比你能活的时间更长的时间)
即使如此,您可能仍然存在漏洞,让其他人可以通过漏洞利用来找出他们的存储桶中的内容。坚持使用组合池,真正随机选择仍然很棘手,但它会让你的生活更轻松。
编辑:我知道语气听起来有点生涩。我主要为那些可能会断章取义地阅读本文并尝试其中一些算法的人提供所有粗体内容。我真的祝你一切顺利:-)
编辑2:经过进一步考虑,我认为按顺序挑选的问题可能会减少到首先让玩家轮流。如果这已经在规则中,那可能并不重要。
Depending on how crucial security is, it might be okay (if money is involved (you or them) DO NOT DO THAT). I'm not entirely sure it would be less random from the perspective of an ignorant player.
a) Don't count on them being ignorant, your program could be cracked and then they would know what pieces are coming up
b) It would be very tricky to fill the bags in such a way that you don't introduce vulnerabilities. For instance, let's take the naive algorithm of picking one randomly and putting it in a the first bucket, taking it out, and then doing the same for the second bucket and so on. You just ensured that if there are N pieces, the first player had a probability of 1/N of picking a given piece, the second player had a 1/(N-1), the third had 1/(N-3) and so on. Players can then analyze the pieces already played in order to figure out the probabilities that other players are holding certain pieces.
I THINK the following algorithm might work better, but almost all people get probability wrong the first time they come up with a new algorithm. DON'T USE THIS, just understand that it might cover the security vulnerability I talked about:
number of items marked for each player (NOTE: May take much longer than you may live depending on N and P)
Even then after all this, you might still have a vulnerability to someone figuring out what's in their bucket from an exploit. Stick with a combined pool, it's still tricky to pick really randomly, but it will make your life easier.
Edit: I know the tone sounds kind of jerky. I mostly included all that bold for people who might read this out of context and try some of these algorithms. I really wish you well :-)
Edit 2: On further consideration, I think that the problem with picking in order might reduce to having players taking turns in the first place. If that's in the rules already it might not matter.