PHP Shuffle Multiple Decks

时间:2013-06-28 00:49:47

标签: php shuffle blackjack

我有以下PHP代码,它会洗牌1个牌组;然而 - 我正打算像一个赌场在二十一点游戏中那样洗牌6副牌。有关如何实现这一目标的任何想法?

    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;
        }

3 个答案:

答案 0 :(得分:0)

这样的东西?

$decks = array_merge($deck1, $deck2, ...);
shuffle($decks);

答案 1 :(得分:0)

像这样。

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);

答案 2 :(得分:0)

所以我基本上使用以下方法解决了这个问题(首先我按顺序将所有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];
        }