對了,忘記說,
我最近寫的程式都是要在春節連假中再跑,我猜時間至少五天跑不掉吧...
雖然標題變了,不過內容也是跟競爭有關喔~
昨天寫完程式後,跟爸爸討論了一下,提出了一個問題:「如果我的策略跟他的策略不一樣的話怎麼辦?我有怎樣的對策?還是別人的選擇頭來跟我的策略沒有影響?」
這樣的話勝率就不會像之前的程式一樣輸贏的機率都是一半了(之前是兩個人的策略一樣,輸贏的機率當然佔各半)。可能你多或是我少,所以要找到別人的策略我到底要怎麼應對。
程式如下:
<?php
if (isset($argv))
for ($i=1;$i<count($argv);$i++)
{
$it = explode("=",$argv[$i]);
$_GET[$it[0]] = $it[1];
}
$n="\n";
$brn="<br />\n";
date_default_timezone_set("Asia/Taipei");
//設定變數
//mode=0 無變數
//mode=1 凋謝速率
//mode=2 員工貢獻度
//mode=3 競爭
//mode=4 參考 v(自己與敵人的策略不一對勝率的影響)
if(isset($_GET['debug'])) $debug=$_GET['debug'];
else $debug=1;//顯示步驟
if(isset($_GET['from'])) $from=$_GET['from'];
else $from=0;
if(isset($_GET['to'])) $to=$_GET['to'];
else $to=100;
if(isset($_GET['gap'])) $gap=$_GET['gap'];
else $gap=0.1;
if(isset($_GET['army_from'])) $army_from=$_GET['army_from'];
else $army_from=0;
if(isset($_GET['army_to'])) $army_to=$_GET['army_to'];
else $army_to=100;
if(isset($_GET['army_gap'])) $army_gap=$_GET['army_gap'];
else $army_gap=0.1;
if(isset($_GET['choice_time'])) $choice_time=$_GET['choice_time'];
else $choice_time=1;
if(isset($_GET['limit'])) $limit=$_GET['limit'];
else $limit=100;
if(isset($_GET['loop_num'])) $loop_num=$_GET['loop_num'];
else $loop_num=50;
printf("date,me\army,=>");
for($a=$army_from;$a<=$army_to;$a=$a+$army_gap){
printf(",$a");
}
printf("$n");
for($k=$from;$k<=$to;$k=$k+$gap){
$percent=$k;
$thedate=date("m-d H:i");
printf("%s,%.1f,=>", $thedate, $percent);
for($p=$army_from;$p<=$army_to;$p=$p+$army_gap){
$army_percent=$p;
$win=0;
for($j=0;$j<$loop_num;$j++){
//變數設定
$max_num=0;
$max_percent=$limit*$percent/100;
$army_max_percent=$limit*(100-$army_percent)/100;
$percent_num=0;
$army_percent_num=0;
$choice=0;
$army_choice=0;
$time=0;
$army_time=0;
$thisnum=range(1,$limit,1);//(小,大,差)
shuffle($thisnum);//洗牌
for($i=0;$i<$limit;$i++){
if($i>=$max_percent and $i-1<$max_percent) $time=$choice_time;
if($limit-$i>=$army_max_percent and $limit-$i-1<$army_max_percent) $army_time=$choice_time;
$num=$thisnum[$i];//我方此家分數
$army_num=$thisnum[$limit-$i-1];//敵方此家分數
if($max_num<=$num) $max_num=$num;//找尋最大值
if($max_num<=$army_num) $max_num=$army_num;
if($percent_num<$num) $percent_num=$num;
if($army_percent_num<$army_num) $army_percent_num=$army_num;
if($time>0 and $num>=$percent_num and $num>=$army_percent_num) {
$choice=$choice+$num;
$time=$time-1;
$thisnum[$i]=0;
}//拿走
if($army_time>0 and $army_num>=$army_percent_num and $army_num>=$percent_num) {
$army_choice=$army_choice+$army_num;
$army_time=$army_time-1;
$thisnum[$limit-$i-1]=0;
}//敵方拿走
if($debug>0) echo $i+1, " ", $num, " ", $army_num, " ", $percent_num, " ", $army_percent_num, " ", $time, " ", $army_time, $n;//顯示資訊
}
if($debug>0){
echo "Choice: ", $choice, ",", $army_choice, $n;
echo "Max: ", $max_num, $n;
}
if($max_num==$choice) $best++;
if($choice==0) $fail++;
if($max_num>$choice and $choice>0) $fine++;
if($choice>$army_choice) $win++;
}
printf(",%.6f", $win/$loop_num);
}
echo ("$n");
}
?>