[ PHP ] – Poker Shuffle 撲克洗牌

用 php 實作 撲克洗牌

<?php

$icon=['♥'=>'red','♠'=>'black','♣'=>'black','♦'=>'red'];
$n=['A','2','3','4','5','6','7','8','9','10','J','Q','K'];
$cards=[];
foreach ($icon as $icon_k => $icon_v) { 
	//echo $icon_k.' _ '.$icon_v; echo '<br/>';
	foreach ($n as $n_k){
		echo $icon_k.' _ '.$icon_v.'_'.$n_k; echo '<br/>';
		array_push($cards,$icon_k.' _ '.$icon_v.'_'.$n_k);
	}
}
echo '<hr/>';
echo '原始陣列<br/>';
print_r($cards);
shuffle($cards);
echo '<hr/>';
echo '洗牌後陣列<br/>';
print_r($cards);
echo '<hr/>';
echo '第一種發牌方法存到陣列<br/>';
$gamer1=[];
$gamer2=[];
$gamer3=[];
$gamer4=[];
for($j=0;$j<4;$j++){ //四個玩家
	$k=$j*13;
	for($i=$k;$i<(12+$k);$i++){ //每人發13張牌
		
		array_push(${'gamer'.($j+1)},$cards[$i]);
	}
	echo '<br/>gamer'.($j+1).'<br/>';
	print_r(${'gamer'.($j+1)});
}

echo '<hr/>';
echo '第二種發牌方法直接輸出陣列<br/>';

for($j=0;$j<4;$j++){ //四個玩家
	$k=$j*13;
	for($i=$k;$i<(12+$k);$i++){ //每人發13張牌
		echo 'gamer'.($j+1).'_'.current($cards).'<br/>'; 
		next($cards);
	}
	next($cards);
	echo '<br/>';
}

♥ _ red_A
♥ _ red_2
♥ _ red_3
♥ _ red_4
♥ _ red_5
♥ _ red_6
♥ _ red_7
♥ _ red_8
♥ _ red_9
♥ _ red_10
♥ _ red_J
♥ _ red_Q
♥ _ red_K
♠ _ black_A
♠ _ black_2
♠ _ black_3
♠ _ black_4
♠ _ black_5
♠ _ black_6
♠ _ black_7
♠ _ black_8
♠ _ black_9
♠ _ black_10
♠ _ black_J
♠ _ black_Q
♠ _ black_K
♣ _ black_A
♣ _ black_2
♣ _ black_3
♣ _ black_4
♣ _ black_5
♣ _ black_6
♣ _ black_7
♣ _ black_8
♣ _ black_9
♣ _ black_10
♣ _ black_J
♣ _ black_Q
♣ _ black_K
♦ _ red_A
♦ _ red_2
♦ _ red_3
♦ _ red_4
♦ _ red_5
♦ _ red_6
♦ _ red_7
♦ _ red_8
♦ _ red_9
♦ _ red_10
♦ _ red_J
♦ _ red_Q
♦ _ red_K


原始陣列
Array ( [0] => ♥ _ red_A [1] => ♥ _ red_2 [2] => ♥ _ red_3 [3] => ♥ _ red_4 [4] => ♥ _ red_5 [5] => ♥ _ red_6 [6] => ♥ _ red_7 [7] => ♥ _ red_8 [8] => ♥ _ red_9 [9] => ♥ _ red_10 [10] => ♥ _ red_J [11] => ♥ _ red_Q [12] => ♥ _ red_K [13] => ♠ _ black_A [14] => ♠ _ black_2 [15] => ♠ _ black_3 [16] => ♠ _ black_4 [17] => ♠ _ black_5 [18] => ♠ _ black_6 [19] => ♠ _ black_7 [20] => ♠ _ black_8 [21] => ♠ _ black_9 [22] => ♠ _ black_10 [23] => ♠ _ black_J [24] => ♠ _ black_Q [25] => ♠ _ black_K [26] => ♣ _ black_A [27] => ♣ _ black_2 [28] => ♣ _ black_3 [29] => ♣ _ black_4 [30] => ♣ _ black_5 [31] => ♣ _ black_6 [32] => ♣ _ black_7 [33] => ♣ _ black_8 [34] => ♣ _ black_9 [35] => ♣ _ black_10 [36] => ♣ _ black_J [37] => ♣ _ black_Q [38] => ♣ _ black_K [39] => ♦ _ red_A [40] => ♦ _ red_2 [41] => ♦ _ red_3 [42] => ♦ _ red_4 [43] => ♦ _ red_5 [44] => ♦ _ red_6 [45] => ♦ _ red_7 [46] => ♦ _ red_8 [47] => ♦ _ red_9 [48] => ♦ _ red_10 [49] => ♦ _ red_J [50] => ♦ _ red_Q [51] => ♦ _ red_K )


