Pro/application/console/controller/Testld.php
2026-01-28 15:54:52 +08:00

491 lines
15 KiB
PHP

<?php
namespace app\console\controller;
use think\Controller;
use think\Request;
use think\Db;
class Testld Extends Common{
//测试路单
/*
public function testld(){
$ns = Db::name('number_tab')->where(array('boot_id' => 4, 'bet_status' => 3))->order('id ASC')->select();
$bigRoad = array();
$bigEyeRoad = array();
//列
$yKey = 0;
//行
$xKey = 0;
//上一回合坐标
$last = array();
foreach($ns AS $key => $value){
if($key == 0 && $value['result'] == 3){
$bigRoad[$yKey][$xKey] = array('result' => 3, 'tie_num' => 1);
$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;
}elseif($yKey == 0 && $xKey == 0 && !empty($last) && $value['result'] != 3){
$bigRoad[$last['yKey']][$last['xKey']]['result'] = $value['result'];
$last = array('yKey' => $yKey, 'xKey' => $xKey);
}else{
$bigRoad[$yKey][$xKey] = array('result' => $value['result'], 'tie_num' => 0);
$last = array('yKey' => $yKey, 'xKey' => $xKey);
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoad[$yKey][$xKey]['result']){
$yKey++;
$xKey = 0;
}else{
$xKey++;
}
}
}
$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){
$bigEyeRoadPushData = array();
if($k == 0){ //第一个
$p1 = $key - 1;
$p2 = $key - 2;
if(count($bigRoad[$p1]) == count($bigEyeRoad[$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;
}
}
}
echo "<pre>";
print_r($bigEyeRoad);
echo "</pre>";
}
*/
//测试路单
public function testld2(){
$ns = Db::name('number_tab')->where(array('boot_id' => 7, 'bet_status' => 3))->order('id ASC')->select();
$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 = 'bankerPair';
}elseif($value['pair'] == 2){
$pair = 'playerPair';
}elseif($value['pair'] == 3){
$pair = 'bothPair';
}else{
$pair = 'none';
}
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'];
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_y' => $show_y, 'show_x' => $show_x, 'result' => $v['result'], 'pair' => $v['pair'], 'tie_num' => $v['tie_num']);
array_push($bigRoadLocation,$pushArray);
}
}
//echo "<pre>";
//print_r($bigRoadLocation);
//echo "</pre>";
//exit();
/**************************** 计算 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){
$bigEyeRoadPushData = array();
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_y' => $show_y, 'show_x' => $show_x, 'result' => $v['result']);
array_push($bigEyeRoadLocation,$pushArray);
}
}
echo "<pre>";
print_r($bigEyeRoadLocation);
echo "</pre>";
exit();
/**************************** 计算 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){
$pushData = array();
if($k == 0){ //第一个
$p1 = $key - 1;
$p2 = $key - 3;
if(count($bigRoad[$p1]) == count($pathway[$p2])){
$pushData = array('result' => 1);
}else{
$pushData = array('result' => 2);
}
}elseif($k == 1){ //第二个
if(isset($bigRoad[$key-1][$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;
}
}
}
//重新计算坐标
$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_y' => $show_y, 'show_x' => $show_x, 'result' => $v['result']);
array_push($pathwayLocation,$pushArray);
}
}
echo "<pre>";
print_r($pathwayLocation);
echo "</pre>";
exit();
/**************************** 计算 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){
$pushData = array();
if($k == 0){ //第一个
$p1 = $key - 1;
$p2 = $key - 4;
if(count($bigRoad[$p1]) == count($roach[$p2])){
$pushData = array('result' => 1);
}else{
$pushData = array('result' => 2);
}
}elseif($k == 1){ //第二个
if(isset($bigRoad[$key-1][$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_y' => $show_y, 'show_x' => $show_x, 'result' => $v['result']);
array_push($roachLocation,$pushArray);
}
}
echo "<pre>";
print_r($roachLocation);
echo "</pre>";
exit();
}
}