我有下面的PHP代码,它洗牌1副牌;然而-我希望洗牌6像赌场一样在21点游戏。对如何实现这一点有什么想法吗?
private $suites = array('c', 'd', 'h', 's');
private $ranks = array('2', '3', '4', '5', '6', '7', '8', '9', 't', 'j', 'q', 'k', 'a');
private $deck = array();
for ($i = 0; $i < count($this->deck); $i++) {
$r = $i + rand(0, 51 - $i);
$temp = $this->deck[$i];
$this->deck[$i] = $this->deck[$r];
$this->deck[$r] = $temp;
}发布于 2013-06-28 08:54:33
像这样的东西?
$decks = array_merge($deck1, $deck2, ...);
shuffle($decks);发布于 2013-06-28 08:55:28
就像这样。
CONST COUNT_DECKS = 6;
$suites = array('c', 'd', 'h', 's');
$ranks = array('2', '3', '4', '5', '6', '7', '8', '9', 't', 'j', 'q', 'k', 'a');
$deck = array();
for ($i = 0; $i < COUNT_DECKS; $i++)
foreach ($ranks as $rank)
foreach ($suites as $suit)
$deck[] = $suit . $rank;
shuffle($deck);
var_dump($deck);发布于 2013-06-28 09:48:47
因此,我基本上使用以下方法解决了这个问题(首先,我按顺序加载了包含所有52张卡的$deck1。
for($i =0;$i<6;$i++){
$decks = array_merge($decks,$deck1);
}
shuffle($decks);
for ($i = 0; $i < count($this->deck); $i++) {
$this->deck[$i] = $decks[$i];
}https://stackoverflow.com/questions/17355545
复制相似问题