洗牌後陣列
Array ( [0] => ♥ _ red_9 [1] => ♣ _ black_K [2] => ♣ _ black_Q [3] => ♠ _ black_Q [4] => ♣ _ black_A [5] => ♥ _ red_7 [6] => ♥ _ red_J [7] => ♣ _ black_8 [8] => ♦ _ red_4 [9] => ♠ _ black_10 [10] => ♦ _ red_9 [11] => ♥ _ red_5 [12] => ♥ _ red_2 [13] => ♥ _ red_10 [14] => ♣ _ black_10 [15] => ♦ _ red_6 [16] => ♣ _ black_6 [17] => ♥ _ red_K [18] => ♠ _ black_8 [19] => ♣ _ black_4 [20] => ♠ _ black_5 [21] => ♦ _ red_J [22] => ♦ _ red_5 [23] => ♠ _ black_6 [24] => ♦ _ red_2 [25] => ♦ _ red_7 [26] => ♦ _ red_A [27] => ♠ _ black_A [28] => ♠ _ black_2 [29] => ♦ _ red_K [30] => ♠ _ black_J [31] => ♣ _ black_J [32] => ♣ _ black_7 [33] => ♦ _ red_3 [34] => ♠ _ black_4 [35] => ♥ _ red_Q [36] => ♣ _ black_5 [37] => ♥ _ red_8 [38] => ♥ _ red_3 [39] => ♠ _ black_3 [40] => ♣ _ black_9 [41] => ♠ _ black_7 [42] => ♠ _ black_9 [43] => ♠ _ black_K [44] => ♦ _ red_10 [45] => ♦ _ red_8 [46] => ♥ _ red_6 [47] => ♥ _ red_4 [48] => ♣ _ black_2 [49] => ♣ _ black_3 [50] => ♥ _ red_A [51] => ♦ _ red_Q )


第一種發牌方法存到陣列

gamer1
Array ( [0] => ♥ _ red_9 [1] => ♣ _ black_K [2] => ♣ _ black_Q [3] => ♠ _ black_Q [4] => ♣ _ black_A [5] => ♥ _ red_7 [6] => ♥ _ red_J [7] => ♣ _ black_8 [8] => ♦ _ red_4 [9] => ♠ _ black_10 [10] => ♦ _ red_9 [11] => ♥ _ red_5 )
gamer2
Array ( [0] => ♥ _ red_10 [1] => ♣ _ black_10 [2] => ♦ _ red_6 [3] => ♣ _ black_6 [4] => ♥ _ red_K [5] => ♠ _ black_8 [6] => ♣ _ black_4 [7] => ♠ _ black_5 [8] => ♦ _ red_J [9] => ♦ _ red_5 [10] => ♠ _ black_6 [11] => ♦ _ red_2 )
gamer3
Array ( [0] => ♦ _ red_A [1] => ♠ _ black_A [2] => ♠ _ black_2 [3] => ♦ _ red_K [4] => ♠ _ black_J [5] => ♣ _ black_J [6] => ♣ _ black_7 [7] => ♦ _ red_3 [8] => ♠ _ black_4 [9] => ♥ _ red_Q [10] => ♣ _ black_5 [11] => ♥ _ red_8 )
gamer4
Array ( [0] => ♠ _ black_3 [1] => ♣ _ black_9 [2] => ♠ _ black_7 [3] => ♠ _ black_9 [4] => ♠ _ black_K [5] => ♦ _ red_10 [6] => ♦ _ red_8 [7] => ♥ _ red_6 [8] => ♥ _ red_4 [9] => ♣ _ black_2 [10] => ♣ _ black_3 [11] => ♥ _ red_A )


第二種發牌方法直接輸出陣列
gamer1_♥ _ red_9
gamer1_♣ _ black_K
gamer1_♣ _ black_Q
gamer1_♠ _ black_Q
gamer1_♣ _ black_A
gamer1_♥ _ red_7
gamer1_♥ _ red_J
gamer1_♣ _ black_8
gamer1_♦ _ red_4
gamer1_♠ _ black_10
gamer1_♦ _ red_9
gamer1_♥ _ red_5

gamer2_♥ _ red_10
gamer2_♣ _ black_10
gamer2_♦ _ red_6
gamer2_♣ _ black_6
gamer2_♥ _ red_K
gamer2_♠ _ black_8
gamer2_♣ _ black_4
gamer2_♠ _ black_5
gamer2_♦ _ red_J
gamer2_♦ _ red_5
gamer2_♠ _ black_6
gamer2_♦ _ red_2

gamer3_♦ _ red_A
gamer3_♠ _ black_A
gamer3_♠ _ black_2
gamer3_♦ _ red_K
gamer3_♠ _ black_J
gamer3_♣ _ black_J
gamer3_♣ _ black_7
gamer3_♦ _ red_3
gamer3_♠ _ black_4
gamer3_♥ _ red_Q
gamer3_♣ _ black_5
gamer3_♥ _ red_8

gamer4_♠ _ black_3
gamer4_♣ _ black_9
gamer4_♠ _ black_7
gamer4_♠ _ black_9
gamer4_♠ _ black_K
gamer4_♦ _ red_10
gamer4_♦ _ red_8
gamer4_♥ _ red_6
gamer4_♥ _ red_4
gamer4_♣ _ black_2
gamer4_♣ _ black_3
gamer4_♥ _ red_A

!去下營經續永站本助幫能就下一點輕輕,話的您到助幫有章文的我果如 如果我的文章有幫助到您的話,輕輕點一下就能幫助本站永續經營下去!

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *