参数 :
$Poker 是一个数组
"size": 1 - 13 表示
$size_arr = ['A','二','三','四','五','六','七','八','九','十','J','Q','K'];
"tag": 1 - 4 表示
$tag_arr = ['黑桃','红桃','梅花','方片'];
例子:
同花顺
$Poker = [
['size' => 1,'tag' => 3,'name' => '梅花A'],
['size' => 2,'tag' => 3,'name' => '梅花二'],
['size' => 3,'tag' => 3,'name' => '梅花三'],
['size' => 4,'tag' => 3,'name' => '梅花四'],
['size' => 5,'tag' => 3,'name' => '梅花五']
];
炸弹牛
$Poker = [
['size' => 1,'tag' => 1,'name' => '黑桃A'],
['size' => 1,'tag' => 2,'name' => '红桃A'],
['size' => 1,'tag' => 3,'name' => '梅花A'],
['size' => 1,'tag' => 4,'name' => '方片A'],
['size' => 5,'tag' => 3,'name' => '梅花五']
];
五花牛
$Poker = [
['size' => 11,'tag' => 1,'name' => '黑桃J'],
['size' => 11,'tag' => 2,'name' => '红桃J'],
['size' => 12,'tag' => 3,'name' => '梅花Q'],
['size' => 12,'tag' => 4,'name' => '方片Q'],
['size' => 13,'tag' => 3,'name' => '梅花K']
];
五小牛
$Poker = [
['size' => 1,'tag' => 1,'name' => '黑桃A'],
['size' => 1,'tag' => 2,'name' => '红桃A'],
['size' => 2,'tag' => 3,'name' => '梅花二'],
['size' => 2,'tag' => 4,'name' => '方片二'],
['size' => 3,'tag' => 3,'name' => '梅花三']
];
葫芦牛
$Poker = [
['size' => 1,'tag' => 1,'name' => '黑桃A'],
['size' => 1,'tag' => 2,'name' => '红桃A'],
['size' => 1,'tag' => 3,'name' => '梅花A'],
['size' => 9,'tag' => 4,'name' => '方片九'],
['size' => 9,'tag' => 3,'name' => '梅花九']
];
同花
$Poker = [
['size' => 1,'tag' => 3,'name' => '梅花A'],
['size' => 2,'tag' => 3,'name' => '梅花二'],
['size' => 3,'tag' => 3,'name' => '梅花三'],
['size' => 4,'tag' => 3,'name' => '梅花四'],
['size' => 9,'tag' => 3,'name' => '梅花九']
];
顺子
$Poker = [
['size' => 1,'tag' => 3,'name' => '梅花A'],
['size' => 2,'tag' => 3,'name' => '梅花二'],
['size' => 3,'tag' => 3,'name' => '梅花三'],
['size' => 4,'tag' => 3,'name' => '梅花四'],
['size' => 5,'tag' => 4,'name' => '方片五']
];
牛牛
$Poker = [
['size' => 4,'tag' => 3,'name' => '梅花四'],
['size' => 6,'tag' => 3,'name' => '梅花六'],
['size' => 5,'tag' => 3,'name' => '梅花五'],
['size' => 5,'tag' => 4,'name' => '方片五'],
['size' => 10,'tag' => 3,'name' => '梅花十']
];
牛一
$Poker = [
['size' => 4,'tag' => 3,'name' => '梅花四'],
['size' => 5,'tag' => 3,'name' => '梅花五'],
['size' => 6,'tag' => 3,'name' => '梅花六'],
['size' => 6,'tag' => 4,'name' => '方片六'],
['size' => 10,'tag' => 3,'name' => '梅花十']
];
没牛
$Poker = [
['size' => 4,'tag' => 3,'name' => '梅花四'],
['size' => 5,'tag' => 3,'name' => '梅花五'],
['size' => 6,'tag' => 4,'name' => '方片六'],
['size' => 6,'tag' => 3,'name' => '梅花六'],
['size' => 7,'tag' => 3,'name' => '梅花七']
];
代码:
/**
* 获取牛牛牌类型
* @param array $Poker 扑克牌 数据
* @return array
*/
function GetPokerType($Poker){
if($Poker){
if($Poker[0]['size'] == 1 && $Poker[1]['size'] == 10 && $Poker[2]['size'] == 11 && $Poker[3]['size'] == 12 && $Poker[4]['size'] == 13){
if ($Poker[0]['tag'] == $Poker[1]['tag'] && $Poker[0]['tag'] == $Poker[2]['tag'] && $Poker[0]['tag'] == $Poker[3]['tag'] && $Poker[0]['tag'] == $Poker[4]['tag']) {
// 同花顺 10 J Q K A
return [
'type' => 10,
'size' => $Poker[0]['size'],
'tag' => $Poker[0]['tag'],
't_name' => '同花顺'
];
}else{
// 顺子 10 J Q K A
return [
'type' => 4,
'size' => $Poker[0]['size'],
'tag' => $Poker[0]['tag'],
't_name' => '同花顺'
];
}
}
if($Poker[0]['size']+1 == $Poker[1]['size'] && $Poker[0]['size']+2 == $Poker[2]['size'] && $Poker[0]['size']+3 == $Poker[3]['size'] && $Poker[0]['size']+4 == $Poker[4]['size'] && $Poker[0]['tag'] == $Poker[1]['tag'] && $Poker[0]['tag'] == $Poker[2]['tag'] && $Poker[0]['tag'] == $Poker[3]['tag'] && $Poker[0]['tag'] == $Poker[4]['tag']){
return [
'type' => 10,
'size' => $Poker[4]['size'],
'tag' => $Poker[4]['tag'],
't_name' => '同花顺'
];
}else if ($Poker[0]['size'] == $Poker[1]['size'] && $Poker[0]['size'] == $Poker[2]['size'] && $Poker[0]['size'] == $Poker[3]['size'] || $Poker[1]['size'] == $Poker[2]['size'] && $Poker[1]['size'] == $Poker[3]['size'] && $Poker[1]['size'] == $Poker[4]['size']) {
return [
'type' => 9,
'size' => $Poker[2]['size'],
'tag' => $Poker[2]['tag'],
't_name' => '炸弹牛'
];
}else if (in_array($Poker[0]['size'], [11,12,13]) && in_array($Poker[1]['size'], [11,12,13]) && in_array($Poker[2]['size'], [11,12,13]) && in_array($Poker[3]['size'], [11,12,13]) && in_array($Poker[4]['size'], [11,12,13])) {
return [
'type' => 8,
'size' => $Poker[4]['size'],
'tag' => $Poker[4]['tag'],
't_name' => '五花牛'
];
}else if (($Poker[0]['size'] + $Poker[1]['size'] + $Poker[2]['size'] + $Poker[3]['size'] + $Poker[4]['size']) <= 10){
return [
'type' => 7,
'size' => $Poker[4]['size'],
'tag' => $Poker[4]['tag'],
't_name' => '五小牛'
];
}else if ($Poker[0]['size'] == $Poker[1]['size'] && $Poker[0]['size'] == $Poker[2]['size'] && $Poker[3]['size'] == $Poker[4]['size'] || $Poker[0]['size'] == $Poker[1]['size'] && $Poker[3]['size'] == $Poker[2]['size'] && $Poker[3]['size'] == $Poker[4]['size']) {
return [
'type' => 6,
'size' => $Poker[2]['size'],
'tag' => $Poker[2]['tag'],
't_name' => '葫芦'
];
}else if ($Poker[0]['tag'] == $Poker[1]['tag'] && $Poker[0]['tag'] == $Poker[2]['tag'] && $Poker[0]['tag'] == $Poker[3]['tag'] && $Poker[0]['tag'] == $Poker[4]['tag']) {
return [
'type' => 5,
'size' => $Poker[4]['size'],
'tag' => $Poker[4]['tag'],
't_name' => '同花'
];
}else if ($Poker[0]['size']+1 == $Poker[1]['size'] && $Poker[0]['size']+2 == $Poker[2]['size'] && $Poker[0]['size']+3 == $Poker[3]['size'] && $Poker[0]['size']+4 == $Poker[4]['size']) {
return [
'type' => 4,
'size' => $Poker[4]['size'],
'tag' => $Poker[4]['tag'],
't_name' => '顺子'
];
}else{
// 判断有没有牛
$num = niuniu($Poker);
if ($num == 0) {
return [
'type' => 3,
'size' => $Poker[4]['size'],
'tag' => $Poker[4]['tag'],
't_name' => '牛牛'
];
}else if ($num != 11) {
$size_arr = ['一','二','三','四','五','六','七','八','九'];
return [
'type' => 2,
'num' => $num,
'size' => $Poker[4]['size'],
'tag' => $Poker[4]['tag'],
't_name' => '牛'.$size_arr[$num-1]
];
}else{
return [
'type' => 1,
'size' => $Poker[4]['size'],
'tag' => $Poker[4]['tag'],
't_name' => '没牛'
];
}
}
}
}
/**
* 判断有没有牛
* @param array $Poker 玩家扑克牌数据
* @return string 0 - 9 牛牛 - 九牛 11 没牛
**/
function niuniu($Poker){
// 十种组合可能性
$array = [
'0' => [[0,1],[2,3,4]],
'1' => [[0,2],[1,3,4]],
'2' => [[0,3],[1,2,4]],
'3' => [[0,4],[1,2,3]],
'4' => [[1,2],[0,3,4]],
'5' => [[1,3],[0,2,4]],
'6' => [[1,4],[0,3,4]],
'7' => [[2,3],[0,1,4]],
'8' => [[2,4],[0,1,3]],
'9' => [[3,4],[0,1,2]]
];
// 判断大小为 JQK 时 值为 10
foreach ($Poker as $key => $value) {
if (in_array($value['size'], [11,12,13])) {
$Poker[$key]['size'] = 10;
}
}
foreach ($array as $key => $value) {
$count1 = 0;
$count2 = 0;
foreach ($value[1] as $key => $value2) {
$count2 = $Poker[$value2]['size'] + $count2;;
}
$num2 = $count2/10;
if (is_int($num2)) {
foreach ($value[0] as $key => $value1) {
$count1 = $Poker[$value1]['size'] + $count1;
}
$num1 = $count1%10;
return $num1;
}
}
return $num1 = 11;
}
$type1 = GetPokerType($Poker1);
$type2 = GetPokerType($Poker2);
/**
* 判断牛牛输赢
* @param array $type1
* @param array $type2
* @return array
*/
function PokerWinning1($type1,$type2){
if ($type1['type']>$type2['type']) {
return true;
}else if ($type1['type']<$type2['type']){
return false;
}else{
if ($type1['size'] != $type2['size']) {
$result = compare($type1['size'],$type2['size'],'size');
}else{
$result = compare($type1['tag'],$type2['tag'],'tag');
}
return $result;
}
}
// 牛牛比大小
function compare($data1,$data2,$datatype){
//size(大小): 1-13
if ($datatype == 'size') { // 大小
if ( $data1 == 1 ) {
$tag1 = 14;
$tag2 = $data2;
}else if( $data2 == 1){
$tag2 = 14;
$tag1 = $data1;
}else{
$tag1 = $data1;
$tag2 = $data2;
}
if ($tag1 > $tag2) {
return true;
}else{
return false;
}
}
// tag (花色):1 -- 黑桃 2 -- 红桃 3 -- 梅花 4 -- 方片
if ($datatype == 'tag') {
$tag_arr = [1 => 4, 2 => 3, 3 => 2, 4 => 1];
if ($tag_arr[$data1] > $tag_arr[$data2]) {
return true;
}else{
return false;
}
}
}