• 游戏--疯狂猜字随机混乱正确答案逻辑


    不重复字库:

     public static $wordConfig = array(
            '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','退','','','','',' ','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','耀','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','姿','','','','','','','','','廿','','','','','','','','','','丿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','诿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','涿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','槿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','趿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','鱿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','便','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','齿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','蹿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','殿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','饿','','','','','','','','',
        );

    数据库存的正确答案为 a,b,c,d  

    $config = self::$wordConfig;
            $configNum = count($config);
            foreach($list as  $key => $row){
    
                $ignorRandAgain = null;//这个其实可以不要
                $recodRand = null;
                $trueRand = null;
                $trueWord = null;
                $randWord = null;
                $theTrue = explode(',',$row['trueAnswer']);
                $ansNum = count($theTrue);
                //确定正确答案在数组中出现的位置
                foreach($theTrue as $tw){
                    $yes_Or_no = true;
                    do {
                        $temp = rand(0,11);
                        //判断是否位置被占用
                        if(!in_array($temp,$randWord)){
                            $trueWord[] = $temp;
                            //占用位置
                            $randWord[] = $temp;
                            $yes_Or_no = false;
                        }
                    } while ($yes_Or_no);
                }
                //确定混乱文字出现的位置
                for($i = 0; $i < 12-$ansNum; $i++){
                    $yes_Or_no = true;
                    do {
                        //在12个字中的位置
                        $temp = rand(0,11);
                        //判断是否位置被占用
                        if(!in_array($temp,$randWord)){
                            $trueRand[] = $temp;
                            //占用位置
                            $randWord[] = $temp;
                            //位置没有被占用后 再确定混乱字符挑选
                            $yes_Or_no_config = true;
                            do{
                                $tempConfig = rand(0,$configNum);
                                if(!in_array($tempConfig,$ignorRandAgain)){
                                    $recodRand[] = $tempConfig;
                                    $ignorRandAgain[] = $tempConfig;//这一步可以不要  直接判断recordRand就可以了
                                    $yes_Or_no_config = false;
                                }
                            }while($yes_Or_no_config);
                            $yes_Or_no = false;
                        }
                    } while ($yes_Or_no);
                }
                $record = null;
                $count = 0;
                for($i = 0; $i < 12; $i++){
                    //判断当前位置属于谁
                    if(in_array($i,$trueRand)){
                        $word = $config[$recodRand[$i-$count]];
                        $record[] = $word;
                    }else{
                        $word = $theTrue[$count];
                        $record[] = $word;
                        $count++;
                    }
                }
                $list[$key]['falseAnswer'] = implode(',',$record);
            }
    积累知识,分享知识,学习知识。
  • 相关阅读:
    python自动化测试学习笔记-8单元测试unittest模块
    python自动化测试学习笔记-8多线程
    python自动化测试学习笔记-7面向对象编程,类,继承,实例变量,邮件
    python自动化测试学习笔记-6excel操作xlwt、xlrd、xlutils模块
    android 拍照上传文件 原生定位
    golang 固定worker 工作池
    小程序报错x509: certificate signed by unknown authority
    PostgreSQL 添加postgis插件实现获取经纬度间的距离
    微信小程序使用mqtt mpvue mosquito
    golang 调用顺丰API接口测试
  • 原文地址:https://www.cnblogs.com/bin-pureLife/p/4494577.html
Copyright © 2020-2023  润新知