Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 飞镖游戏计算_Php_Permutation - Fatal编程技术网

Php 飞镖游戏计算

Php 飞镖游戏计算,php,permutation,Php,Permutation,我还没有找到任何用于DART的脚本或代码,所以我一直在写我自己的脚本或代码,如果有人知道一个网站有这些脚本或代码,请让我知道(我已经搜索了多种方法,但没有运气) 我正在尝试为一个飞镖游戏(301/501)制作一个脚本,该脚本将计算完成一个游戏需要射击的目标。当你用飞镖(3、2或1)命中一个准确的分数时,游戏结束,最后一个飞镖是一个双飞镖(例如,分数是170,可以命中2个三倍20秒(2*60)和一个双靶心(2*25) 我开始编写一个脚本,循环遍历这些值,并提取第一个加起来的值。我写得不正确/效率低

我还没有找到任何用于DART的脚本或代码,所以我一直在写我自己的脚本或代码,如果有人知道一个网站有这些脚本或代码,请让我知道(我已经搜索了多种方法,但没有运气)

我正在尝试为一个飞镖游戏(301/501)制作一个脚本,该脚本将计算完成一个游戏需要射击的目标。当你用飞镖(3、2或1)命中一个准确的分数时,游戏结束,最后一个飞镖是一个双飞镖(例如,分数是170,可以命中2个三倍20秒(2*60)和一个双靶心(2*25)

我开始编写一个脚本,循环遍历这些值,并提取第一个加起来的值。我写得不正确/效率低下,因为1.我循环了三次(即使可能只需要1或2个省道),2.我只输出了第一组值,而不是所有值

Example:
Score 50
 1. double bull (25)
 2. 20 + double 15
 3. 20 + 20 + double 5
 4. 16 + 8 + double 13
 5. double 12 + double 12 + double 1
 6. triple 15 + 1 + double 2
 7. etc.
我从这里开始:

$score = $_GET['score'];
if ($score > 170) {
    die('No Outs');
}
$possdarts = array();
$possdartstext = array();
for ($x = 0; $x < 2; $x++) {
    for ($a = 0; $a < 60; $a++) {
        if (($score - $a) >= 0)  {
            $possdarts[] = $a;
            if(($x == 2) && ($a % 2 == 0)) {
                $outs[] = $a;
            }
        }
    }
}
$score=$\u GET['score'];
如果($score>170){
死亡(“无出局”);
}
$possdarts=array();
$possdartstext=array();
对于($x=0;$x<2;$x++){
对于($a=0;$a<60;$a++){
如果(($score-$a)>=0){
$possdarts[]=$a;
如果($x==2)和($a%2==0)){
$outs[]=$a;
}
}
}
}

感谢您的帮助。

这非常接近,尽管它不符合顺序,并且会出现重复

$score = $_GET['score'];
if ($score >170 || $score <=1 ) { 
        $message = 'No outs possible';
    } else {
        for ($x=60; $x >= 0; $x--) {
            if (
                $x <= 20 || 
                $x == 50 || 
                $x == 25 || 
                ($x % 3 == 0) || 
                ($x <= 40 && 
                ($x % 2 == 0)
                )
                ) {
                /*
                if it is less than 20 or equal to, because 20 - 1 on board, 
                if it is less than or equal to 40 and divisible by 2 because it could be a double
                if it is divisible by 3 because it could be a triple
                if it is a double or single bull, no point in checking the double for 60-51 
                */
                for ($xx=60; $xx >= 0; $xx--) {
                    if (
                            $x <= 20 || 
                            $x == 50 || 
                            $x == 25 || 
                            ($x % 3 == 0) || 
                            ($x <= 40 && 
                            ($x % 2 == 0)
                            )
                        ) {
                        for ($xxx=50; $xxx > 0; $xxx = $xxx - 2) {
                            if ($xxx == 48) {
                                $xxx = 40;
                            }
                            $xxxdis = ($xxx / 2) . ' Double';
                            if (($xxx + $xx + $x) == $score) {
                                echo $x . ', ' . $xx . ', ' . $xxxdis . "\n";
                            }
                        }
                    }
                }
            }
        }
    }
$score=$\u GET['score'];
如果($score>170 | |$score=0;$x--){
如果(

$x我会尝试这样做:(你也必须添加三元组,但这是我开始的方式…)你必须有很多可用的内存来使用数组…它消耗了很多。我尝试了170,php用尽了…内存限制。你应该意识到这一点。如果你的服务器允许的话,这不是一个真正的问题

<?php
$score = 50;

if ($score >170 || $score <=1 ) { 
        $message = 'No outs possible';
    } else {

        $outs = array();

        //Create an array with values from 0 to {value of $score}
        for($v=0;$v<$score;$v++) {
            $outs[] = $v;
        }

        // Get combinations of values (like 0 0 1, 0 0 2, 0 0 3 etc with space between values)
        $combinations = getCombinations($outs,3);

        //Create an array when combinations are equal to set score

        $ascArr = array();      
        $possibleOuts = array();
        foreach($combinations as $key=>$c) {
            $tmpArr = explode(' ', $c);             //Create array of each combination (value1, value2, value3)

            //Value3 has to be a double
            $tmpArr[2] *= 2;            

            //Get ascii-value of whole string (without spaces)
            $tc = trim($c);
            $ascValue = getAsciiValueOfString($tc);

            //If sum of array-values is the same as score, add it to outs array
            //Also make sure that ascii-value of string occurence cannot be repeated ('0 1 49' or '0 49 1' is actually same)
            if (array_sum($tmpArr) == $score && !in_array($ascValue, $ascArr)) {        
                $possibleOuts[] = $c . ' double';
                $ascArr[] = $ascValue;
            }

        }

        //Could some more part of outs array (besides last) be a double?
        $doubleOuts = array();
        $do = array();

        foreach($possibleOuts as $value) {
            $tmpArr = explode(' ', $value); 
            $do[0] = $tmpArr[0];
            $do[1] = $tmpArr[1];
            $do[2] = $tmpArr[2];
            $do[3] = $tmpArr[3];

            //Check first value. If first value can be divided into 2 and the second value as well
            //then set double on first value, and reduce second value
            if ($tmpArr[0] % 2 === 0 && $tmpArr[0]>0 && $tmpArr[1] % 2 === 0) {
                $do[0] = $tmpArr[0] . ' double';
                $do[1] = $tmpArr[1] - $tmpArr[0];
            }

            $doubleOuts[] = implode(' ', $do);

        }


        //Merge outs and doubleouts-array
        $posOuts = array_merge($possibleOuts, $doubleOuts);


    // Print it out
    foreach($posOuts as $value) {
        echo $value . ' <br />';
    }



}



//Function for getting value of chars
function getAsciiValueOfString($string)
{
    $ascii = 0;

    for ($i = 0; $i < strlen($string); $i++) 
    { 
        $ascii += ord($string[$i]); 
    }

    return($ascii);
}

//Recursive functions for getting differet combinations
function getCombinations($arr,$n)
{
     $res = array();

     foreach ($arr as $w)
     {
           if ($n==1) $res[] = $w;
           else
           {
                 $perms = getCombinations($arr,$n-1);

                 foreach ($perms as $p)
                 {
                      $res[] = $w." ".$p;
                 } 
           }
     }


     return $res;
}


?>

这是我几年前的账户。如果有人无意中发现了这一点,我最终完成了代码,现在就是了

  • 根据@bestprogrammerintheworld建议更新变量名
  • 允许用户放入他们喜欢的完成省道
  • 删除重复项(例如,“45,30,双2”和“30,45,双2”仅显示一次)
  • (编辑器不会在没有任何内容的情况下从代码中断开列表)

    
    
    Update code现在会遍历所有值,但不会检查第二个省道上的值是否可行。`分数50的输出将给出:48、0、1双45、3、1双45、1、2双42、6、1双。你说这不符合顺序-你希望输出结果如何?举一个前5个左右的例子。提示:你是正确的ally应该使用有意义的变量名称,而不仅仅是在其后面加上一个字母($x、$xx、$xxx、$xxxx表示绝对没有,而且很难阅读)
    0 0 25 double
    0 2 24 double
    0 4 23 double
    0 6 22 double
    0 8 21 double
    0 10 20 double
    0 12 19 double
    0 14 18 double
    0 16 17 double
    0 18 16 double
    0 20 15 double
    0 22 14 double
    0 24 13 double
    0 26 12 double
    0 28 11 double
    0 30 10 double
    0 32 9 double
    0 34 8 double
    0 36 7 double
    0 38 6 double
    0 46 2 double
    0 48 1 double
    1 19 15 double
    1 39 5 double
    3 9 19 double
    3 19 14 double
    3 29 9 double
    3 39 4 double
    5 19 13 double
    5 29 8 double
    5 39 3 double
    7 19 12 double
    7 29 7 double
    7 39 2 double
    9 19 11 double
    9 29 6 double
    10 10 15 double
    10 12 14 double
    10 14 13 double
    10 16 12 double
    10 18 11 double
    10 20 10 double
    10 40 0 double
    11 19 10 double
    13 19 9 double
    15 19 8 double
    17 19 7 double
    19 19 6 double
    19 29 1 double
    0 0 25 double
    0 2 24 double
    0 4 23 double
    0 6 22 double
    0 8 21 double
    0 10 20 double
    0 12 19 double
    0 14 18 double
    0 16 17 double
    0 18 16 double
    0 20 15 double
    0 22 14 double
    0 24 13 double
    0 26 12 double
    0 28 11 double
    0 30 10 double
    0 32 9 double
    0 34 8 double
    0 36 7 double
    0 38 6 double
    0 46 2 double
    0 48 1 double
    1 19 15 double
    1 39 5 double
    3 9 19 double
    3 19 14 double
    3 29 9 double
    3 39 4 double
    5 19 13 double
    5 29 8 double
    5 39 3 double
    7 19 12 double
    7 29 7 double
    7 39 2 double
    9 19 11 double
    9 29 6 double
    10 double 0 15 double
    10 double 2 14 double
    10 double 4 13 double
    10 double 6 12 double
    10 double 8 11 double
    10 double 10 10 double
    10 double 30 0 double
    11 19 10 double
    13 19 9 double
    15 19 8 double
    17 19 7 double
    19 19 6 double
    19 29 1 double
    
    <?php
    $score =$_GET['score'];
    $finaldart = $_GET['out'] * 2;
    if ($score >170 || $score <=1 ) {
        die('No outs possible');
    } else {
        for ($firstdart=60; $firstdart >= 0; $firstdart--) {
            if (
                $firstdart <= 20 || 
                $firstdart == 50 || 
                $firstdart == 25 || 
                ($firstdart % 3 == 0) || 
                ($firstdart <= 40 && $firstdart % 2 == 0)
            ) {
                /*
                if it is less than 20 or equal to, because 20 - 1 on board, 
                if it is less than or equal to 40 and divisible by 2 because it could be a double
                if it is divisible by 3 because it could be a triple
                if it is a double or single bull, no point in checking the double for 60-51 
                */
                for ($seconddart=60; $seconddart >= 0; $seconddart--) {
                    if (
                        $seconddart <= 20 || 
                        $seconddart == 50 || 
                        $seconddart == 25 || 
                        ($seconddart % 3 == 0) || 
                        ($seconddart <= 40 && $seconddart % 2 == 0)
                        ) {
                        for ($thirddart=50; $thirddart > 0; $thirddart = $thirddart - 2) {
                            if ($thirddart == 48) {
                                $thirddart = 40;
                            }
                            $outstring = 'Double ' . ($thirddart / 2);
                            if (($thirddart + $seconddart + $firstdart) == $score && (@!in_array($seconddart . ', ' . $firstdart . ', ' . $outstring . "<br />\n", $pouts) && @!in_array($seconddart . ', ' . $firstdart . ', ' . $outstring . "<br />\n", $everyotherout))) {
                                if ($thirddart == $finaldart) {
                                    $pouts[] = $firstdart . ', ' . $seconddart . ', ' . $outstring . "<br />\n";
                                } else {
                                    $everyotherout[] = $firstdart . ', ' . $seconddart . ', ' . $outstring . "<br />\n";
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if(!empty($finaldart)) {
        if(!empty($pouts)){
            foreach($pouts as $out) {
                echo $out;
            }
            echo "<br />\n" . 'Every Other Out' . "<br /><br />\n";
        } else { 
            echo 'No preferred outs avaliable.' . "<br />\n";
        }
    }
    if(!empty($everyotherout)){
        foreach($everyotherout as $out) {
            echo $out;
        }
    } else if(empty($pouts)){
        echo 'No outs avaliable.';
    }
    ?>