Werden wir Helden für einen Tag

Home | About | Archive

原子彈炸烏蠅之打牌矛骰仔典扇巧?

Posted on Feb 3, 2009 by Chung-hong Chan

家中有盒 Pictionary 不見了骰仔 ((我其實更愛玩無需骰仔的遊戲,如 Hearts 。)) ,每次玩都要從麻雀拿一粒骰仔頂當,都幾煩。
電腦抽(假)亂數,好像比骰仔還好。網上 Search 下有十九幾萬個軟件模疑骰仔。但以我每每喜歡原子彈炸烏蠅的作風,我發現用來做統計分析的 R 可以模疑骰仔。
網上找找見到這樣的一句:

dsize < - 6
nrolls <- 1
ndice <- 1
matrix(sample(dsize, nrolls * ndice, replace = TRUE), nrolls, ndice)

甚至可以將它 Function 之

dice.sim < - function(dsize=6,nrolls=1,ndice=1) {
matrix(sample(dsize, nrolls * ndice, replace = TRUE), nrolls, ndice)
}

只需要改變三個參數

dsize: 骰子面數,即最大幾多點
nrolls: 擲骰幾次
ndice: 一次擲幾多粒

多數遊戲數是用六面骰擲一次,每次一粒。例如玩 Pictionary 或飛行棋。


> dice.sim()
[,1]
[1,] 2

如果打麻雀,六面骰擲一次,每次三粒。 ((術語叫做 3d6 ))


> dice.sim(6,1,3)
[,1] [,2] [,3]
[1,] 5 6 1

又例如玩龍與地下城,打架時要擲廿面骰一次,每次一粒。

> dice.sim(20,1,1)
[,1]
[1,] 11

假如你只關心骰仔點數總和。上面麻雀例子可改為:

> sum(dice.sim(6,1,3))
[1] 9

由此可見我這個人都相當無聊。


Powered by Jekyll and profdr theme