zoukankan      html  css  js  c++  java
  • 游戏--疯狂猜字随机混乱正确答案逻辑

    不重复字库:

     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);
            }
    积累知识,分享知识,学习知识。
  • 相关阅读:
    第八周课程总结&实验报告(六)
    第七周课程总结&实验报告(五)
    第六周实验总结&学习总结
    关于我
    各种公告

    笔记 综合
    多项式全家桶
    FFT,NTT 笔记
    省选复习
  • 原文地址:https://www.cnblogs.com/bin-pureLife/p/4494577.html
Copyright © 2011-2022 走看看