This commit is contained in:
li
2026-01-28 23:48:20 +08:00
commit b8cd0c9418
1293 changed files with 184011 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
<?php
namespace freedom\basic;
use think\facade\Db;
use think\Model;
class BaseModel extends model
{
private static $errorMsg;
const DEFAULT_ERROR_MSG = '操作失败,请稍候再试!';
/**
* 设置错误信息
* @param string $errorMsg
* @return bool
*/
protected static function setErrorInfo($errorMsg = self::DEFAULT_ERROR_MSG, $rollback = false)
{
if ($rollback) self::rollbackTrans();
self::$errorMsg = $errorMsg;
return false;
}
/**
* 获取错误信息
* @param string $defaultMsg
* @return string
*/
public static function getErrorInfo($defaultMsg = self::DEFAULT_ERROR_MSG)
{
return !empty(self::$errorMsg) ? self::$errorMsg : $defaultMsg;
}
/**
* 开启事务
*/
public static function beginTrans()
{
Db::startTrans();
}
/**
* 提交事务
*/
public static function commitTrans()
{
Db::commit();
}
/**
* 关闭事务
*/
public static function rollbackTrans()
{
Db::rollback();
}
/**
* 根据结果提交滚回事务
* @param $res
*/
public static function checkTrans($res)
{
if ($res) {
self::commitTrans();
} else {
self::rollbackTrans();
}
}
}
+94
View File
@@ -0,0 +1,94 @@
<?php
namespace freedom\traits;
trait ModelTrait{
/**
* 获取单条数据
* @param array|int $where
* @return array
*/
public static function get($where): array
{
if (!is_array($where)) {
$find = self::find($where);
} else {
$find = self::where($where)->find();
}
if ($find) return $find->toArray();
else return [];
}
/**
* 获取某个字段值
* @param int $where
* @param
* @return string|int|double
*/
public static function getFieldValue($where,$field): string
{
$value = self::where($where)->value($field);
if ($value) return $value;
else return '';
}
/**
* 添加多条数据
* @param $group
* @param bool $replace
* @return int
*/
public static function setAll($group, bool $replace = false): int
{
return self::insertAll($group, $replace);
}
/**
* 修改一条数据
* @param $data
* @param $id
* @param $field
* @return bool $type 返回成功失败
*/
public static function edit($data, $id, $field = null): bool
{
$model = new self;
if (!$field) $field = $model->getPk();
$res = $model->update($data, [$field => $id]);
if (isset($res->result))
return 0 < $res->result;
else if (isset($res['data']['result']))
return 0 < $res['data']['result'];
else
return false != $res;
}
/**
* 查询一条数据是否存在
* @param $map
* @param string $field
* @return bool 是否存在
*/
public static function be($map, string $field = ''): bool
{
$model = (new self);
if (!is_array($map) && empty($field)) $field = $model->getPk();
$map = !is_array($map) ? [$field => $map] : $map;
return 0 < $model->where($map)->count();
}
/**
* 删除一条数据
* @param $id
* @return bool $type 返回成功失败
*/
public static function del($id): bool
{
return false !== self::destroy($id);
}
}
+156
View File
@@ -0,0 +1,156 @@
<?php
namespace freedom\utils;
/**
* TODO 卡牌工具类
* Class CardPosition
* @package freedom\utils
*/
class CardPosition
{
/**
* TODO 卡牌编号转换数字
* @param int $id 卡牌
* @return int;
*/
public static function interchangeCard(int $id): int
{
if($id == 101 || $id == 201 || $id == 301 || $id == 401){
return 1;
}
if($id == 102 || $id == 202 || $id == 302 || $id == 402){
return 2;
}
if($id == 103 || $id == 203 || $id == 303 || $id == 403){
return 3;
}
if($id == 104 || $id == 204 || $id == 304 || $id == 404){
return 4;
}
if($id == 105 || $id == 205 || $id == 305 || $id == 405){
return 5;
}
if($id == 106 || $id == 206 || $id == 306 || $id == 406){
return 6;
}
if($id == 107 || $id == 207 || $id == 307 || $id == 407){
return 7;
}
if($id == 108 || $id == 208 || $id == 308 || $id == 408){
return 8;
}
if($id == 109 || $id == 209 || $id == 309 || $id == 409){
return 9;
}
if($id == 110 || $id == 210 || $id == 310 || $id == 410){
return 10;
}
if($id == 111 || $id == 211 || $id == 311 || $id == 411){
return 11;
}
if($id == 112 || $id == 212 || $id == 312 || $id == 412){
return 12;
}
if($id == 113 || $id == 213 || $id == 313 || $id == 413){
return 13;
}
return 0;
}
/**
* TODO 卡牌编号转换字段名称
* @param int $id 卡牌
* @return string;
*/
public static function interchangePosition(int $id): string
{
if($id == 11){
return 'player_1';
}
if($id == 12){
return 'player_2';
}
if($id == 13){
return 'player_3';
}
if($id == 21){
return 'banker_1';
}
if($id == 22){
return 'banker_2';
}
if($id == 23){
return 'banker_3';
}
return '';
}
/**
* TODO 判断花式大小
* @param int $id 卡牌
* @return string|int;
*/
public static function interchangeColor(int $id): string
{
return substr( $id, 0, 1 );
}
//卡牌位置信息转换
/**
* TODO 卡牌位置信息转换
* @param int $id 卡牌
* @return int;
*/
public static function interchangeNumber(int $id): int
{
if($id >= 10){
$id = 0;
}
return $id;
}
/**
* TODO Baccarat开牌条件判断
* @param array $cardInfo 卡牌
* @return bool;
*/
public static function checkOpenScan(array $cardInfo): bool
{
$playerCount = (self::interchangeNumber(self::interchangeCard($cardInfo['player_1'])) + self::interchangeNumber(self::interchangeCard($cardInfo['player_2']))) % 10;
$bankerCount = (self::interchangeNumber(self::interchangeCard($cardInfo['banker_1'])) + self::interchangeNumber(self::interchangeCard($cardInfo['banker_2']))) % 10;
$player3Count = (self::interchangeNumber(self::interchangeCard($cardInfo['player_3']))) % 10;
if(empty($cardInfo['player_1']) || empty($cardInfo['player_2']) || empty($cardInfo['banker_1']) || empty($cardInfo['banker_2'])){
return false;
}
if(($playerCount == 8 || $playerCount == 9 || $bankerCount == 8 || $bankerCount == 9) && empty($cardInfo['player_3']) && empty($cardInfo['banker_3'])){
return true;
}
if($playerCount >= 6 && $bankerCount >= 6 && empty($cardInfo['player_3']) && empty($cardInfo['banker_3'])){
return true;
}
if(($playerCount == 6 || $playerCount == 7) && $bankerCount < 6 && empty($cardInfo['player_3']) && $cardInfo['banker_3'] > 0){
return true;
}
if($playerCount < 6 && $cardInfo['player_3'] > 0 && $bankerCount == 7 && empty($cardInfo['banker_3'])){
return true;
}
if($playerCount < 6 && $cardInfo['player_3'] > 0 && (($bankerCount == 6 && in_array($player3Count,array(6,7)) && $cardInfo['banker_3'] > 0) || ($bankerCount == 6 && in_array($player3Count,array(1,2,3,4,5,8,9,0)) && empty($cardInfo['banker_3'])))){
return true;
}
if($playerCount < 6 && $cardInfo['player_3'] > 0 && (($bankerCount == 5 && in_array($player3Count,array(4,5,6,7)) && $cardInfo['banker_3'] > 0) || ($bankerCount == 5 && in_array($player3Count,array(1,2,3,8,9,0)) && empty($cardInfo['banker_3'])))){
return true;
}
if($playerCount < 6 && $cardInfo['player_3'] > 0 && (($bankerCount == 4 && in_array($player3Count,array(2,3,4,5,6,7)) && $cardInfo['banker_3'] > 0) || ($bankerCount == 4 && in_array($player3Count,array(1,8,9,0)) && empty($cardInfo['banker_3'])))){
return true;
}
if($playerCount < 6 && $cardInfo['player_3'] > 0 && (($bankerCount == 3 && in_array($player3Count,array(0,1,2,3,4,5,6,7,9)) && $cardInfo['banker_3'] > 0) || ($bankerCount == 3 && in_array($player3Count,array(8)) && empty($cardInfo['banker_3'])))){
return true;
}
if($playerCount < 6 && $cardInfo['player_3'] > 0 && $bankerCount < 3 && $cardInfo['banker_3'] > 0){
return true;
}
return false;
}
}
+718
View File
@@ -0,0 +1,718 @@
<?php
namespace freedom\utils;
/**
* TODO 卡牌工具类(NN)
* Class CardPositionNn
* @package freedom\utils
*/
class CardPositionNn
{
/**
* TODO 发牌顺序 [识别]
* @param int $id 卡牌
* @return array;
*/
public static function nnOrderSb(int $id): array
{
$order = array();
//闲一先发牌
if($id == 1){
$order[0]="player_1_card_1";
$order[1]="player_1_card_2";
$order[2]="player_1_card_3";
$order[3]="player_1_card_4";
$order[4]="player_1_card_5";
$order[5]="player_2_card_1";
$order[6]="player_2_card_2";
$order[7]="player_2_card_3";
$order[8]="player_2_card_4";
$order[9]="player_2_card_5";
$order[10]="player_3_card_1";
$order[11]="player_3_card_2";
$order[12]="player_3_card_3";
$order[13]="player_3_card_4";
$order[14]="player_3_card_5";
$order[15]="banker_card_1";
$order[16]="banker_card_2";
$order[17]="banker_card_3";
$order[18]="banker_card_4";
$order[19]="banker_card_5";
}
if($id == 2){
$order[0]="player_2_card_1";
$order[1]="player_2_card_2";
$order[2]="player_2_card_3";
$order[3]="player_2_card_4";
$order[4]="player_2_card_5";
$order[5]="player_3_card_1";
$order[6]="player_3_card_2";
$order[7]="player_3_card_3";
$order[8]="player_3_card_4";
$order[9]="player_3_card_5";
$order[10]="banker_card_1";
$order[11]="banker_card_2";
$order[12]="banker_card_3";
$order[13]="banker_card_4";
$order[14]="banker_card_5";
$order[15]="player_1_card_1";
$order[16]="player_1_card_2";
$order[17]="player_1_card_3";
$order[18]="player_1_card_4";
$order[19]="player_1_card_5";
}
if($id == 3){
$order[0]="player_3_card_1";
$order[1]="player_3_card_2";
$order[2]="player_3_card_3";
$order[3]="player_3_card_4";
$order[4]="player_3_card_5";
$order[5]="banker_card_1";
$order[6]="banker_card_2";
$order[7]="banker_card_3";
$order[8]="banker_card_4";
$order[9]="banker_card_5";
$order[10]="player_1_card_1";
$order[11]="player_1_card_2";
$order[12]="player_1_card_3";
$order[13]="player_1_card_4";
$order[14]="player_1_card_5";
$order[15]="player_2_card_1";
$order[16]="player_2_card_2";
$order[17]="player_2_card_3";
$order[18]="player_2_card_4";
$order[19]="player_2_card_5";
}
if($id == 4){
$order[0]="banker_card_1";
$order[1]="banker_card_2";
$order[2]="banker_card_3";
$order[3]="banker_card_4";
$order[4]="banker_card_5";
$order[5]="player_1_card_1";
$order[6]="player_1_card_2";
$order[7]="player_1_card_3";
$order[8]="player_1_card_4";
$order[9]="player_1_card_5";
$order[10]="player_2_card_1";
$order[11]="player_2_card_2";
$order[12]="player_2_card_3";
$order[13]="player_2_card_4";
$order[14]="player_2_card_5";
$order[15]="player_3_card_1";
$order[16]="player_3_card_2";
$order[17]="player_3_card_3";
$order[18]="player_3_card_4";
$order[19]="player_3_card_5";
}
return $order;
}
/**
* TODO 发牌顺序 [识别]
* @param int $id 卡牌
* @return array;
*/
public static function nnOrderNumSb(int $id): array
{
$orderNum = array();
//闲一先发牌
if($id == 1){
$orderNum[0]="11";
$orderNum[1]="12";
$orderNum[2]="13";
$orderNum[3]="14";
$orderNum[4]="15";
$orderNum[5]="21";
$orderNum[6]="22";
$orderNum[7]="23";
$orderNum[8]="24";
$orderNum[9]="25";
$orderNum[10]="31";
$orderNum[11]="32";
$orderNum[12]="33";
$orderNum[13]="34";
$orderNum[14]="35";
$orderNum[15]="41";
$orderNum[16]="42";
$orderNum[17]="43";
$orderNum[18]="44";
$orderNum[19]="45";
}
if($id == 2){
$orderNum[0]="21";
$orderNum[1]="22";
$orderNum[2]="23";
$orderNum[3]="24";
$orderNum[4]="25";
$orderNum[5]="31";
$orderNum[6]="32";
$orderNum[7]="33";
$orderNum[8]="34";
$orderNum[9]="35";
$orderNum[10]="41";
$orderNum[11]="42";
$orderNum[12]="43";
$orderNum[13]="44";
$orderNum[14]="45";
$orderNum[15]="11";
$orderNum[16]="12";
$orderNum[17]="13";
$orderNum[18]="14";
$orderNum[19]="15";
}
if($id == 3){
$orderNum[0]="31";
$orderNum[1]="32";
$orderNum[2]="33";
$orderNum[3]="34";
$orderNum[4]="35";
$orderNum[5]="41";
$orderNum[6]="42";
$orderNum[7]="43";
$orderNum[8]="44";
$orderNum[9]="45";
$orderNum[10]="11";
$orderNum[11]="12";
$orderNum[12]="13";
$orderNum[13]="14";
$orderNum[14]="15";
$orderNum[15]="21";
$orderNum[16]="22";
$orderNum[17]="23";
$orderNum[18]="24";
$orderNum[19]="25";
}
if($id == 4){
$orderNum[0]="41";
$orderNum[1]="42";
$orderNum[2]="43";
$orderNum[3]="44";
$orderNum[4]="45";
$orderNum[5]="11";
$orderNum[6]="12";
$orderNum[7]="13";
$orderNum[8]="14";
$orderNum[9]="15";
$orderNum[10]="21";
$orderNum[11]="22";
$orderNum[12]="23";
$orderNum[13]="24";
$orderNum[14]="25";
$orderNum[15]="31";
$orderNum[16]="32";
$orderNum[17]="33";
$orderNum[18]="34";
$orderNum[19]="35";
}
return $orderNum;
}
/**
* TODO 发牌顺序
* @param int $id 卡牌
* @return array;
*/
public static function nnOrder(int $id): array
{
$order = array();
//庄一先发牌
if($id == 1){
$order[0]="player_1_card_1";
$order[1]="player_2_card_1";
$order[2]="player_3_card_1";
$order[3]="banker_card_1";
$order[4]="player_1_card_2";
$order[5]="player_2_card_2";
$order[6]="player_3_card_2";
$order[7]="banker_card_2";
$order[8]="player_1_card_3";
$order[9]="player_2_card_3";
$order[10]="player_3_card_3";
$order[11]="banker_card_3";
$order[12]="player_1_card_4";
$order[13]="player_2_card_4";
$order[14]="player_3_card_4";
$order[15]="banker_card_4";
$order[16]="player_1_card_5";
$order[17]="player_2_card_5";
$order[18]="player_3_card_5";
$order[19]="banker_card_5";
}
if($id == 2){
$order[0]="player_2_card_1";
$order[1]="player_3_card_1";
$order[2]="banker_card_1";
$order[3]="player_1_card_1";
$order[4]="player_2_card_2";
$order[5]="player_3_card_2";
$order[6]="banker_card_2";
$order[7]="player_1_card_2";
$order[8]="player_2_card_3";
$order[9]="player_3_card_3";
$order[10]="banker_card_3";
$order[11]="player_1_card_3";
$order[12]="player_2_card_4";
$order[13]="player_3_card_4";
$order[14]="banker_card_4";
$order[15]="player_1_card_4";
$order[16]="player_2_card_5";
$order[17]="player_3_card_5";
$order[18]="banker_card_5";
$order[19]="player_1_card_5";
}
if($id == 3){
$order[0]="player_3_card_1";
$order[1]="banker_card_1";
$order[2]="player_1_card_1";
$order[3]="player_2_card_1";
$order[4]="player_3_card_2";
$order[5]="banker_card_2";
$order[6]="player_1_card_2";
$order[7]="player_2_card_2";
$order[8]="player_3_card_3";
$order[9]="banker_card_3";
$order[10]="player_1_card_3";
$order[11]="player_2_card_3";
$order[12]="player_3_card_4";
$order[13]="banker_card_4";
$order[14]="player_1_card_4";
$order[15]="player_2_card_4";
$order[16]="player_3_card_5";
$order[17]="banker_card_5";
$order[18]="player_1_card_5";
$order[19]="player_2_card_5";
}
if($id == 4){
$order[0]="banker_card_1";
$order[1]="player_1_card_1";
$order[2]="player_2_card_1";
$order[3]="player_3_card_1";
$order[4]="banker_card_2";
$order[5]="player_1_card_2";
$order[6]="player_2_card_2";
$order[7]="player_3_card_2";
$order[8]="banker_card_3";
$order[9]="player_1_card_3";
$order[10]="player_2_card_3";
$order[11]="player_3_card_3";
$order[12]="banker_card_4";
$order[13]="player_1_card_4";
$order[14]="player_2_card_4";
$order[15]="player_3_card_4";
$order[16]="banker_card_5";
$order[17]="player_1_card_5";
$order[18]="player_2_card_5";
$order[19]="player_3_card_5";
}
return $order;
}
/**
* TODO 发牌顺序
* @param int $id 卡牌
* @return array;
*/
public static function nnOrderNum(int $id): array
{
$orderNum = array();
//庄一先发牌
if($id == 1){
$orderNum[0]="11";
$orderNum[1]="21";
$orderNum[2]="31";
$orderNum[3]="41";
$orderNum[4]="12";
$orderNum[5]="22";
$orderNum[6]="32";
$orderNum[7]="42";
$orderNum[8]="13";
$orderNum[9]="23";
$orderNum[10]="33";
$orderNum[11]="43";
$orderNum[12]="14";
$orderNum[13]="24";
$orderNum[14]="34";
$orderNum[15]="44";
$orderNum[16]="15";
$orderNum[17]="25";
$orderNum[18]="35";
$orderNum[19]="45";
}
if($id == 2){
$orderNum[0]="21";
$orderNum[1]="31";
$orderNum[2]="41";
$orderNum[3]="11";
$orderNum[4]="22";
$orderNum[5]="32";
$orderNum[6]="42";
$orderNum[7]="12";
$orderNum[8]="23";
$orderNum[9]="33";
$orderNum[10]="43";
$orderNum[11]="13";
$orderNum[12]="24";
$orderNum[13]="34";
$orderNum[14]="44";
$orderNum[15]="14";
$orderNum[16]="25";
$orderNum[17]="35";
$orderNum[18]="45";
$orderNum[19]="15";
}
if($id == 3){
$orderNum[0]="31";
$orderNum[1]="41";
$orderNum[2]="11";
$orderNum[3]="21";
$orderNum[4]="32";
$orderNum[5]="42";
$orderNum[6]="12";
$orderNum[7]="22";
$orderNum[8]="33";
$orderNum[9]="43";
$orderNum[10]="13";
$orderNum[11]="23";
$orderNum[12]="34";
$orderNum[13]="44";
$orderNum[14]="14";
$orderNum[15]="24";
$orderNum[16]="35";
$orderNum[17]="45";
$orderNum[18]="15";
$orderNum[19]="25";
}
if($id == 4){
$orderNum[0]="41";
$orderNum[1]="11";
$orderNum[2]="21";
$orderNum[3]="31";
$orderNum[4]="42";
$orderNum[5]="12";
$orderNum[6]="22";
$orderNum[7]="32";
$orderNum[8]="43";
$orderNum[9]="13";
$orderNum[10]="23";
$orderNum[11]="33";
$orderNum[12]="44";
$orderNum[13]="14";
$orderNum[14]="24";
$orderNum[15]="34";
$orderNum[16]="45";
$orderNum[17]="15";
$orderNum[18]="25";
$orderNum[19]="35";
}
return $orderNum;
}
/**
* TODO 发牌第一家
* @param int $id 卡牌
* @return int|bool;
*/
public static function nnPosition(int $id){
$num = CardPosition::interchangeCard($id);
if($num == false){
return false;
}else{
$positionNum = $num%4;
}
if($positionNum == 0){
$positionNum = 4;
}
return $positionNum;
}
/**
* TODO nn结果
* @param array $card 卡牌
* @return array;
*/
public static function JudgeCowCow(array $card): array
{
//获取五张牌中最大的牌
$compare = $card;
for($i=0;$i<4;$i++){
for($j=$i+1;$j<5;$j++){
if(substr($compare[$i],1,2) < substr($compare[$j],1,2)){
$a = $compare[$i];
$compare[$i] = $compare[$j];
$compare[$j]=$a;
}
}
}
$maxCard = substr($compare['0'],1,2);
if(substr($maxCard,0,1) == 0){
$maxCard = substr($maxCard,1,1);
}
$sameNum = 0;
for($i=0;$i<5; $i++){
$card[$i] = substr($card[$i],1,2);
if(substr($card[$i],0,1) == 0){
$card[$i] = substr($card[$i],1,1);
}
if($card[$i] == $maxCard){
$sameNum++;
}
}
$max = $compare['0'];
if($sameNum > 1){
$compare = array_slice($compare,0,$sameNum);
for($i=0;$i<$sameNum-1;$i++){//对5张牌从大到小排序。
for($j=$i+1;$j<$sameNum;$j++){
if($compare[$i] > $compare[$j]){
$a = $compare[$i];
$compare[$i] = $compare[$j];
$compare[$j]=$a;
}
}
}
$max = $compare['0'];
}
$cow = -1;
//计算5张牌总值,cow计算牛几。
$cardAll = 0;
$n= 0 ;//存储10、J、Q、K张数。
$king = 0;//存储J、Q、K张数。
$result = array();
//计算J、Q、K张数。
for($i=0;$i<5;$i++){
if($card[$i] >= 11){
$king++;
}
}
$word = '';
if($king == 5){
$cow = 11;
$word = '五公';
$result['word'] = $word;
$result['cow'] = $cow;
$result['max'] = $max;
return $result;
}
for($i=0;$i<4;$i++){//对5张牌从大到小排序。
for($j=$i+1;$j<5;$j++){
if($card[$i] < $card[$j]){
$a = $card[$i];
$card[$i] = $card[$j];
$card[$j]=$a;
}
}
}
for($i=0;$i<5;$i++){
if($card[$i] >= 10){
$n++;
$card[$i] = 10;
}
$cardAll += $card[$i];
}
switch ($n){
case 0: //5张牌中没有一张10、J、Q、K。
for($i=0;$i<4;$i++){
for($j=$i + 1;$j<5;$j++){
if(($cardAll - $card[$i]- $card[$j])%10==0){
$cow=($card[$i] + $card[$j])%10;
}
}
}
break;
case 1: //5张牌中有一张10、J、Q、K。
//先判断是否有牛牛,不能判断剩余四张相加为10倍数为牛牛,如 Q 8 5 4 3
//只能先判断两张是否是10的倍数,如果是再判断剩余是否是10的倍数;有限判断出牛牛;再来判断三张是否有10的倍数,有的话有牛,否则无牛
for($i =1; $i < 4; $i ++){
for($j = $i +1; $j < 5; $j++){
if(($card[$i] + $card[$j]) % 10 == 0){
$cow=($cardAll - $card[0])%10;
}
}
}
//判断是否有牛
for($i=1; $i<5; $i++){ //剩下四张牌有三张加起来等于10
if(($cardAll - $card[0] - $card[$i])%10==0){
$cow=($cardAll-$card[0])%10;
break;
}
}
break;
case 2: //5张牌中有两张10、J、Q、K。 三张是个牛就有问题,应该优先输出
if(($cardAll - $card[0] - $card[1])%10 == 0){//优先牛牛输出 如 J Q 2 3 5;这里先检查剩余是否为牛牛,否则算法有漏洞
$cow = 0;
}else{
//10 10 6 5 3 n=2 i=3 j=4 cardAll = 34
for($i=$n;$i<4;$i++){//剩下三(四)张牌有两张加起来等于10。
for($j=$i+1;$j<5;$j++){
if(($card[$i]+$card[$j])==10){
$temp = $cardAll;
for($k=0;$k<$n;$k++){
$temp -= $card[$k]; // 18
$cow = $temp%10; //8
}
}
}
}
}
break;
case 3: //5张牌中有三张10、J、Q、K。
case 4: //5张牌中有四张10、J、Q、K。
case 5: //5张牌中五张都是10、J、Q、K。
for($i=0;$i<$n;$i++){//总值减去10、J、Q、K的牌。
$cardAll -= $card[$i];
}
$cow = $cardAll%10;
break;
}
switch ($cow){
case 0:
$word = 'NN';
break;
case 1:
$word = 'N1';
break;
case 2:
$word = 'N2';
break;
case 3:
$word = 'N3';
break;
case 4:
$word = 'N4';
break;
case 5:
$word = 'N5';
break;
case 6:
$word = 'N6';
break;
case 7:
$word = 'N7';
break;
case 8:
$word = 'N8';
break;
case 9:
$word = 'N9';
break;
case -1:
$word = 'N0';
break;
}
if($cow == -1){
$cow = 0;
}else if($cow == 0){
$cow = 10;
}
$result['word'] = $word;
$result['cow'] = $cow;
$result['max'] = $max;
return $result;
}
/**
* TODO NN比较两张牌大小
* @param int $card1 卡牌
* @param int $card2 卡牌
* @return int;
*/
public static function compareCard(int $card1, int $card2): int
{
$card1Num = CardPosition::interchangeCard($card1);
$card2Num = CardPosition::interchangeCard($card2);
$card1Color = CardPosition::interchangeColor($card1);
$card2Color = CardPosition::interchangeColor($card2);
if($card1Num > $card2Num){
return 1;
}elseif($card1Num < $card2Num){
return 0;
}else{
if($card1Color > $card2Color){
return 0;
}else{
return 1;
}
}
}
/**
* TODO NN识别固定位置
* @param int $position 位置
* @return string;
*/
public static function sbStaticCardPosition(int $position): string
{
$result = '';
switch($position) {
case 1:
$result = "player_1_card_1";
break;
case 2:
$result = "player_1_card_2";
break;
case 3:
$result = "player_1_card_3";
break;
case 4:
$result = "player_1_card_4";
break;
case 5:
$result = "player_1_card_5";
break;
case 6:
$result = "player_2_card_1";
break;
case 7:
$result = "player_2_card_2";
break;
case 8:
$result = "player_2_card_3";
break;
case 9:
$result = "player_2_card_4";
break;
case 10:
$result = "player_2_card_5";
break;
case 11:
$result = "player_3_card_1";
break;
case 12:
$result = "player_3_card_2";
break;
case 13:
$result = "player_3_card_3";
break;
case 14:
$result = "player_3_card_4";
break;
case 15:
$result = "player_3_card_5";
break;
case 16:
$result = "banker_card_1";
break;
case 17:
$result = "banker_card_2";
break;
case 18:
$result = "banker_card_3";
break;
case 19:
$result = "banker_card_4";
break;
case 20:
$result = "banker_card_5";
break;
}
return $result;
}
}
+390
View File
@@ -0,0 +1,390 @@
<?php
namespace freedom\utils;
/**
* TODO 卡牌工具类(TC)
* Class CardPositionTc
* @package freedom\utils
*/
class CardPositionTc
{
/**
* TODO 获取倍数
* @param int $id 卡牌
* @return int;
*/
public static function getTimes(int $id): int
{
if($id == 1){
return 1;
}elseif($id == 2){
return 2;
}elseif($id == 3){
return 3;
}elseif($id == 4){
return 4;
}elseif($id == 5){
return 5;
}elseif($id == 6){
return 6;
}elseif($id == 7){
return 7;
}elseif($id == 8){
return 8;
}elseif($id == 9){
return 9;
}elseif($id == 10){
return 10;
}elseif($id == 11){
return 12;
}elseif($id == 12){
return 15;
}elseif($id == 13){
return 20;
}
return 0;
}
/**
* TODO 发牌顺序
* @param int $id 卡牌
* @return array;
*/
public static function tcOrder(int $id): array
{
$order = array();
//庄一先发牌
if($id == 1){
$order[0]="player_1_card_1";
$order[1]="player_2_card_1";
$order[2]="player_3_card_1";
$order[3]="banker_card_1";
$order[4]="player_1_card_2";
$order[5]="player_2_card_2";
$order[6]="player_3_card_2";
$order[7]="banker_card_2";
$order[8]="player_1_card_3";
$order[9]="player_2_card_3";
$order[10]="player_3_card_3";
$order[11]="banker_card_3";
}
if($id == 2){
$order[0]="player_2_card_1";
$order[1]="player_3_card_1";
$order[2]="banker_card_1";
$order[3]="player_1_card_1";
$order[4]="player_2_card_2";
$order[5]="player_3_card_2";
$order[6]="banker_card_2";
$order[7]="player_1_card_2";
$order[8]="player_2_card_3";
$order[9]="player_3_card_3";
$order[10]="banker_card_3";
$order[11]="player_1_card_3";
}
if($id == 3){
$order[0]="player_3_card_1";
$order[1]="banker_card_1";
$order[2]="player_1_card_1";
$order[3]="player_2_card_1";
$order[4]="player_3_card_2";
$order[5]="banker_card_2";
$order[6]="player_1_card_2";
$order[7]="player_2_card_2";
$order[8]="player_3_card_3";
$order[9]="banker_card_3";
$order[10]="player_1_card_3";
$order[11]="player_2_card_3";
}
if($id == 4){
$order[0]="banker_card_1";
$order[1]="player_1_card_1";
$order[2]="player_2_card_1";
$order[3]="player_3_card_1";
$order[4]="banker_card_2";
$order[5]="player_1_card_2";
$order[6]="player_2_card_2";
$order[7]="player_3_card_2";
$order[8]="banker_card_3";
$order[9]="player_1_card_3";
$order[10]="player_2_card_3";
$order[11]="player_3_card_3";
}
return $order;
}
/**
* TODO 发牌顺序
* @param int $id 卡牌
* @return array;
*/
public static function tcOrderNum(int $id): array
{
$orderNum = array();
//庄一先发牌
if($id == 1){
$orderNum[0]="11";
$orderNum[1]="21";
$orderNum[2]="31";
$orderNum[3]="41";
$orderNum[4]="12";
$orderNum[5]="22";
$orderNum[6]="32";
$orderNum[7]="42";
$orderNum[8]="13";
$orderNum[9]="23";
$orderNum[10]="33";
$orderNum[11]="43";
}
if($id == 2){
$orderNum[0]="21";
$orderNum[1]="31";
$orderNum[2]="41";
$orderNum[3]="11";
$orderNum[4]="22";
$orderNum[5]="32";
$orderNum[6]="42";
$orderNum[7]="12";
$orderNum[8]="23";
$orderNum[9]="33";
$orderNum[10]="43";
$orderNum[11]="13";
}
if($id == 3){
$orderNum[0]="31";
$orderNum[1]="41";
$orderNum[2]="11";
$orderNum[3]="21";
$orderNum[4]="32";
$orderNum[5]="42";
$orderNum[6]="12";
$orderNum[7]="22";
$orderNum[8]="33";
$orderNum[9]="43";
$orderNum[10]="13";
$orderNum[11]="23";
}
if($id == 4){
$orderNum[0]="41";
$orderNum[1]="11";
$orderNum[2]="21";
$orderNum[3]="31";
$orderNum[4]="42";
$orderNum[5]="12";
$orderNum[6]="22";
$orderNum[7]="32";
$orderNum[8]="43";
$orderNum[9]="13";
$orderNum[10]="23";
$orderNum[11]="33";
}
return $orderNum;
}
/**
* TODO tc结果
* @param array $card 卡牌
* @return array ;
*/
public static function ThredCardCowCow(array $card): array
{
$cardType = [];
if(!is_array($card) || count($card) !== 3){
return false;
}
//获取三张牌中最大的牌
$compare = $card;
for($i=0;$i<2;$i++){
for($j=$i+1;$j<3;$j++){
if(substr($compare[$i],1,2) < substr($compare[$j],1,2)){
$a = $compare[$i];
$compare[$i] = $compare[$j];
$compare[$j]=$a;
}
}
}
$maxCard = substr($compare['0'],1,2);
if(substr($maxCard,0,1) == 0){
$maxCard = substr($maxCard,1,1);
}
$sameNum = 0;
for($i=0;$i<3; $i++){
$cardType[$i] = substr($card[$i],0,1);
$card[$i] = substr($card[$i],1,2);
if(substr($card[$i],0,1) == 0){
$card[$i] = substr($card[$i],1,1);
}
if($card[$i] == $maxCard){
$sameNum++;
}
}
//特殊牌型最大牌判断
$spaceNum = array_count_values($card);
if($sameNum == 1){
$max = $compare['0'];
}
if($sameNum > 1){
$compare = array_slice($compare,0,$sameNum);
for($i=0;$i<$sameNum-1;$i++){//对5张牌从大到小排序。
for($j=$i+1;$j<$sameNum;$j++){
if($compare[$i] > $compare[$j]){
$a = $compare[$i];
$compare[$i] = $compare[$j];
$compare[$j]=$a;
}
}
}
$max = $compare['0'];
if($sameNum == 2){
if($compare['0']>300 && $compare['0']<400){
$max = $compare['1'];
}
}
}
$result = array();
//豹子判断
if(count($card) != count(array_unique($card))) {
if (count(array_unique($card)) == 1) {
$cow = 11;
$word = '豹子';
if (array_key_exists(1, $spaceNum)) {
if ($spaceNum['1'] > 0) {
if ($spaceNum['1'] == 1) {
$max = $compare[2];
}
if ($spaceNum['1'] == 2) {
if ($compare[1] > 300 && $compare[1] < 400) {
$max = $compare[2];
} else {
$max = $compare[1];
}
}
}
}
$result['word'] = $word;
$result['cow'] = $cow;
$result['max'] = $max;
return $result;
}
}
if(count(array_unique($cardType)) == 1){
//皇家同花顺
$example = array(1,12,13);
$diffResult=array_diff($card,$example);
if(count($diffResult) == 0){
$cow = 13;
$word = '皇家同花顺';
if(isset($spaceNum['1'])){
$max = $compare[2];
}
$result['word'] = $word;
$result['cow'] = $cow;
$result['max'] = $max;
return $result;
}
//同花顺
if(count($card) == count(array_unique($card))) {
$maxC=$minC=-1;
for ($i=0; $i < 3; $i++) {
if($card[$i] > $maxC || $maxC == -1){
$maxC = $card[$i];
}
if($card[$i] < $minC || $minC == -1){
$minC = $card[$i];
}
}
if($maxC - $minC == 2){
$cow = 12;
$word = '同花顺';
// if(isset($spaceNum['1'])){
// $max = $compare[2];
// }
$result['word'] = $word;
$result['cow'] = $cow;
$result['max'] = $max;
return $result;
}
}
}
if($card[0]>10)$card[0]=10;
if($card[1]>10)$card[1]=10;
if($card[2]>10)$card[2]=10;
$sumNum = $card[0] + $card[1] + $card[2];
if($sumNum < 10){
$cow = $sumNum;
}else{
$cow = $sumNum%10;
}
switch ($cow){
case 0:
$word = '牛牛';
break;
case 1:
$word = '牛一';
break;
case 2:
$word = '牛二';
break;
case 3:
$word = '牛三';
break;
case 4:
$word = '牛四';
break;
case 5:
$word = '牛五';
break;
case 6:
$word = '牛六';
break;
case 7:
$word = '牛七';
break;
case 8:
$word = '牛八';
break;
case 9:
$word = '牛九';
break;
}
if($cow == 0){
$cow = 10;
}
$result['word'] = $word;
$result['cow'] = $cow;
$result['max'] = $max;
return $result;
}
/**
* TODO TC比较两张牌大小
* @param int $card1 卡牌
* @param int $card2 卡牌
* @param int $result 结果
* @return int;
*/
public static function compareCardTc(int $card1, int $card2, int $result): int
{
$card1Num = CardPosition::interchangeCard($card1);
$card2Num = CardPosition::interchangeCard($card2);
$card1Color = CardPosition::interchangeColor($card1);
$card2Color = CardPosition::interchangeColor($card2);
if($card1Num > $card2Num){
return 1;
}elseif($card1Num < $card2Num){
return 0;
}else{
if($card1Color > $card2Color){
return 0;
}elseif($card1Color < $card2Color){
return 1;
}
}
}
}
+154
View File
@@ -0,0 +1,154 @@
<?php
namespace freedom\utils;
class DiceUtil
{
/**
* 根据结果输出某点的次数
* @param $resultArray // 结果数组
* @param $living // 点数
* @return int
*/
public static function getLivingCount($resultArray, $living): int
{
$count = 0;
foreach ($resultArray as $k => $v){
if (intval($v) == $living){
$count++;
}
}
return $count;
}
/**
* 分析结果 控制端传入三个数 方法对其分析 输出结果
* @param $resultArray
* @return array
*/
public static function parseResult($resultArray): array
{
// 返回数组
$returnArray = [];
$returnArray[] = 'living_' . $resultArray[0];
$returnArray[] = 'living_' . $resultArray[1];
$returnArray[] = 'living_' . $resultArray[2];
// int类型结果数组
$intResultArray = [];
foreach ($resultArray as $v) {
$intResultArray[] = intval($v);
}
$total = array_sum($intResultArray);
if ($total > 3 && $total < 18) {
$returnArray[] = 'number_' . $total;
}
// 判断是不是全部值都是一样的
$uniqueArray = array_unique($intResultArray);
// 重新排序
sort($uniqueArray);
if (count($uniqueArray) == 1) {
$returnArray[] = 'two_'.$uniqueArray[0] . $uniqueArray[0];
$returnArray[] = 'three_'.$uniqueArray[0] . $uniqueArray[0] . $uniqueArray[0];
$returnArray[] = 'leopard';
} else {
if ($total >= 4 && $total <= 10) {
$returnArray[] = 'small';
}
if ($total >= 11 && $total <= 17) {
$returnArray[] = 'big';
}
if ($total % 2 == 0) {
$returnArray[] = 'plural';
} else {
$returnArray[] = 'singular';
}
}
if (count($uniqueArray) == 2) {
$returnArray[] = 'two_'.$uniqueArray[0] . $uniqueArray[1];
$pointArr = array_count_values($resultArray);
foreach ($pointArr as $key => $value){
if($value == 2){
$returnArray[] = 'two_'.$key . $key;
}
}
}
if (count($uniqueArray) == 3) {
$returnArray[] = 'two_'.$uniqueArray[0] . $uniqueArray[1];
$returnArray[] = 'two_'.$uniqueArray[0] . $uniqueArray[2];
$returnArray[] = 'two_'.$uniqueArray[1] . $uniqueArray[2];
}
return $returnArray;
}
/**
* 分析统计 分析结果 控制端传入三个数 方法对其分析 输出结果
* @param $resultArray
* @return array
*/
public static function parseCount($resultArray): array
{
$returnArray = [];
// int类型结果数组
$intResultArray = [];
foreach ($resultArray as $v) {
$intResultArray[] = intval($v);
}
$total = array_sum($intResultArray);
// 判断是不是全部值都是一样的
$uniqueArray = array_unique($intResultArray);
if (count($uniqueArray) == 1) {
$returnArray[] = 'leopard';
} else {
if ($total >= 4 && $total <= 10) {
$returnArray[] = 'small';
}
if ($total >= 11 && $total <= 17) {
$returnArray[] = 'big';
}
if ($total % 2 == 0) {
$returnArray[] = 'plural';
} else {
$returnArray[] = 'singular';
}
}
return $returnArray;
}
/**
* 统计自增方法
* @param $beforeCountArray
* @param $afterCountArray
* @return int[]
*/
public static function countInc($beforeCountArray, $afterCountArray): array
{
if (empty($beforeCountArray)){
$beforeCountArray = ['leopard' => 0, 'small' => 0, 'big' => 0, 'singular' => 0, 'plural' => 0];
}
foreach ($beforeCountArray as $k => $v){
if (in_array($k, $afterCountArray)){
$beforeCountArray[$k] = $v + 1;
}
}
return $beforeCountArray;
}
/**
* 下注额自增方法
* @param $beforeAmountArray
* @param $afterAmountArray
* @return array
*/
public static function amountInc($beforeAmountArray, $afterAmountArray): array
{
$returnArray = [];
foreach ($afterAmountArray as $k => $v){
if (array_key_exists($k, $beforeAmountArray)){
$returnArray[$k] = $beforeAmountArray[$k] + $v;
unset($beforeAmountArray[$k]);
} else {
$returnArray[$k] = $v;
}
}
return $returnArray + $beforeAmountArray;
}
}
+143
View File
@@ -0,0 +1,143 @@
<?php
namespace freedom\utils;
use think\facade\Cache;
/**
* TODO Redis操作工具类
* Class RedisUtil
* @package freedom\utils
*/
class RedisUtil
{
/**
* TODO 卡牌保存
* @param int $numberTabId 局ID
* @param int $card 卡牌点数
* @param int $timeout 过期时间,默认3天
* @return bool;
*/
public static function saveCardPosition(int $numberTabId, int $position, int $card, $timeout = 60*60*24*3):bool{
$res = Cache::store('redis')->set('card_'.$numberTabId.'_'.$position,$card,$timeout);
if ($res){
return true;
}else{
return false;
}
}
/**
* TODO 卡牌获取
* @param int $numberTabId 局ID
* @return array;
*/
public static function getCardPosition(int $numberTabId): array
{
$card11 = Cache::store('redis')->get('card_'.$numberTabId.'_11');
$card12 = Cache::store('redis')->get('card_'.$numberTabId.'_12');
$card13 = Cache::store('redis')->get('card_'.$numberTabId.'_13');
$card21 = Cache::store('redis')->get('card_'.$numberTabId.'_21');
$card22 = Cache::store('redis')->get('card_'.$numberTabId.'_22');
$card23 = Cache::store('redis')->get('card_'.$numberTabId.'_23');
$cardInfoRedis = [];
if ($card11) $cardInfoRedis['player_1'] = $card11;
if ($card12) $cardInfoRedis['player_2'] = $card12;
if ($card13) $cardInfoRedis['player_3'] = $card13;
if ($card21) $cardInfoRedis['banker_1'] = $card21;
if ($card22) $cardInfoRedis['banker_2'] = $card22;
if ($card23) $cardInfoRedis['banker_3'] = $card23;
return $cardInfoRedis;
}
/**
* TODO 卡牌缓存删除
* @param int $numberTabId
* @return bool
*/
public static function deleteCardPosition(int $numberTabId): bool
{
Cache::store('redis')->delete('card_'.$numberTabId.'_11');
Cache::store('redis')->delete('card_'.$numberTabId.'_12');
Cache::store('redis')->delete('card_'.$numberTabId.'_13');
Cache::store('redis')->delete('card_'.$numberTabId.'_21');
Cache::store('redis')->delete('card_'.$numberTabId.'_22');
Cache::store('redis')->delete('card_'.$numberTabId.'_23');
return true;
}
/**
* TODO 卡牌保存
* @param int $numberTabId 局ID
* @param array $array 卡牌数组
* @param int $timeout 过期时间,默认3天
* @return bool;
*/
public static function saveCard(int $numberTabId, array $array, $timeout = 60*60*24*3): bool{
$res = Cache::store('redis')->set('card_'.$numberTabId,json_encode($array),$timeout);
if ($res){
return true;
}else{
return false;
}
}
/**
* TODO 卡牌获取
* @param int $numberTabId 局ID
* @return array;
*/
public static function getCard(int $numberTabId): array{
$cardInfoRedis = Cache::store('redis')->get('card_'.$numberTabId);
if ($cardInfoRedis){
return json_decode($cardInfoRedis,true);
}else{
return [];
}
}
/**
* TODO 设置缓存
* @param string $name 名称
* @param string|int|bool $value 名称
* @param int $waitTime 过期时间
* @return bool;
*/
public static function save(string $name, $value, int $waitTime): bool
{
$res = Cache::store('redis')->set($name,$value,$waitTime);
if ($res){
return true;
}else{
return false;
}
}
/**
* TODO 删除缓存
* @param string $name 名称
* @return bool;
*/
public static function delete(string $name): bool
{
$res = Cache::store('redis')->delete($name);
if ($res){
return true;
}else{
return false;
}
}
/**
* TODO 获取缓存
* @param string $name 名称
* @return string;
*/
public static function get(string $name): string
{
return Cache::store('redis')->get($name);
}
}
+129
View File
@@ -0,0 +1,129 @@
<?php
namespace freedom\utils;
class RouletteUtil
{
/**
* 分析统计 分析结果 控制端传入一个数 方法对其分析 输出结果
* @param $result
* @return array
*/
public static function parseCount($result): array
{
$returnArray = [];
if ($result != 0) {
if ($result >= 1 && $result <= 18) {
$returnArray[] = 'low';
}
if ($result >= 19 && $result <= 36) {
$returnArray[] = 'high';
}
if ($result % 2 == 0) {
$returnArray[] = 'even';
} else {
$returnArray[] = 'odd';
}
if(in_array($result,[1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36])){
$returnArray[] = 'red';
}
if(in_array($result,[2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35])){
$returnArray[] = 'black';
}
} else {
$returnArray[] = 'zero';
}
return $returnArray;
}
/**
* 统计自增方法
* @param $beforeCountArray
* @param $afterCountArray
* @return int[]
*/
public static function countInc($beforeCountArray, $afterCountArray): array
{
if (empty($beforeCountArray)){
$beforeCountArray = ['low' => 0, 'high' => 0, 'odd' => 0, 'even' => 0, 'red' => 0, 'black' => 0, 'zero' => 0];
}
foreach ($beforeCountArray as $k => $v){
if (in_array($k, $afterCountArray)){
$beforeCountArray[$k] = $v + 1;
}
}
return $beforeCountArray;
}
/**
* 分析结果 控制端传入一个数 方法对其分析 输出结果
* @param $resultArray
* @return array
*/
public static function parseResult($result): array
{
// 返回数组
$returnArray = [];
$returnArray[] = 'straight_'.$result;
if ($result != 0) {
if ($result >= 1 && $result <= 18) {
$returnArray[] = 'low';
}
if ($result >= 19 && $result <= 36) {
$returnArray[] = 'high';
}
if ($result % 2 == 0) {
$returnArray[] = 'even';
} else {
$returnArray[] = 'odd';
}
if (in_array($result,[1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36])) {
$returnArray[] = 'red';
}
if (in_array($result,[2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35])) {
$returnArray[] = 'black';
}
if (in_array($result,[1,4,7,10,13,16,19,22,25,28,31,34])) {
$returnArray[] = 'column_1';
}
if (in_array($result,[2,5,8,11,14,17,20,23,26,29,32,35])) {
$returnArray[] = 'column_2';
}
if (in_array($result,[3,6,9,12,15,18,21,24,27,30,33,36])) {
$returnArray[] = 'column_3';
}
if ($result >= 1 && $result <= 12) {
$returnArray[] = 'dozen_1';
}
if ($result >= 13 && $result <= 24) {
$returnArray[] = 'dozen_2';
}
if ($result >= 25 && $result <= 36) {
$returnArray[] = 'dozen_3';
}
}
return $returnArray;
}
/**
* 下注额自增方法
* @param $beforeAmountArray
* @param $afterAmountArray
* @return array
*/
public static function amountInc($beforeAmountArray, $afterAmountArray): array
{
$returnArray = [];
foreach ($afterAmountArray as $k => $v){
if (array_key_exists($k, $beforeAmountArray)){
$returnArray[$k] = $beforeAmountArray[$k] + $v;
unset($beforeAmountArray[$k]);
} else {
$returnArray[$k] = $v;
}
}
return $returnArray + $beforeAmountArray;
}
}
+342
View File
@@ -0,0 +1,342 @@
<?php
namespace freedom\utils;
use app\models\table\Table;
/**
* TODO swooleSession工具类
* Class SocketSession
* @package freedom\utils
*/
class SocketSession
{
/**
* 大房名称,所有有效连接都会加入
* @var string
*/
const HOUSE_NAME = 'house';
/**
* 控制台房间
* @var string
*/
const SPACE_ROOM_NAME = 'space';
/**
* 会员房间
* @var string
*/
const USER_ROOM_NAME = 'user';
/**
* 扫描房间
* @var string
*/
const SCAN_ROOM_NAME = 'scan';
/**
* 接口房间
* @var string
*/
const API_ROOM_NAME = 'api';
/**
* 经理房间
* @var string
*/
const MANAGER_ROOM_NAME = 'manager';
/**
* TODO 连接socket成功后保存session的工具方法,所有连接将加入house,不同连接模式加入不同的房间
* @param array $event
* @param string $mode
* @return void;
*/
public static function saveSocketSession(array $event, string $mode){
$ws = app('\think\swoole\WebSocket');
$fd = $ws->getSender();
//保存信息到table
$tableFd = app('swoole.table.fd');
if($mode == 'space'){
$tableSpace = app('swoole.table.space');
$tableId = $event['table_id'];
$tableName = $event['table_name'];
//查找原本是否有登录
$spaceInfo = $tableSpace->get((string) $tableId);
if(!empty($spaceInfo)){
$tableSpace->del((string) $tableId);
$tableFd->del((string) $spaceInfo['fd']);
$ws->setSender(0)->to($spaceInfo['fd'])->emit('RepeatedEntry',['status' => true, 'msg' => 'repeated_entry']);
}
$tableFd->set((string) $fd,[
'mode' => 'space',
'table_id' => $tableId,
'table_name' => $tableName,
]);
$tableSpace->set((string) $tableId,[
'fd' => $fd,
'mode' => 'space',
'table_name' => $tableName,
]);
$ws->join(self::SPACE_ROOM_NAME);
}elseif($mode == 'scan'){
$tableScan = app('swoole.table.scan');
$appid = $event['appid'];
//查找原本是否有登录
$scanInfo = $tableScan->get((string) $appid);
if(!empty($scanInfo)){
$tableScan->del((string) $appid);
$tableFd->del((string) $scanInfo['fd']);
$ws->setSender(0)->to($scanInfo['fd'])->emit('RepeatedEntry',['status' => true, 'msg' => 'repeated_entry']);
}
$tableFd->set((string) $fd,[
'mode' => 'scan',
'scan_appid' => $appid,
]);
$tableScan->set((string) $appid,[
'fd' => $fd,
'mode' => 'scan',
'appid' => $appid,
]);
$ws->join(self::SCAN_ROOM_NAME);
}elseif($mode == 'user'){
$tableUser = app('swoole.table.user');
$user_id = $event['user_id'];
$username = $event['username'];
//查找原本是否有登录
$userInfo = $tableUser->get((string) $user_id);
if(!empty($userInfo)){
$tableUser->del((string) $user_id);
$tableFd->del((string) $userInfo['fd']);
$ws->setSender(0)->to($userInfo['fd'])->emit('RepeatedEntry',['status' => true, 'msg' => 'repeated_entry']);
}
$tableFd->set((string) $fd,[
'mode' => 'user',
'user_id' => $user_id,
'username' => $username,
]);
$tableUser->set((string) $user_id,[
'fd' => $fd,
'mode' => 'user',
'username' => $username,
'isToBet' => 1,
'toBetTime' => time(),
'isToRob' => 1,
'toRobTime' => time(),
'isToCancelBet' => 1,
'toCancelBetTime' => time(),
'isToSeat' => 1,
'toSeatTime' => time(),
'isToLeaveSeat' => 1,
'toLeaveSeatTime' => time(),
]);
$ws->join(self::USER_ROOM_NAME);
} elseif ($mode == 'api'){
$tableApi = app('swoole.table.api');
$appid = $event['appid'];
//查找原本是否有登录
$apiInfo = $tableApi->get((string) $appid);
if(empty($scanInfo)){
$tableApi->del((string) $appid);
$tableFd->del((string) $apiInfo['fd']);
}
$tableFd->set((string) $fd,[
'mode' => 'scan',
'api_appid' => $appid,
]);
$tableApi->set((string) $appid,[
'fd' => $fd,
'mode' => 'api',
'appid' => $appid,
]);
$ws->join(self::API_ROOM_NAME);
} elseif ($mode == 'manager'){
$tableManager = app('swoole.table.manager');
$user_id = $event['user_id'];
$username = $event['username'];
//查找原本是否有登录
$userInfo = $tableManager->get((string) $user_id);
if(!empty($userInfo)){
$tableManager->del((string) $user_id);
$tableFd->del((string) $userInfo['fd']);
$ws->setSender(0)->to($userInfo['fd'])->emit('RepeatedEntry',['status' => true, 'msg' => 'repeated_entry']);
}
$tableFd->set((string) $fd,[
'mode' => 'manager',
'user_id' => $user_id,
'username' => $username,
]);
$tableManager->set((string) $user_id,[
'fd' => $fd,
'mode' => 'manager',
'username' => $username,
]);
//电投用
$ws->join(self::MANAGER_ROOM_NAME);
}
//加入房子
$ws->join(self::HOUSE_NAME);
}
/**
* TODO 检查房间是否存在有效连接
* @param int $fd
* @param string $mode
* @return bool;
*/
public static function checkSocketSession(int $fd, string $mode): bool
{
$tableFd = app('swoole.table.fd');
$fdInfo = $tableFd->get((string) $fd);
if(!empty($fdInfo)){
if($mode == 'space' || $mode == 'sb'){
$tableSpace = app('swoole.table.space');
$spaceInfo = $tableSpace->get((string) $fdInfo['table_id']);
if(!empty($spaceInfo)){
return true;
}else{
return false;
}
}elseif($mode == 'scan'){
$tableScan = app('swoole.table.scan');
$scanInfo = $tableScan->get((string) $fdInfo['scan_appid']);
if(!empty($scanInfo)){
return true;
}else{
return false;
}
}elseif($mode == 'user'){
$tableUser = app('swoole.table.user');
$userInfo = $tableUser->get((string) $fdInfo['user_id']);
if(!empty($userInfo)){
return true;
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}
/**
* TODO 事件执行的权限检查
* @param array $event
* @param string $mode
* @return array;
*/
public static function preliminaryCheck(array $event, string $mode): array
{
$ws = app('\think\swoole\WebSocket');
$tableId = intval($event['table_id']);
$tableInfo = Table::get($tableId);
if ($mode == 'scan' && $tableInfo['scanner_type'] == 2) {
$mode = 'sb';
}
if(SocketSession::checkSocketSession(intval($ws->getSender()),$mode) == false) {
return ['status' => false, 'msg' => 'no_right'];
}
if(!$tableInfo) {
return ['status' => false, 'msg' => 'not_table_data'];
}
return ['status' => true, 'data' => $tableInfo];
}
/**
* TODO 检查是否重复提交
* @param int $fd
* @param string $mode
* @param string $e
* @return bool;
*/
public static function checkRepeat(int $fd, string $mode, string $e): bool
{
$tableFd = app('swoole.table.fd');
$fdInfo = $tableFd->get((string) $fd);
if($mode == 'user'){
$user_id = $fdInfo['user_id'];
$tableUser = app('swoole.table.user');
$userInfo = $tableUser->get((string) $user_id);
if(!empty($userInfo)){
if($e == 'isToBet'){
if($userInfo['isToBet'] == 1 || $userInfo['toBetTime'] <= (time() - 10)){
$userInfo['isToBet'] = 0;
$userInfo['toBetTime'] = time();
$tableUser->set((string) $user_id, $userInfo);
return true;
}else{
return false;
}
}elseif($e == 'isToRob'){
if($userInfo['isToRob'] == 1 || $userInfo['toRobTime'] <= (time() - 10)){
$userInfo['isToRob'] = 0;
$userInfo['toRobTime'] = time();
$tableUser->set((string) $user_id, $userInfo);
return true;
}else{
return false;
}
}elseif($e == 'isToCancelBet'){
if($userInfo['isToCancelBet'] == 1 || $userInfo['toCancelBetTime'] <= (time() - 10)){
$userInfo['isToCancelBet'] = 0;
$userInfo['toCancelBetTime'] = time();
$tableUser->set((string) $user_id, $userInfo);
return true;
}else{
return false;
}
}elseif($e == 'isToSeat'){
if($userInfo['isToSeat'] == 1 || $userInfo['toSeatTime'] <= (time() - 10)){
$userInfo['isToSeat'] = 0;
$userInfo['toSeatTime'] = time();
$tableUser->set((string) $user_id, $userInfo);
return true;
}else{
return false;
}
}elseif($e == 'isToLeaveSeat'){
if($userInfo['isToLeaveSeat'] == 1 || $userInfo['toLeaveSeatTime'] <= (time() - 10)){
$userInfo['isToLeaveSeat'] = 0;
$userInfo['toLeaveSeatTime'] = time();
$tableUser->set((string) $user_id, $userInfo);
return true;
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}elseif($mode == 'space'){
return false;
}else{
return false;
}
}
/**
* TODO 重置重复值
* @param int $fd
* @param string $mode
* @param string $e
* @return void;
*/
public static function resetRepeat(int $fd, string $mode, string $e)
{
$tableFd = app('swoole.table.fd');
$fdInfo = $tableFd->get((string) $fd);
if($mode == 'user'){
$user_id = $fdInfo['user_id'];
$tableUser = app('swoole.table.user');
$userInfo = $tableUser->get((string) $user_id);
$userInfo[$e] = 1;
$tableUser->set((string) $user_id, $userInfo);
}
}
}
+114
View File
@@ -0,0 +1,114 @@
<?php
namespace freedom\utils;
class ToningUtil
{
/**
* 结果数目自增方法
* @param $result
* @param $afterCountString
* @return int[]
*/
public static function countInc($result, $afterCountString): array
{
$array = [
'zero_count' => 0,
'one_count' => 0,
'two_count' => 0,
'three_count' => 0,
'four_count' => 0,
'big_count' => 0,
'small_count' => 0,
'singular_count' => 0,
'plural_count' => 0
];
if ($result == 0){
$array['zero_count'] = 1;
$array['small_count'] = 1;
$array['plural_count'] = 1;
}
if ($result == 1){
$array['one_count'] = 1;
$array['small_count'] = 1;
$array['singular_count'] = 1;
}
if ($result == 2){
$array['two_count'] = 1;
}
if ($result == 3){
$array['three_count'] = 1;
$array['big_count'] = 1;
$array['singular_count'] = 1;
}
if ($result == 4){
$array['four_count'] = 1;
$array['big_count'] = 1;
$array['plural_count'] = 1;
}
$afterCountArray = string_to_array($afterCountString);
foreach ($array as $k => $v){
foreach ($afterCountArray as $key => $value){
if ($k == $key){
$array[$k] = $v + intval($value);
}
}
}
return $array;
}
/**
* 下注额自增方法
* @param $beforeAmountArray
* @param $afterAmountArray
* @return array
*/
public static function amountInc($beforeAmountArray, $afterAmountArray): array
{
if (empty($beforeAmountArray)){
$beforeAmountArray = [
'toning_zero' => 0,
'toning_four' => 0,
'toning_one' => 0,
'toning_three' => 0,
'toning_big' => 0,
'toning_small' => 0,
'toning_singular' => 0,
'toning_plural' => 0
];
}
$returnArray = [];
foreach ($beforeAmountArray as $k => $v){
foreach ($afterAmountArray as $key => $value){
if ($k == $key){
$returnArray[$k] = intval($v) + intval($value);
}
}
}
return $returnArray;
}
/**
* 结果汇总字符串转数组
* @param $countString
* @return array
*/
public static function parseCount($countString): array
{
if (empty($countString)){
return [
'zero_count' => 0,
'one_count' => 0,
'two_count' => 0,
'three_count' => 0,
'four_count' => 0,
'big_count' => 0,
'small_count' => 0,
'singular_count' => 0,
'plural_count' => 0
];
} else {
return string_to_array($countString);
}
}
}
+506
View File
@@ -0,0 +1,506 @@
<?php
namespace freedom\utils;
/**
* TODO 露珠类
* Class Waybill
* @package freedom\utils
*/
class Waybill
{
/**
* TODO Toning露珠获取定位方法
* @param array $ns 局数组
* @return array;
*/
public static function waybillToning(array $ns): array
{
/**************************** 计算 showRoad start ***************************/
$showRoad = array_chunk($ns,6);
$showRoadLocation = array();
foreach($showRoad as $k => $v){
foreach($v as $key => $val){
$pushData = array('show_x' => $k + 1, 'show_y' =>$key + 1, 'result' => $val['toning_result']);
array_push($showRoadLocation,$pushData);
}
}
/**************************** 计算 showRoad end ***************************/
return (['status'=>true,'msg'=>'数据存在','waybill'=>$showRoadLocation]);
}
/**
* TODO Roulette露珠获取定位方法
* @param array $ns 局数组
* @return array;
*/
public static function waybillRoulette(array $ns): array
{
/**************************** 计算 showRoad start ***************************/
$showRoad = array_chunk($ns,6);
$showRoadLocation = array();
foreach($showRoad as $k => $v){
foreach($v as $key => $val){
$pushData = array('show_x' => $k + 1, 'show_y' =>$key + 1, 'result' => $val['roulette_result']);
array_push($showRoadLocation,$pushData);
}
}
/**************************** 计算 showRoad end ***************************/
return (['status'=>true,'msg'=>'数据存在','waybill'=>$showRoadLocation]);
}
/**
* TODO Nn&Tc露珠获取定位方法
* @param array $ns 局数组
* @return array;
*/
public static function waybillNn(array $ns): array
{
$showRoadLocation = array();
foreach($ns as $k => $v){
$pushData2 = array('show_x' => $k + 1, 'show_y' =>2,'type' => 2, 'result' => $v['result_player_1'], 'is_win' => $v['win_player_1']);
$pushData3 = array('show_x' => $k + 1, 'show_y' =>3,'type' => 2, 'result' => $v['result_player_2'], 'is_win' => $v['win_player_2']);
$pushData4 = array('show_x' => $k + 1, 'show_y' =>4,'type' => 2, 'result' => $v['result_player_3'], 'is_win' => $v['win_player_3']);
if($v['win_player_1'] == 0 && $v['win_player_2'] == 0 && $v['win_player_3'] == 0){
$banker_win = 1;
}else{
$banker_win = 0;
}
$pushData1 = array('show_x' => $k + 1, 'show_y' =>1,'type' => 1, 'result' => $v['result_banker'], 'is_win' => $banker_win);
array_push($showRoadLocation,$pushData1);
array_push($showRoadLocation,$pushData2);
array_push($showRoadLocation,$pushData3);
array_push($showRoadLocation,$pushData4);
}
return (['status'=>true,'msg'=>'数据存在','waybill'=>$showRoadLocation]);
}
/**
* TODO DT&Baccarat露珠获取定位方法
* @param array $ns 局数组
* @return array;
*/
public static function waybill(array $ns): array
{
/**************************** 计算 sanxingRoad start ***************************/
$sanxingRoad = array();
$firstTieNum = 0;
$isFirst = true;
$num = 0;
foreach($ns AS $v){
if($isFirst == true){
if($v['result'] == 3){
$firstTieNum++;
}elseif($v['result'] == 1 || $v['result'] == 2){
$v['tie_num'] = $firstTieNum;
$sanxingRoad[$num] = $v;
$isFirst = false;
$num++;
}
}else{
if($v['result'] == 3){
$sanxingRoad[$num-1]['tie_num'] = $sanxingRoad[$num-1]['tie_num'] + 1;
}elseif($v['result'] == 1 || $v['result'] == 2){
$v['tie_num'] = 0;
$sanxingRoad[] = $v;
$num++;
}
}
}
$sanxingRoad = array_chunk($sanxingRoad,3);
$sanxingRoadLocation = array();
foreach($sanxingRoad AS $k => $v){
foreach($v as $key => $val){
$pushData = array('show_x' => $k + 1, 'show_y' =>$key + 1, 'result' => $val['result'], 'pair' => $val['pair'], 'tie_num' => $val['tie_num']);
array_push($sanxingRoadLocation,$pushData);
}
}
/**************************** 计算 sanxingRoad end ***************************/
/**************************** 计算 showRoad start ***************************/
$showRoad = array_chunk($ns,6);
$showRoadLocation = array();
foreach($showRoad as $k => $v){
foreach($v as $key => $val){
$pushData = array('show_x' => $k + 1, 'show_y' =>$key + 1, 'result' => $val['result'], 'pair' => $val['pair']);
array_push($showRoadLocation,$pushData);
}
}
/**************************** 计算 showRoad end ***************************/
$bigRoad = array();
$bigEyeRoad = array();
$pathway = array();
$roach = array();
/**************************** 计算 bigRoad start ***************************/
//列
$yKey = 0;
//行
$xKey = 0;
$last = array();
foreach($ns AS $key => $value){
if($value['pair'] == 1){
$pair = 1;
}elseif($value['pair'] == 2){
$pair = 2;
}elseif($value['pair'] == 3){
$pair = 3;
}else{
$pair = 0;
}
if($key == 0 && $value['result'] == 3){
$bigRoad[$yKey][$xKey] = array('result' => 3, 'tie_num' => 1, 'pair' => $pair);
$last = array('yKey' => $yKey, 'xKey' => $xKey);
}elseif($yKey == 0 && $xKey == 0 && !empty($last) && $value['result'] != 3){
$bigRoad[$last['yKey']][$last['xKey']]['result'] = $value['result'];
$bigRoad[$last['yKey']][$last['xKey']]['pair'] = $value['pair'];
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoad[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3){
$yKey++;
$xKey = 0;
}elseif(isset($ns[$key+1]) && $ns[$key+1]['result'] == $bigRoad[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3){
$xKey++;
}
$last = array('yKey' => $yKey, 'xKey' => $xKey);
}elseif($key > 0 && $value['result'] == 3){
$bigRoad[$last['yKey']][$last['xKey']]['tie_num'] = $bigRoad[$last['yKey']][$last['xKey']]['tie_num'] + 1;
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoad[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3 && $bigRoad[$last['yKey']][$last['xKey']]['result'] != 3){
$yKey++;
$xKey = 0;
}elseif(isset($ns[$key+1]) && $ns[$key+1]['result'] == $bigRoad[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3 && $bigRoad[$last['yKey']][$last['xKey']]['result'] != 3){
$xKey++;
}
$last = array('yKey' => $last['yKey'], 'xKey' => $last['xKey']);
}else{
$bigRoad[$yKey][$xKey] = array('result' => $value['result'], 'tie_num' => 0, 'pair' => $pair);
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoad[$yKey][$xKey]['result'] && $ns[$key+1]['result'] != 3){
$yKey++;
$xKey = 0;
}elseif(isset($ns[$key+1]) && $ns[$key+1]['result'] == $bigRoad[$yKey][$xKey]['result'] && $ns[$key+1]['result'] != 3){
$xKey++;
}
$last = array('yKey' => $yKey, 'xKey' => $xKey);
}
}
//重新计算坐标
$bigRoadLocation = array();
$occupy = array();
foreach($bigRoad AS $key => $value){
$swerve = false;
$swerveY = $key;
foreach($value AS $k => $v){
$show_y = $key;
$show_x = $k;
if($show_x > 5 && $swerve === false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = 5;
array_push($occupy,$show_y.'-'.$show_x);
}elseif(in_array($show_y.'-'.$show_x,$occupy)){
if($swerve === false){
$swerve = $show_x - 1;
}
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
array_push($occupy,$show_y.'-'.$show_x);
}elseif($swerve !== false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
array_push($occupy,$show_y.'-'.$show_x);
}
$pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result'], 'pair' => $v['pair'], 'tie_num' => $v['tie_num']);
array_push($bigRoadLocation,$pushArray);
}
}
/**************************** 计算 bigRoad end ***************************/
/**************************** 计算 bigEyeRoad start ***************************/
$bigEyeRoadStart = false;
$bigEyeRoadYKey = 0;
$bigEyeRoadXKey = 0;
$bigEyeRoadLast = array();
foreach($bigRoad AS $key => $value){
foreach($value AS $k => $v){
if($key == 1 && $k == 1 && isset($bigRoad[1][1])){
if(isset($bigRoad[0][1])){
$bigEyeRoad[0][0] = array('result' => 1);
}else{
$bigEyeRoad[0][0] = array('result' => 2);
}
$bigEyeRoadStart = true;
$bigEyeRoadLast = $bigEyeRoad[0][0];
continue;
}
if($key == 2 && $k == 0 && !isset($bigEyeRoad[0][0])){
if(isset($bigRoad[0]) && isset($bigRoad[1]) && count($bigRoad[0]) == count($bigRoad[1])){
$bigEyeRoad[0][0] = array('result' => 1);
}else{
$bigEyeRoad[0][0] = array('result' => 2);
}
$bigEyeRoadStart = true;
$bigEyeRoadLast = $bigEyeRoad[0][0];
continue;
}
if($bigEyeRoadStart == true){
if($k == 0){ //第一个
$p1 = $key - 1;
$p2 = $key - 2;
if(count($bigRoad[$p1]) == count($bigRoad[$p2])){
$bigEyeRoadPushData = array('result' => 1);
}else{
$bigEyeRoadPushData = array('result' => 2);
}
}elseif($k == 1){ //第二个
if(isset($bigRoad[$key-1][$k])){
$bigEyeRoadPushData = array('result' => 1);
}else{
$bigEyeRoadPushData = array('result' => 2);
}
}else{ //第三个或者之后那些
if(isset($bigRoad[$key-1][$k-1]) && !isset($bigRoad[$key-1][$k])){
$bigEyeRoadPushData = array('result' => 2);
}else{
$bigEyeRoadPushData = array('result' => 1);
}
}
if($bigEyeRoadLast['result'] == $bigEyeRoadPushData['result']){
$bigEyeRoadXKey++;
}else{
$bigEyeRoadYKey++;
$bigEyeRoadXKey = 0;
}
$bigEyeRoad[$bigEyeRoadYKey][$bigEyeRoadXKey] = $bigEyeRoadPushData;
$bigEyeRoadLast = $bigEyeRoadPushData;
}
}
}
//重新计算坐标
$bigEyeRoadLocation = array();
$occupyEye = array();
foreach($bigEyeRoad AS $key => $value){
$swerve = false;
$swerveY = $key;
foreach($value AS $k => $v){
$show_y = $key;
$show_x = $k;
if($show_x > 5 && $swerve === false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = 5;
array_push($occupyEye,$show_y.'-'.$show_x);
}elseif(in_array($show_y.'-'.$show_x,$occupyEye)){
if($swerve === false){
$swerve = $show_x - 1;
}
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
array_push($occupyEye,$show_y.'-'.$show_x);
}elseif($swerve !== false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
array_push($occupyEye,$show_y.'-'.$show_x);
}
$pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result']);
array_push($bigEyeRoadLocation,$pushArray);
}
}
/**************************** 计算 bigEyeRoad end ***************************/
/**************************** 计算 pathway start ***************************/
$pathwayStart = false;
$pathwayYKey = 0;
$pathwayXKey = 0;
$pathwayLast = array();
foreach($bigRoad AS $key => $value){
foreach($value AS $k => $v){
if($key == 2 && $k == 1 && isset($bigRoad[2][1])){
if(isset($bigRoad[0][1])){
$pathway[0][0] = array('result' => 1);
}else{
$pathway[0][0] = array('result' => 2);
}
$pathwayStart = true;
$pathwayLast = $pathway[0][0];
continue;
}
if($key == 3 && $k == 0 && !isset($pathway[0][0])){
if(isset($bigRoad[0]) && isset($bigRoad[2]) && count($bigRoad[0]) == count($bigRoad[2])){
$pathway[0][0] = array('result' => 1);
}else{
$pathway[0][0] = array('result' => 2);
}
$pathwayStart = true;
$pathwayLast = $pathway[0][0];
continue;
}
if($pathwayStart == true){
if($k == 0){ //第一个
$p1 = $key - 1;
$p2 = $key - 3;
if(count($bigRoad[$p1]) == count($bigRoad[$p2])){
$pushData = array('result' => 1);
}else{
$pushData = array('result' => 2);
}
}elseif($k == 1){ //第二个
if(isset($bigRoad[$key-2][$k])){
$pushData = array('result' => 1);
}else{
$pushData = array('result' => 2);
}
}else{ //第三个或者之后那些
if(isset($bigRoad[$key-2][$k-1]) && !isset($bigRoad[$key-2][$k])){
$pushData = array('result' => 2);
}else{
$pushData = array('result' => 1);
}
}
if($pathwayLast['result'] == $pushData['result']){
$pathwayXKey++;
}else{
$pathwayYKey++;
$pathwayXKey = 0;
}
$pathway[$pathwayYKey][$pathwayXKey] = $pushData;
$pathwayLast = $pushData;
}
}
}
//echo "<pre>";
//print_r($pathway);
//echo "</pre>";
//exit();
//重新计算坐标
$pathwayLocation = array();
$occupyPathway = array();
foreach($pathway AS $key => $value){
$swerve = false;
$swerveY = $key;
foreach($value AS $k => $v){
$show_y = $key;
$show_x = $k;
if($show_x > 5 && $swerve === false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = 5;
array_push($occupyPathway,$show_y.'-'.$show_x);
}elseif(in_array($show_y.'-'.$show_x,$occupyPathway)){
if($swerve === false){
$swerve = $show_x - 1;
}
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
array_push($occupyPathway,$show_y.'-'.$show_x);
}elseif($swerve !== false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
array_push($occupyPathway,$show_y.'-'.$show_x);
}
$pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result']);
array_push($pathwayLocation,$pushArray);
}
}
/**************************** 计算 pathway end ***************************/
/**************************** 计算 roach start ***************************/
$roachStart = false;
$roachYKey = 0;
$roachXKey = 0;
$roachLast = array();
foreach($bigRoad AS $key => $value){
foreach($value AS $k => $v){
if($key == 3 && $k == 1 && isset($bigRoad[3][1])){
if(isset($bigRoad[0][1])){
$roach[0][0] = array('result' => 1);
}else{
$roach[0][0] = array('result' => 2);
}
$roachStart = true;
$roachLast = $roach[0][0];
continue;
}
if($key == 4 && $k == 0 && !isset($roach[0][0])){
if(isset($bigRoad[0]) && isset($bigRoad[3]) && count($bigRoad[0]) == count($bigRoad[3])){
$roach[0][0] = array('result' => 1);
}else{
$roach[0][0] = array('result' => 2);
}
$roachStart = true;
$roachLast = $roach[0][0];
continue;
}
if($roachStart == true){
if($k == 0){ //第一个
$p1 = $key - 1;
$p2 = $key - 4;
if(count($bigRoad[$p1]) == count($bigRoad[$p2])){
$pushData = array('result' => 1);
}else{
$pushData = array('result' => 2);
}
}elseif($k == 1){ //第二个
if(isset($bigRoad[$key-3][$k])){
$pushData = array('result' => 1);
}else{
$pushData = array('result' => 2);
}
}else{ //第三个或者之后那些
if(isset($bigRoad[$key-3][$k-1]) && !isset($bigRoad[$key-3][$k])){
$pushData = array('result' => 2);
}else{
$pushData = array('result' => 1);
}
}
if($roachLast['result'] == $pushData['result']){
$roachXKey++;
}else{
$roachYKey++;
$roachXKey = 0;
}
$roach[$roachYKey][$roachXKey] = $pushData;
$roachLast = $pushData;
}
}
}
//重新计算坐标
$roachLocation = array();
$occupyRoach = array();
foreach($roach AS $key => $value){
$swerve = false;
$swerveY = $key;
foreach($value AS $k => $v){
$show_y = $key;
$show_x = $k;
if($show_x > 5 && $swerve === false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = 5;
array_push($occupyRoach,$show_y.'-'.$show_x);
}elseif(in_array($show_y.'-'.$show_x,$occupyRoach)){
if($swerve === false){
$swerve = $show_x - 1;
}
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
array_push($occupyRoach,$show_y.'-'.$show_x);
}elseif($swerve !== false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
array_push($occupyRoach,$show_y.'-'.$show_x);
}
$pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result']);
array_push($roachLocation,$pushArray);
}
}
$data = array();
$data['showRoad'] = $showRoadLocation;
$data['bigRoad'] = $bigRoadLocation;
$data['bigEyeRoad'] = $bigEyeRoadLocation;
$data['pathway'] = $pathwayLocation;
$data['roach'] = $roachLocation;
$data['sanxingRoad'] = $sanxingRoadLocation;
return ['status'=>true,'msg'=>'数据存在','waybill'=>$data];
}
}