Skip to content

Instantly share code, notes, and snippets.

@Zerosen

Zerosen/TODOLIST.txt

Created Sep 20, 2018
Embed
What would you like to do?
スタックオーバーフローで質問用に用意したもの。
240.241.242.243.244.245.246.247.249.250.248.247.246.245.244.243.242.241.240\n
231.000.232.000.234.000.236.237.238.239.238.237.235.000.233.000.232.000.231\n
000.224.000.225.000.226.000.227.229.230.228.227.000.226.000.225.000.224.000\n
215.000.216.000.217.000.218.220.222.223.221.219.218.000.217.000.216.000.215\n
203.205.206.207.208.209.210.211.213.214.212.211.210.209.208.207.206.204.203\n
202.202.202.202.202.202.202.202.202.202.202.202.202.202.202.202.202.202.202\n
000.000.000.000.000.001.000.000.000.000.000.000.000.001.000.000.000.000.000\n
000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000\n
000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000\n
000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000\n
000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000\n
000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000\n
000.000.000.000.000.001.000.000.000.000.000.000.000.001.000.000.000.000.000\n
002.002.002.002.002.002.002.002.002.002.002.002.002.002.002.002.002.002.002\n
003.004.006.007.008.009.010.011.012.014.013.011.010.009.008.007.006.005.003\n
015.000.016.000.017.000.018.019.021.023.022.020.018.000.017.000.016.000.015\n
000.024.000.025.000.026.000.027.028.030.029.027.000.026.000.025.000.024.000\n
031.000.032.000.033.000.035.037.038.039.038.037.036.000.034.000.032.000.031\n
040.041.042.043.044.045.046.047.048.050.049.047.046.045.044.043.042.041.040\n
<?php
/*関数の宣言*/
function show_votes(){
//数えたい。
$vote_sofar = file("投票内容");
$times_vote = file_get_contents("投票ボタンが押された回数");
$int_times_vote = intval($times_vote);
$vote_sofar_num = array();
$maximum=0;
for ($b=0 ; $b<$int_times_vote ; $b++){
$number=0;
$flag=0;
if($b!=0){
for ($c=$b-1 ; $c>=0 ; $c--){//前に重複があるならスキップして次のループへ。
if($vote_sofar[$c] == $vote_sofar[$b]){
$flag=1;
}
}
}
if($flag == 1){
$vote_sofar_num[$b] = -1;
continue;
}
for ($a=0 ; $a<$int_times_vote ; $a++){//以降に重複があればnumberをインクリメント。
if($vote_sofar[$b]==$vote_sofar[$a]){
$number++;
}
}
$vote_sofar_num[$b] = $number;
//echo $vote_sofar_num[$b];
}
$dd = 0;
for ($b=0 ; $b<$int_times_vote ; $b++){
$found_max = 0;
if($vote_sofar_num[$b] > 0){
for ($d=$b+1 ; $d<$int_times_vote ; $d++){//マキシマムを求める。
$pos_max=$b;
if($vote_sofar_num[$b] < $vote_sofar_num[$d]){
$maximum = $vote_sofar_num[$d];
$pos_max=$d;
$found_max = 1; //見つけた。
}
}
//求めたマキシマムと最上の値を交換。
if ($found_max = 1){
$vote_sofar_num[$pos_max] = $vote_sofar_num[$b];
$vote_sofar_num[$b] = $maximum;
$swap = $vote_sofar[$pos_max];
$vote_sofar[$pos_max] = $vote_sofar[$b];
$vote_sofar[$b] = $swap;
}
}
}
for($b=0 ; $b<$int_times_vote ; $b++){
if($vote_sofar_num[$b] > 0){
echo $vote_sofar[$b];
echo ":";
echo $vote_sofar_num[$b];
echo "回\n";
}
}
return;
}
function get_koma_position(){//テキストデータから駒の配置を得る。
global $ban_pos_data;
global $koma_position;
$ban_pos_data=file("ban_pos_data");
for($y=1;$y<=19;$y++){
for($x=1;$x<=19;$x++){
$koma_position[$x][$y] = substr($ban_pos_data[$y-1],4*($x-1),3);
$backup = $koma_position[$x][$y];
$head1 = substr($backup,0,1);
$head2 = substr($backup,0,2);
if ($head1 == 0 && $head2 == 00){
strval($backup);
$box = substr_replace($backup,"",0,2);
intval($box);
$koma_position[$x][$y] = $box;
}else if($head1 == 0 && $head2 != 00){
strval($backup);
$box = substr_replace($backup,"",0,1);
intval($box);
$koma_position[$x][$y] = $box;
}
//$koma_position[$x][$y]の中は最初は001だけどここで1に変換してる
//ようするに最終的には$koma_position[$x][$y]の中身は1であり001か010ではない。
}
}
return;
}
function move_koma(){//0 を000に変換してない。
global $koma_position;
global $ban_pos_data;
chmod("ban_pos_data",0666);
$fx = $_GET["fx-axis"];
$fy = $_GET["fy-axis"];
$tx = $_GET["tx-axis"];
$ty = $_GET["ty-axis"];
$ban_pos_data=file("ban_pos_data");
$dox = $koma_position[$fx][$fy];//1を001へ、10を010へ変換が必要。この時点で文字列。
$dox = conversion($dox);//変換。まだ文字列001。
//echo "test";
//echo $dox;
//strval($dox);
$box = $ban_pos_data[$ty-1];//000.000.000移動先のy列。注$tyに-1を付ける。
//echo $box;
//strval($box);
$box = substr_replace($box,$dox,($tx-1)*4,3);//移動先へ書き込む。
//echo $box;
$ban_pos_data[$ty-1] = $box;//取り出した列へ戻す。
//echo $ban_pos_data[$ty-1];
$box = $ban_pos_data[$fy-1];//000.000.000移動元のy列。
$box = substr_replace($box,"000",($fx-1)*4,3);//移動元を消す。
//echo $box;
$ban_pos_data[$fy-1] = $box;//取り出した列へ戻す。
file_put_contents("ban_pos_data",$ban_pos_data);
return;
}
function conversion($before){//1を001へ、10を010へ変換。
//mb_strlen を使って文字列の文字数を取得。
//文字列"001"は数値にすると1に勝手に変わる。
$box = strval($before);
//echo $box;
$nofstr = mb_strlen($box);
if ($nofstr == 1){
$after = substr_replace($box,"00",0,0);
}else if($nofstr == 2){
$after = substr_replace($box,"0",0,0);
}else if($nofstr == 3){
$after = $box;
}
return $after;
}
function monitor_get(){
if($_GET==true){
$test1 = $_GET["fx-axis"];
$test2 = $_GET["fy-axis"];
$test3 = $_GET["tx-axis"];
$test4 = $_GET["ty-axis"];
echo $test1;
echo $test2;
echo $test3;
echo $test4;
}
return;
}
/*PHP では、グローバル変数は、関数の内部で使用する場合、関数の内部でグローバルとして宣言する必要があります。global $koma_positionのことです。*/
function ban_position($x,$y){
global $koma_position;
global $kind_koma;
return $kind_koma[$koma_position [$x][$y]];
}
function beginning_koma_pos(){
global $koma_position;
$n=1;
//y軸1
$koma_position [1][$n] =40;
$koma_position [2][$n] =41;
$koma_position [3][$n] =42;
$koma_position [4][$n] =43;
$koma_position [5][$n] =44;
$koma_position [6][$n] =45;
$koma_position [7][$n] =46;
$koma_position [8][$n] =47;
$koma_position [9][$n] =49;
$koma_position [10][$n] =50;
$koma_position [11][$n] =48;
$koma_position [12][$n] =47;
$koma_position [13][$n] =46;
$koma_position [14][$n] =45;
$koma_position [15][$n] =44;
$koma_position [16][$n] =43;
$koma_position [17][$n] =42;
$koma_position [18][$n] =41;
$koma_position [19][$n] =40;
$n++;
//y軸2
$koma_position [1][$n] =31;
$koma_position [2][$n] =0;
$koma_position [3][$n] =32;
$koma_position [4][$n] =0;
$koma_position [5][$n] =34;
$koma_position [6][$n] =0;
$koma_position [7][$n] =36;
$koma_position [8][$n] =37;
$koma_position [9][$n] =38;
$koma_position [10][$n] =39;
$koma_position [11][$n] =38;
$koma_position [12][$n] =37;
$koma_position [13][$n] =35;
$koma_position [14][$n] =0;
$koma_position [15][$n] =33;
$koma_position [16][$n] =0;
$koma_position [17][$n] =32;
$koma_position [18][$n] =0;
$koma_position [19][$n] =31;
$n++;
//y軸3
$koma_position [1][$n] =0;
$koma_position [2][$n] =24;
$koma_position [3][$n] =0;
$koma_position [4][$n] =25;
$koma_position [5][$n] =0;
$koma_position [6][$n] =26;
$koma_position [7][$n] =0;
$koma_position [8][$n] =27;
$koma_position [9][$n] =29;
$koma_position [10][$n] =30;
$koma_position [11][$n] =28;
$koma_position [12][$n] =27;
$koma_position [13][$n] =0;
$koma_position [14][$n] =26;
$koma_position [15][$n] =0;
$koma_position [16][$n] =25;
$koma_position [17][$n] =0;
$koma_position [18][$n] =24;
$koma_position [19][$n] =0;
$n++;
//y軸4
$koma_position [1][$n] =15;
$koma_position [2][$n] =0;
$koma_position [3][$n] =16;
$koma_position [4][$n] =0;
$koma_position [5][$n] =17;
$koma_position [6][$n] =0;
$koma_position [7][$n] =18;
$koma_position [8][$n] =20;
$koma_position [9][$n] =22;
$koma_position [10][$n] =23;
$koma_position [11][$n] =21;
$koma_position [12][$n] =19;
$koma_position [13][$n] =18;
$koma_position [14][$n] =0;
$koma_position [15][$n] =17;
$koma_position [16][$n] =0;
$koma_position [17][$n] =16;
$koma_position [18][$n] =0;
$koma_position [19][$n] =15;
$n++;
//y軸5
$koma_position [1][$n] =3;
$koma_position [2][$n] =5;
$koma_position [3][$n] =6;
$koma_position [4][$n] =7;
$koma_position [5][$n] =8;
$koma_position [6][$n] =9;
$koma_position [7][$n] =10;
$koma_position [8][$n] =11;
$koma_position [9][$n] =13;
$koma_position [10][$n] =14;
$koma_position [11][$n] =12;
$koma_position [12][$n] =11;
$koma_position [13][$n] =10;
$koma_position [14][$n] =9;
$koma_position [15][$n] =8;
$koma_position [16][$n] =7;
$koma_position [17][$n] =6;
$koma_position [18][$n] =4;
$koma_position [19][$n] =3;
$n++;
//y軸6
$koma_position [1][$n] =2;
$koma_position [2][$n] =2;
$koma_position [3][$n] =2;
$koma_position [4][$n] =2;
$koma_position [5][$n] =2;
$koma_position [6][$n] =2;
$koma_position [7][$n] =2;
$koma_position [8][$n] =2;
$koma_position [9][$n] =2;
$koma_position [10][$n] =2;
$koma_position [11][$n] =2;
$koma_position [12][$n] =2;
$koma_position [13][$n] =2;
$koma_position [14][$n] =2;
$koma_position [15][$n] =2;
$koma_position [16][$n] =2;
$koma_position [17][$n] =2;
$koma_position [18][$n] =2;
$koma_position [19][$n] =2;
$n++;
//y軸7
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =1;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =1;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸8
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =0;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =0;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸9
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =0;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =0;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸10
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =0;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =0;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸11
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =0;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =0;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸12
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =0;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =0;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸13
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =1;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =1;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸14
$koma_position [1][$n] =2;
$koma_position [2][$n] =2;
$koma_position [3][$n] =2;
$koma_position [4][$n] =2;
$koma_position [5][$n] =2;
$koma_position [6][$n] =2;
$koma_position [7][$n] =2;
$koma_position [8][$n] =2;
$koma_position [9][$n] =2;
$koma_position [10][$n] =2;
$koma_position [11][$n] =2;
$koma_position [12][$n] =2;
$koma_position [13][$n] =2;
$koma_position [14][$n] =2;
$koma_position [15][$n] =2;
$koma_position [16][$n] =2;
$koma_position [17][$n] =2;
$koma_position [18][$n] =2;
$koma_position [19][$n] =2;
$n++;
//y軸15
$koma_position [1][$n] =3;
$koma_position [2][$n] =4;
$koma_position [3][$n] =6;
$koma_position [4][$n] =7;
$koma_position [5][$n] =8;
$koma_position [6][$n] =9;
$koma_position [7][$n] =10;
$koma_position [8][$n] =11;
$koma_position [9][$n] =12;
$koma_position [10][$n] =14;
$koma_position [11][$n] =13;
$koma_position [12][$n] =11;
$koma_position [13][$n] =10;
$koma_position [14][$n] =9;
$koma_position [15][$n] =8;
$koma_position [16][$n] =7;
$koma_position [17][$n] =6;
$koma_position [18][$n] =5;
$koma_position [19][$n] =3;
$n++;
//y軸16
$koma_position [1][$n] =15;
$koma_position [2][$n] =0;
$koma_position [3][$n] =16;
$koma_position [4][$n] =0;
$koma_position [5][$n] =17;
$koma_position [6][$n] =0;
$koma_position [7][$n] =18;
$koma_position [8][$n] =19;
$koma_position [9][$n] =21;
$koma_position [10][$n] =23;
$koma_position [11][$n] =22;
$koma_position [12][$n] =20;
$koma_position [13][$n] =18;
$koma_position [14][$n] =0;
$koma_position [15][$n] =17;
$koma_position [16][$n] =0;
$koma_position [17][$n] =16;
$koma_position [18][$n] =0;
$koma_position [19][$n] =15;
$n++;
//y軸17
$koma_position [1][$n] =0;
$koma_position [2][$n] =24;
$koma_position [3][$n] =0;
$koma_position [4][$n] =25;
$koma_position [5][$n] =0;
$koma_position [6][$n] =26;
$koma_position [7][$n] =0;
$koma_position [8][$n] =27;
$koma_position [9][$n] =28;
$koma_position [10][$n] =30;
$koma_position [11][$n] =29;
$koma_position [12][$n] =27;
$koma_position [13][$n] =0;
$koma_position [14][$n] =26;
$koma_position [15][$n] =0;
$koma_position [16][$n] =25;
$koma_position [17][$n] =0;
$koma_position [18][$n] =24;
$koma_position [19][$n] =0;
$n++;
//y軸18
$koma_position [1][$n] =31;
$koma_position [2][$n] =0;
$koma_position [3][$n] =32;
$koma_position [4][$n] =0;
$koma_position [5][$n] =33;
$koma_position [6][$n] =0;
$koma_position [7][$n] =35;
$koma_position [8][$n] =37;
$koma_position [9][$n] =38;
$koma_position [10][$n] =39;
$koma_position [11][$n] =38;
$koma_position [12][$n] =37;
$koma_position [13][$n] =36;
$koma_position [14][$n] =0;
$koma_position [15][$n] =34;
$koma_position [16][$n] =0;
$koma_position [17][$n] =32;
$koma_position [18][$n] =0;
$koma_position [19][$n] =31;
$n++;
//y軸19
$koma_position [1][$n] =40;
$koma_position [2][$n] =41;
$koma_position [3][$n] =42;
$koma_position [4][$n] =43;
$koma_position [5][$n] =44;
$koma_position [6][$n] =45;
$koma_position [7][$n] =46;
$koma_position [8][$n] =47;
$koma_position [9][$n] =48;
$koma_position [10][$n] =50;
$koma_position [11][$n] =49;
$koma_position [12][$n] =47;
$koma_position [13][$n] =46;
$koma_position [14][$n] =45;
$koma_position [15][$n] =44;
$koma_position [16][$n] =43;
$koma_position [17][$n] =42;
$koma_position [18][$n] =41;
$koma_position [19][$n] =40;
return;
}
function init_table_koma(){
global $kind_koma;
$n = 200;
$kind_koma = array (
//先手の駒。
0=>"  ",
1=>"仲人",
2=>"歩兵",
3=>"飛車",
4=>"左車",
5=>"右車",
6=>"横行",
7=>"横飛",
8=>"堅行",
9=>"角行",
10=>"龍馬",
11=>"龍王",
12=>"摩羯",
13=>"鉤行",
14=>"奔王",
15=>"驢馬",
16=>"桂馬",
17=>"猛牛",
18=>"飛龍",
19=>"羅刹",
20=>"夜叉",
21=>"力士",
22=>"金剛",
23=>"狛犬",
24=>"老鼠",
25=>"嗔猪",
26=>"盲熊",
27=>"悪狼",
28=>"麒麟",
29=>"鳳凰",
30=>"師子",
31=>"反車",
32=>"猫叉",
33=>"淮鶏",
34=>"古猿",
35=>"蟠蛇",
36=>"臥龍",
37=>"猛豹",
38=>"盲虎",
39=>"醉象",
40=>"香車",
41=>"土将",
42=>"石将",
43=>"瓦将",
44=>"鉄将",
45=>"銅将",
46=>"銀将",
47=>"金将",
48=>"提婆",
49=>"無明",
50=>"玉将",
100=>"駒なし",
101=>"奔人",
102=>"金",
103=>"金",
104=>"金",
105=>"金",
106=>"金",
107=>"金",
108=>"金",
109=>"金",
110=>"成らず",
111=>"成らず",
112=>"金",
113=>"金",
114=>"成らず",
115=>"金",
116=>"金",
117=>"金",
118=>"金",
119=>"金",
120=>"金",
121=>"金",
122=>"金",
123=>"金",
124=>"蝙蝠",
125=>"奔猪",
126=>"奔熊",
127=>"奔狼",
128=>"師子",
129=>"奔王",
130=>"成らず",
131=>"金",
132=>"奔猫",
133=>"仙鶴",
134=>"山母",
135=>"奔蛇",
136=>"奔龍",
137=>"奔豹",
138=>"奔虎",
139=>"王子",
140=>"金",
141=>"奔土",
142=>"奔石",
143=>"奔瓦",
144=>"奔鉄",
145=>"奔銅",
146=>"奔銀",
147=>"奔金",
148=>"教王",
149=>"法性",
150=>"自在王",
//ここから以下が後手の駒。
//0=>"駒なし",
1+$n=>"仲人",
2+$n=>"歩兵",
3+$n=>"飛車",
4+$n=>"左車",
5+$n=>"右車",
6+$n=>"横行",
7+$n=>"横飛",
8+$n=>"堅行",
9+$n=>"角行",
10+$n=>"龍馬",
11+$n=>"龍王",
12+$n=>"摩羯",
13+$n=>"鉤行",
14+$n=>"奔王",
15+$n=>"驢馬",
16+$n=>"桂馬",
17+$n=>"猛牛",
18+$n=>"飛龍",
19+$n=>"羅刹",
20+$n=>"夜叉",
21+$n=>"力士",
22+$n=>"金剛",
23+$n=>"狛犬",
24+$n=>"老鼠",
25+$n=>"嗔猪",
26+$n=>"盲熊",
27+$n=>"悪狼",
28+$n=>"麒麟",
29+$n=>"鳳凰",
30+$n=>"師子",
31+$n=>"反車",
32+$n=>"猫叉",
33+$n=>"淮鶏",
34+$n=>"古猿",
35+$n=>"蟠蛇",
36+$n=>"臥龍",
37+$n=>"猛豹",
38+$n=>"盲虎",
39+$n=>"醉象",
40+$n=>"香車",
41+$n=>"土将",
42+$n=>"石将",
43+$n=>"瓦将",
44+$n=>"鉄将",
45+$n=>"銅将",
46+$n=>"銀将",
47+$n=>"金将",
48+$n=>"提婆",
49+$n=>"無明",
50+$n=>"玉将",
100+$n=>"  ",
101+$n=>"奔人",
102+$n=>"金",
103+$n=>"金",
104+$n=>"金",
105+$n=>"金",
106+$n=>"金",
107+$n=>"金",
108+$n=>"金",
109+$n=>"金",
110+$n=>"成らず",
111+$n=>"成らず",
112+$n=>"金",
113+$n=>"金",
114+$n=>"成らず",
115+$n=>"金",
116+$n=>"金",
117+$n=>"金",
118+$n=>"金",
119+$n=>"金",
120+$n=>"金",
121+$n=>"金",
122+$n=>"金",
123+$n=>"金",
124+$n=>"蝙蝠",
125+$n=>"奔猪",
126+$n=>"奔熊",
127+$n=>"奔狼",
128+$n=>"師子",
129+$n=>"奔王",
130+$n=>"成らず",
131+$n=>"金",
132+$n=>"奔猫",
133+$n=>"仙鶴",
134+$n=>"山母",
135+$n=>"奔蛇",
136+$n=>"奔龍",
137+$n=>"奔豹",
138+$n=>"奔虎",
139+$n=>"王子",
140+$n=>"金",
141+$n=>"奔土",
142+$n=>"奔石",
143+$n=>"奔瓦",
144+$n=>"奔鉄",
145+$n=>"奔銅",
146+$n=>"奔銀",
147+$n=>"奔金",
148+$n=>"教王",
149+$n=>"法性",
150+$n=>"自在王",
);
return;
}
?>
<!DOCTYPE html>
<html lang = "ja">
<?php
include 'functions.php';
$koma_position = array ();/*phpだとこの書き方で全部いけるらしい。*/
$kind_koma = array ();
init_table_koma();//駒とそれに対応する番号などを初期化。
get_koma_position();
//beginning_koma_pos();//駒の初期位置。
$increment_y = 1;
?>
<head>
<meta charset = "UTF-8">
<title>民主主義摩訶大大将棋.php</title>
</head>
<body>
<h1>民主主義摩訶大大将棋</h1>
<div id="container1">
<table border ="1">
<?php for($yaxis=0;$yaxis<=19;$yaxis++){ ?>
<tr>
<?php for($xaxis=0;$xaxis<=19;$xaxis++){ ?>
<?php if($xaxis!=0 && $yaxis!=0){ ?>
<td>
<?php echo ban_position($xaxis,$yaxis); ?>
</td>
<?php }else{ ?>
<td>
<?php
if ($yaxis==0 && $xaxis==0){
echo "y/x";
}else if($yaxis==0){
echo $xaxis;
}else if ($xaxis==0){
echo $yaxis;
}
?>
</td>
<?php } ?>
<?php } ?>
</tr>
<?php } ?>
</table>
</div>
<h1>vote a movement</h1>
<div id="container2">
<form name="voteform" id="votemovement" action="move_koma.php" method="get" enctype="application/x-www-form-urlencoded">
<label for="votemovement">FROM:X-axis</label>
<select name="fx-axis" form="votemovement">
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
<option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>
<option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
<option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option>
</select>
<label for="votemovement">Y-axis</label>
<select name="fy-axis" form="votemovement">
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
<option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>
<option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
<option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option>
</select>
<label for="votemovement">TO:X-axis</label>
<select name="tx-axis" form="votemovement">
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
<option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>
<option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
<option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option>
</select>
<label for="votemovement">Y-axis</label>
<select name="ty-axis" form="votemovement">
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
<option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>
<option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
<option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option>
</select>
<input name="voteinput" formaction="vote.php" type="submit" form="votemovement" formmethod="get" value="投票する">
<input name="moveinput" formaction="move_koma.php" type="submit" form="votemovement" formmethod="get" value="駒を動かす">
</form>
</div>
<h1>これまでの投票</h1>
<article>
<p>
<?php show_votes(); ?>
</p>
</article>
<footer>
<?php
//monitor_get();
// echo $ban_pos_data[0];
//echo $koma_position[3][2];
?>
</footer>
</body>
</html>
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
先手が0~150後手が200~350
100足すと成る
先手の駒に200足すと後手の駒
0駒なし
1仲人
2歩兵
3飛車
4左車
5右車
6横行
7横飛
8堅行
9角行
10龍馬
11龍王
12摩羯
13鉤行
14奔王
15驢馬
16桂馬
17猛牛
18飛龍
19羅刹
20夜叉
21力士
22金剛
23狛犬
24老鼠
25嗔猪
26盲熊
27悪狼
28麒麟
29鳳凰
30師子
31反車
32猫叉
33淮鶏
34古猿
35蟠蛇
36臥龍
37猛豹
38盲虎
39醉象
40香車
41土将
42石将
43瓦将
44鉄将
45銅将
46銀将
47金将
48提婆
49無明
50玉将
100駒なし
101奔人
102金
103金
104金
105金
106金
107金
108金
109金
110成らず
111成らず
112金
113金
114成らず
115金
116金
117金
118金
119金
120金
121金
122金
123金
124蝙蝠
125奔猪
126奔熊
127奔狼
128師子
129奔王
130成らず
131金
132奔猫
133仙鶴
134山母
135奔蛇
136奔龍
137奔豹
138奔虎
139王子
140金
141奔土
142奔石
143奔瓦
144奔鉄
145奔銅
146奔銀
147奔金
148教王
149法性
150自在王
<!DOCTYPE html>
<html lang = "ja">
<?php
include 'functions.php';
$koma_position = array ();/*phpだとこの書き方で全部いけるらしい。*/
$kind_koma = array ();
init_table_koma();//駒とそれに対応する番号などを初期化。
get_koma_position();
//beginning_koma_pos();//駒の初期位置。
$increment_y = 1;
?>
<head>
<meta charset = "UTF-8">
<title>民主主義摩訶大大将棋.php</title>
</head>
<body>
<?php
move_koma();
/*
echo $koma_position[1][14];
monitor_get();
print $ban_pos_data[13];
*/
?>
<a href="index.php">戻る。</a>
</body>
</html>
駒を動かす仕組みはできた。
投票を受け付ける、仕組みを次は作る。
投票ボタンの中は
$fx $fy $tx $ty
1 14 1 13
この1.14.1.13を文字列にして変数に入れる。
投票番号 という配列を作る。
投票番号[0] = 1.14.1.13
投票番号[1] = 2.14.2.13
投票番号[2] = 1.14.1.13
同じ投票があれば、その数を変数人気に入れる。
echo "1.14.1.13"
echo 人気
人気の多い投票順に上から並べる。
1
2
1
3
2
1
155
224
333
442
511
2245
1554
3333
4422
5111
<!DOCTYPE html>
<html lang = "ja">
<?php
include 'functions.php';
?>
<head>
<meta charset = "UTF-8">
<title>民主主義摩訶大大将棋.php</title>
</head>
<body>
<div>
<a href="index.php">戻る。</a>
</div>
<?php
$fx = $_GET["fx-axis"];
$fy = $_GET["fy-axis"];
$tx = $_GET["tx-axis"];
$ty = $_GET["ty-axis"];
$fx_str=strval($fx);
$fy_str=strval($fy);
$tx_str=strval($tx);
$ty_str=strval($ty);
$vote = "a";
$vote = substr_replace($vote,"\n",0,1);//aを置換。
$vote = substr_replace($vote,$ty_str,0,0);//先頭に。
$vote = substr_replace($vote,".",0,0);//先頭にピリオド。
$vote = substr_replace($vote,$tx_str,0,0);//先頭に。
$vote = substr_replace($vote,".",0,0);//先頭にピリオド。
$vote = substr_replace($vote,$fy_str,0,0);//先頭に。
$vote = substr_replace($vote,".",0,0);//先頭にピリオド。
$vote = substr_replace($vote,$fx_str,0,0);//先頭に。
//echo $vote;
$times_vote = file_get_contents("投票ボタンが押された回数");
$int_times_vote = intval($times_vote);
if($int_times_vote!=0){
$vote_sofar = file_get_contents("投票内容");
$box = "a";
$box = substr_replace($box,$vote,0,1);//先頭に。
$box = substr_replace($box,$vote_sofar,0,0);//先頭に。
file_put_contents("投票内容",$box);
file_put_contents("投票ボタンが押された回数",$int_times_vote + 1);
}else if($int_times_vote==0){
file_put_contents("投票内容",$vote);
file_put_contents("投票ボタンが押された回数","1");
}
/*
echo "これまでの投票";
$vote_sofar = file("投票内容");
$number=0;
for ($x=0 ; $x<$int_times_vote+1 ; $x++){
echo $vote_sofar[$x].'/';
}
*/
show_votes();
?>
</body>
</html>
18
3.19.8.13
2.19.8.13
3.19.8.13
3.19.8.13
3.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.7.13
2.19.7.13
240.241.242.243.244.245.246.247.249.250.248.247.246.245.244.243.242.241.240\n
231.000.232.000.234.000.236.237.238.239.238.237.235.000.233.000.232.000.231\n
000.224.000.225.000.226.000.227.229.230.228.227.000.226.000.225.000.224.000\n
215.000.216.000.217.000.218.220.222.223.221.219.218.000.217.000.216.000.215\n
203.205.206.207.208.209.210.211.213.214.212.211.210.209.208.207.206.204.203\n
202.202.202.202.202.202.202.202.202.202.202.202.202.202.202.202.202.202.202\n
000.000.000.000.000.001.000.000.000.000.000.000.000.001.000.000.000.000.000\n
000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000\n
000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000\n
000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000\n
000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000\n
000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000\n
000.000.000.000.000.001.000.000.000.000.000.000.000.001.000.000.000.000.000\n
002.002.002.002.002.002.002.002.002.002.002.002.002.002.002.002.002.002.002\n
003.004.006.007.008.009.010.011.012.014.013.011.010.009.008.007.006.005.003\n
015.000.016.000.017.000.018.019.021.023.022.020.018.000.017.000.016.000.015\n
000.024.000.025.000.026.000.027.028.030.029.027.000.026.000.025.000.024.000\n
031.000.032.000.033.000.035.037.038.039.038.037.036.000.034.000.032.000.031\n
040.041.042.043.044.045.046.047.048.050.049.047.046.045.044.043.042.041.040\n
<?php
/*関数の宣言*/
function show_votes(){
//数えたい。
$vote_sofar = file("投票内容");
$times_vote = file_get_contents("投票ボタンが押された回数");
$int_times_vote = intval($times_vote);
$vote_sofar_num = array();
$maximum=0;
for ($b=0 ; $b<$int_times_vote ; $b++){
$number=0;
$flag=0;
if($b!=0){
for ($c=$b-1 ; $c>=0 ; $c--){//前に重複があるならスキップして次のループへ。
if($vote_sofar[$c] == $vote_sofar[$b]){
$flag=1;
}
}
}
if($flag == 1){
$vote_sofar_num[$b] = -1;
continue;
}
for ($a=0 ; $a<$int_times_vote ; $a++){//以降に重複があればnumberをインクリメント。
if($vote_sofar[$b]==$vote_sofar[$a]){
$number++;
}
}
$vote_sofar_num[$b] = $number;
//echo $vote_sofar_num[$b];
}
$dd = 0;
for ($b=0 ; $b<$int_times_vote ; $b++){
$found_max = 0;
if($vote_sofar_num[$b] > 0){
for ($d=$b+1 ; $d<$int_times_vote ; $d++){//マキシマムを求める。
$pos_max=$b;
if($vote_sofar_num[$b] < $vote_sofar_num[$d]){
$maximum = $vote_sofar_num[$d];
$pos_max=$d;
$found_max = 1; //見つけた。
}
}
//求めたマキシマムと最上の値を交換。
if ($found_max = 1){
$vote_sofar_num[$pos_max] = $vote_sofar_num[$b];
$vote_sofar_num[$b] = $maximum;
$swap = $vote_sofar[$pos_max];
$vote_sofar[$pos_max] = $vote_sofar[$b];
$vote_sofar[$b] = $swap;
}
}
}
for($b=0 ; $b<$int_times_vote ; $b++){
if($vote_sofar_num[$b] > 0){
echo $vote_sofar[$b];
echo ":";
echo $vote_sofar_num[$b];
echo "回\n";
}
}
return;
}
function get_koma_position(){//テキストデータから駒の配置を得る。
global $ban_pos_data;
global $koma_position;
$ban_pos_data=file("ban_pos_data");
for($y=1;$y<=19;$y++){
for($x=1;$x<=19;$x++){
$koma_position[$x][$y] = substr($ban_pos_data[$y-1],4*($x-1),3);
$backup = $koma_position[$x][$y];
$head1 = substr($backup,0,1);
$head2 = substr($backup,0,2);
if ($head1 == 0 && $head2 == 00){
strval($backup);
$box = substr_replace($backup,"",0,2);
intval($box);
$koma_position[$x][$y] = $box;
}else if($head1 == 0 && $head2 != 00){
strval($backup);
$box = substr_replace($backup,"",0,1);
intval($box);
$koma_position[$x][$y] = $box;
}
//$koma_position[$x][$y]の中は最初は001だけどここで1に変換してる
//ようするに最終的には$koma_position[$x][$y]の中身は1であり001か010ではない。
}
}
return;
}
function move_koma(){//0 を000に変換してない。
global $koma_position;
global $ban_pos_data;
chmod("ban_pos_data",0666);
$fx = $_GET["fx-axis"];
$fy = $_GET["fy-axis"];
$tx = $_GET["tx-axis"];
$ty = $_GET["ty-axis"];
$ban_pos_data=file("ban_pos_data");
$dox = $koma_position[$fx][$fy];//1を001へ、10を010へ変換が必要。この時点で文字列。
$dox = conversion($dox);//変換。まだ文字列001。
//echo "test";
//echo $dox;
//strval($dox);
$box = $ban_pos_data[$ty-1];//000.000.000移動先のy列。注$tyに-1を付ける。
//echo $box;
//strval($box);
$box = substr_replace($box,$dox,($tx-1)*4,3);//移動先へ書き込む。
//echo $box;
$ban_pos_data[$ty-1] = $box;//取り出した列へ戻す。
//echo $ban_pos_data[$ty-1];
$box = $ban_pos_data[$fy-1];//000.000.000移動元のy列。
$box = substr_replace($box,"000",($fx-1)*4,3);//移動元を消す。
//echo $box;
$ban_pos_data[$fy-1] = $box;//取り出した列へ戻す。
file_put_contents("ban_pos_data",$ban_pos_data);
return;
}
function conversion($before){//1を001へ、10を010へ変換。
//mb_strlen を使って文字列の文字数を取得。
//文字列"001"は数値にすると1に勝手に変わる。
$box = strval($before);
//echo $box;
$nofstr = mb_strlen($box);
if ($nofstr == 1){
$after = substr_replace($box,"00",0,0);
}else if($nofstr == 2){
$after = substr_replace($box,"0",0,0);
}else if($nofstr == 3){
$after = $box;
}
return $after;
}
function monitor_get(){
if($_GET==true){
$test1 = $_GET["fx-axis"];
$test2 = $_GET["fy-axis"];
$test3 = $_GET["tx-axis"];
$test4 = $_GET["ty-axis"];
echo $test1;
echo $test2;
echo $test3;
echo $test4;
}
return;
}
/*PHP では、グローバル変数は、関数の内部で使用する場合、関数の内部でグローバルとして宣言する必要があります。global $koma_positionのことです。*/
function ban_position($x,$y){
global $koma_position;
global $kind_koma;
return $kind_koma[$koma_position [$x][$y]];
}
function beginning_koma_pos(){
global $koma_position;
$n=1;
//y軸1
$koma_position [1][$n] =40;
$koma_position [2][$n] =41;
$koma_position [3][$n] =42;
$koma_position [4][$n] =43;
$koma_position [5][$n] =44;
$koma_position [6][$n] =45;
$koma_position [7][$n] =46;
$koma_position [8][$n] =47;
$koma_position [9][$n] =49;
$koma_position [10][$n] =50;
$koma_position [11][$n] =48;
$koma_position [12][$n] =47;
$koma_position [13][$n] =46;
$koma_position [14][$n] =45;
$koma_position [15][$n] =44;
$koma_position [16][$n] =43;
$koma_position [17][$n] =42;
$koma_position [18][$n] =41;
$koma_position [19][$n] =40;
$n++;
//y軸2
$koma_position [1][$n] =31;
$koma_position [2][$n] =0;
$koma_position [3][$n] =32;
$koma_position [4][$n] =0;
$koma_position [5][$n] =34;
$koma_position [6][$n] =0;
$koma_position [7][$n] =36;
$koma_position [8][$n] =37;
$koma_position [9][$n] =38;
$koma_position [10][$n] =39;
$koma_position [11][$n] =38;
$koma_position [12][$n] =37;
$koma_position [13][$n] =35;
$koma_position [14][$n] =0;
$koma_position [15][$n] =33;
$koma_position [16][$n] =0;
$koma_position [17][$n] =32;
$koma_position [18][$n] =0;
$koma_position [19][$n] =31;
$n++;
//y軸3
$koma_position [1][$n] =0;
$koma_position [2][$n] =24;
$koma_position [3][$n] =0;
$koma_position [4][$n] =25;
$koma_position [5][$n] =0;
$koma_position [6][$n] =26;
$koma_position [7][$n] =0;
$koma_position [8][$n] =27;
$koma_position [9][$n] =29;
$koma_position [10][$n] =30;
$koma_position [11][$n] =28;
$koma_position [12][$n] =27;
$koma_position [13][$n] =0;
$koma_position [14][$n] =26;
$koma_position [15][$n] =0;
$koma_position [16][$n] =25;
$koma_position [17][$n] =0;
$koma_position [18][$n] =24;
$koma_position [19][$n] =0;
$n++;
//y軸4
$koma_position [1][$n] =15;
$koma_position [2][$n] =0;
$koma_position [3][$n] =16;
$koma_position [4][$n] =0;
$koma_position [5][$n] =17;
$koma_position [6][$n] =0;
$koma_position [7][$n] =18;
$koma_position [8][$n] =20;
$koma_position [9][$n] =22;
$koma_position [10][$n] =23;
$koma_position [11][$n] =21;
$koma_position [12][$n] =19;
$koma_position [13][$n] =18;
$koma_position [14][$n] =0;
$koma_position [15][$n] =17;
$koma_position [16][$n] =0;
$koma_position [17][$n] =16;
$koma_position [18][$n] =0;
$koma_position [19][$n] =15;
$n++;
//y軸5
$koma_position [1][$n] =3;
$koma_position [2][$n] =5;
$koma_position [3][$n] =6;
$koma_position [4][$n] =7;
$koma_position [5][$n] =8;
$koma_position [6][$n] =9;
$koma_position [7][$n] =10;
$koma_position [8][$n] =11;
$koma_position [9][$n] =13;
$koma_position [10][$n] =14;
$koma_position [11][$n] =12;
$koma_position [12][$n] =11;
$koma_position [13][$n] =10;
$koma_position [14][$n] =9;
$koma_position [15][$n] =8;
$koma_position [16][$n] =7;
$koma_position [17][$n] =6;
$koma_position [18][$n] =4;
$koma_position [19][$n] =3;
$n++;
//y軸6
$koma_position [1][$n] =2;
$koma_position [2][$n] =2;
$koma_position [3][$n] =2;
$koma_position [4][$n] =2;
$koma_position [5][$n] =2;
$koma_position [6][$n] =2;
$koma_position [7][$n] =2;
$koma_position [8][$n] =2;
$koma_position [9][$n] =2;
$koma_position [10][$n] =2;
$koma_position [11][$n] =2;
$koma_position [12][$n] =2;
$koma_position [13][$n] =2;
$koma_position [14][$n] =2;
$koma_position [15][$n] =2;
$koma_position [16][$n] =2;
$koma_position [17][$n] =2;
$koma_position [18][$n] =2;
$koma_position [19][$n] =2;
$n++;
//y軸7
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =1;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =1;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸8
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =0;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =0;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸9
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =0;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =0;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸10
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =0;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =0;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸11
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =0;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =0;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸12
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =0;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =0;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸13
$koma_position [1][$n] =0;
$koma_position [2][$n] =0;
$koma_position [3][$n] =0;
$koma_position [4][$n] =0;
$koma_position [5][$n] =0;
$koma_position [6][$n] =1;
$koma_position [7][$n] =0;
$koma_position [8][$n] =0;
$koma_position [9][$n] =0;
$koma_position [10][$n] =0;
$koma_position [11][$n] =0;
$koma_position [12][$n] =0;
$koma_position [13][$n] =0;
$koma_position [14][$n] =1;
$koma_position [15][$n] =0;
$koma_position [16][$n] =0;
$koma_position [17][$n] =0;
$koma_position [18][$n] =0;
$koma_position [19][$n] =0;
$n++;
//y軸14
$koma_position [1][$n] =2;
$koma_position [2][$n] =2;
$koma_position [3][$n] =2;
$koma_position [4][$n] =2;
$koma_position [5][$n] =2;
$koma_position [6][$n] =2;
$koma_position [7][$n] =2;
$koma_position [8][$n] =2;
$koma_position [9][$n] =2;
$koma_position [10][$n] =2;
$koma_position [11][$n] =2;
$koma_position [12][$n] =2;
$koma_position [13][$n] =2;
$koma_position [14][$n] =2;
$koma_position [15][$n] =2;
$koma_position [16][$n] =2;
$koma_position [17][$n] =2;
$koma_position [18][$n] =2;
$koma_position [19][$n] =2;
$n++;
//y軸15
$koma_position [1][$n] =3;
$koma_position [2][$n] =4;
$koma_position [3][$n] =6;
$koma_position [4][$n] =7;
$koma_position [5][$n] =8;
$koma_position [6][$n] =9;
$koma_position [7][$n] =10;
$koma_position [8][$n] =11;
$koma_position [9][$n] =12;
$koma_position [10][$n] =14;
$koma_position [11][$n] =13;
$koma_position [12][$n] =11;
$koma_position [13][$n] =10;
$koma_position [14][$n] =9;
$koma_position [15][$n] =8;
$koma_position [16][$n] =7;
$koma_position [17][$n] =6;
$koma_position [18][$n] =5;
$koma_position [19][$n] =3;
$n++;
//y軸16
$koma_position [1][$n] =15;
$koma_position [2][$n] =0;
$koma_position [3][$n] =16;
$koma_position [4][$n] =0;
$koma_position [5][$n] =17;
$koma_position [6][$n] =0;
$koma_position [7][$n] =18;
$koma_position [8][$n] =19;
$koma_position [9][$n] =21;
$koma_position [10][$n] =23;
$koma_position [11][$n] =22;
$koma_position [12][$n] =20;
$koma_position [13][$n] =18;
$koma_position [14][$n] =0;
$koma_position [15][$n] =17;
$koma_position [16][$n] =0;
$koma_position [17][$n] =16;
$koma_position [18][$n] =0;
$koma_position [19][$n] =15;
$n++;
//y軸17
$koma_position [1][$n] =0;
$koma_position [2][$n] =24;
$koma_position [3][$n] =0;
$koma_position [4][$n] =25;
$koma_position [5][$n] =0;
$koma_position [6][$n] =26;
$koma_position [7][$n] =0;
$koma_position [8][$n] =27;
$koma_position [9][$n] =28;
$koma_position [10][$n] =30;
$koma_position [11][$n] =29;
$koma_position [12][$n] =27;
$koma_position [13][$n] =0;
$koma_position [14][$n] =26;
$koma_position [15][$n] =0;
$koma_position [16][$n] =25;
$koma_position [17][$n] =0;
$koma_position [18][$n] =24;
$koma_position [19][$n] =0;
$n++;
//y軸18
$koma_position [1][$n] =31;
$koma_position [2][$n] =0;
$koma_position [3][$n] =32;
$koma_position [4][$n] =0;
$koma_position [5][$n] =33;
$koma_position [6][$n] =0;
$koma_position [7][$n] =35;
$koma_position [8][$n] =37;
$koma_position [9][$n] =38;
$koma_position [10][$n] =39;
$koma_position [11][$n] =38;
$koma_position [12][$n] =37;
$koma_position [13][$n] =36;
$koma_position [14][$n] =0;
$koma_position [15][$n] =34;
$koma_position [16][$n] =0;
$koma_position [17][$n] =32;
$koma_position [18][$n] =0;
$koma_position [19][$n] =31;
$n++;
//y軸19
$koma_position [1][$n] =40;
$koma_position [2][$n] =41;
$koma_position [3][$n] =42;
$koma_position [4][$n] =43;
$koma_position [5][$n] =44;
$koma_position [6][$n] =45;
$koma_position [7][$n] =46;
$koma_position [8][$n] =47;
$koma_position [9][$n] =48;
$koma_position [10][$n] =50;
$koma_position [11][$n] =49;
$koma_position [12][$n] =47;
$koma_position [13][$n] =46;
$koma_position [14][$n] =45;
$koma_position [15][$n] =44;
$koma_position [16][$n] =43;
$koma_position [17][$n] =42;
$koma_position [18][$n] =41;
$koma_position [19][$n] =40;
return;
}
function init_table_koma(){
global $kind_koma;
$n = 200;
$kind_koma = array (
//先手の駒。
0=>"  ",
1=>"仲人",
2=>"歩兵",
3=>"飛車",
4=>"左車",
5=>"右車",
6=>"横行",
7=>"横飛",
8=>"堅行",
9=>"角行",
10=>"龍馬",
11=>"龍王",
12=>"摩羯",
13=>"鉤行",
14=>"奔王",
15=>"驢馬",
16=>"桂馬",
17=>"猛牛",
18=>"飛龍",
19=>"羅刹",
20=>"夜叉",
21=>"力士",
22=>"金剛",
23=>"狛犬",
24=>"老鼠",
25=>"嗔猪",
26=>"盲熊",
27=>"悪狼",
28=>"麒麟",
29=>"鳳凰",
30=>"師子",
31=>"反車",
32=>"猫叉",
33=>"淮鶏",
34=>"古猿",
35=>"蟠蛇",
36=>"臥龍",
37=>"猛豹",
38=>"盲虎",
39=>"醉象",
40=>"香車",
41=>"土将",
42=>"石将",
43=>"瓦将",
44=>"鉄将",
45=>"銅将",
46=>"銀将",
47=>"金将",
48=>"提婆",
49=>"無明",
50=>"玉将",
100=>"駒なし",
101=>"奔人",
102=>"金",
103=>"金",
104=>"金",
105=>"金",
106=>"金",
107=>"金",
108=>"金",
109=>"金",
110=>"成らず",
111=>"成らず",
112=>"金",
113=>"金",
114=>"成らず",
115=>"金",
116=>"金",
117=>"金",
118=>"金",
119=>"金",
120=>"金",
121=>"金",
122=>"金",
123=>"金",
124=>"蝙蝠",
125=>"奔猪",
126=>"奔熊",
127=>"奔狼",
128=>"師子",
129=>"奔王",
130=>"成らず",
131=>"金",
132=>"奔猫",
133=>"仙鶴",
134=>"山母",
135=>"奔蛇",
136=>"奔龍",
137=>"奔豹",
138=>"奔虎",
139=>"王子",
140=>"金",
141=>"奔土",
142=>"奔石",
143=>"奔瓦",
144=>"奔鉄",
145=>"奔銅",
146=>"奔銀",
147=>"奔金",
148=>"教王",
149=>"法性",
150=>"自在王",
//ここから以下が後手の駒。
//0=>"駒なし",
1+$n=>"仲人",
2+$n=>"歩兵",
3+$n=>"飛車",
4+$n=>"左車",
5+$n=>"右車",
6+$n=>"横行",
7+$n=>"横飛",
8+$n=>"堅行",
9+$n=>"角行",
10+$n=>"龍馬",
11+$n=>"龍王",
12+$n=>"摩羯",
13+$n=>"鉤行",
14+$n=>"奔王",
15+$n=>"驢馬",
16+$n=>"桂馬",
17+$n=>"猛牛",
18+$n=>"飛龍",
19+$n=>"羅刹",
20+$n=>"夜叉",
21+$n=>"力士",
22+$n=>"金剛",
23+$n=>"狛犬",
24+$n=>"老鼠",
25+$n=>"嗔猪",
26+$n=>"盲熊",
27+$n=>"悪狼",
28+$n=>"麒麟",
29+$n=>"鳳凰",
30+$n=>"師子",
31+$n=>"反車",
32+$n=>"猫叉",
33+$n=>"淮鶏",
34+$n=>"古猿",
35+$n=>"蟠蛇",
36+$n=>"臥龍",
37+$n=>"猛豹",
38+$n=>"盲虎",
39+$n=>"醉象",
40+$n=>"香車",
41+$n=>"土将",
42+$n=>"石将",
43+$n=>"瓦将",
44+$n=>"鉄将",
45+$n=>"銅将",
46+$n=>"銀将",
47+$n=>"金将",
48+$n=>"提婆",
49+$n=>"無明",
50+$n=>"玉将",
100+$n=>"  ",
101+$n=>"奔人",
102+$n=>"金",
103+$n=>"金",
104+$n=>"金",
105+$n=>"金",
106+$n=>"金",
107+$n=>"金",
108+$n=>"金",
109+$n=>"金",
110+$n=>"成らず",
111+$n=>"成らず",
112+$n=>"金",
113+$n=>"金",
114+$n=>"成らず",
115+$n=>"金",
116+$n=>"金",
117+$n=>"金",
118+$n=>"金",
119+$n=>"金",
120+$n=>"金",
121+$n=>"金",
122+$n=>"金",
123+$n=>"金",
124+$n=>"蝙蝠",
125+$n=>"奔猪",
126+$n=>"奔熊",
127+$n=>"奔狼",
128+$n=>"師子",
129+$n=>"奔王",
130+$n=>"成らず",
131+$n=>"金",
132+$n=>"奔猫",
133+$n=>"仙鶴",
134+$n=>"山母",
135+$n=>"奔蛇",
136+$n=>"奔龍",
137+$n=>"奔豹",
138+$n=>"奔虎",
139+$n=>"王子",
140+$n=>"金",
141+$n=>"奔土",
142+$n=>"奔石",
143+$n=>"奔瓦",
144+$n=>"奔鉄",
145+$n=>"奔銅",
146+$n=>"奔銀",
147+$n=>"奔金",
148+$n=>"教王",
149+$n=>"法性",
150+$n=>"自在王",
);
return;
}
?>
<!DOCTYPE html>
<html lang = "ja">
<?php
include 'functions.php';
$koma_position = array ();/*phpだとこの書き方で全部いけるらしい。*/
$kind_koma = array ();
init_table_koma();//駒とそれに対応する番号などを初期化。
get_koma_position();
//beginning_koma_pos();//駒の初期位置。
$increment_y = 1;
?>
<head>
<meta charset = "UTF-8">
<title>民主主義摩訶大大将棋.php</title>
</head>
<body>
<h1>民主主義摩訶大大将棋</h1>
<div id="container1">
<table border ="1">
<?php for($yaxis=0;$yaxis<=19;$yaxis++){ ?>
<tr>
<?php for($xaxis=0;$xaxis<=19;$xaxis++){ ?>
<?php if($xaxis!=0 && $yaxis!=0){ ?>
<td>
<?php echo ban_position($xaxis,$yaxis); ?>
</td>
<?php }else{ ?>
<td>
<?php
if ($yaxis==0 && $xaxis==0){
echo "y/x";
}else if($yaxis==0){
echo $xaxis;
}else if ($xaxis==0){
echo $yaxis;
}
?>
</td>
<?php } ?>
<?php } ?>
</tr>
<?php } ?>
</table>
</div>
<h1>vote a movement</h1>
<div id="container2">
<form name="voteform" id="votemovement" action="move_koma.php" method="get" enctype="application/x-www-form-urlencoded">
<label for="votemovement">FROM:X-axis</label>
<select name="fx-axis" form="votemovement">
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
<option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>
<option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
<option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option>
</select>
<label for="votemovement">Y-axis</label>
<select name="fy-axis" form="votemovement">
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
<option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>
<option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
<option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option>
</select>
<label for="votemovement">TO:X-axis</label>
<select name="tx-axis" form="votemovement">
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
<option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>
<option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
<option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option>
</select>
<label for="votemovement">Y-axis</label>
<select name="ty-axis" form="votemovement">
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
<option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>
<option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
<option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option>
</select>
<input name="voteinput" formaction="vote.php" type="submit" form="votemovement" formmethod="get" value="投票する">
<input name="moveinput" formaction="move_koma.php" type="submit" form="votemovement" formmethod="get" value="駒を動かす">
</form>
</div>
<h1>これまでの投票</h1>
<article>
<p>
<?php show_votes(); ?>
</p>
</article>
<footer>
<?php
//monitor_get();
// echo $ban_pos_data[0];
//echo $koma_position[3][2];
?>
</footer>
</body>
</html>
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
先手が0~150後手が200~350
100足すと成る
先手の駒に200足すと後手の駒
0駒なし
1仲人
2歩兵
3飛車
4左車
5右車
6横行
7横飛
8堅行
9角行
10龍馬
11龍王
12摩羯
13鉤行
14奔王
15驢馬
16桂馬
17猛牛
18飛龍
19羅刹
20夜叉
21力士
22金剛
23狛犬
24老鼠
25嗔猪
26盲熊
27悪狼
28麒麟
29鳳凰
30師子
31反車
32猫叉
33淮鶏
34古猿
35蟠蛇
36臥龍
37猛豹
38盲虎
39醉象
40香車
41土将
42石将
43瓦将
44鉄将
45銅将
46銀将
47金将
48提婆
49無明
50玉将
100駒なし
101奔人
102金
103金
104金
105金
106金
107金
108金
109金
110成らず
111成らず
112金
113金
114成らず
115金
116金
117金
118金
119金
120金
121金
122金
123金
124蝙蝠
125奔猪
126奔熊
127奔狼
128師子
129奔王
130成らず
131金
132奔猫
133仙鶴
134山母
135奔蛇
136奔龍
137奔豹
138奔虎
139王子
140金
141奔土
142奔石
143奔瓦
144奔鉄
145奔銅
146奔銀
147奔金
148教王
149法性
150自在王
<!DOCTYPE html>
<html lang = "ja">
<?php
include 'functions.php';
$koma_position = array ();/*phpだとこの書き方で全部いけるらしい。*/
$kind_koma = array ();
init_table_koma();//駒とそれに対応する番号などを初期化。
get_koma_position();
//beginning_koma_pos();//駒の初期位置。
$increment_y = 1;
?>
<head>
<meta charset = "UTF-8">
<title>民主主義摩訶大大将棋.php</title>
</head>
<body>
<?php
move_koma();
/*
echo $koma_position[1][14];
monitor_get();
print $ban_pos_data[13];
*/
?>
<a href="index.php">戻る。</a>
</body>
</html>
駒を動かす仕組みはできた。
投票を受け付ける、仕組みを次は作る。
投票ボタンの中は
$fx $fy $tx $ty
1 14 1 13
この1.14.1.13を文字列にして変数に入れる。
投票番号 という配列を作る。
投票番号[0] = 1.14.1.13
投票番号[1] = 2.14.2.13
投票番号[2] = 1.14.1.13
同じ投票があれば、その数を変数人気に入れる。
echo "1.14.1.13"
echo 人気
人気の多い投票順に上から並べる。
1
2
1
3
2
1
155
224
333
442
511
2245
1554
3333
4422
5111
<!DOCTYPE html>
<html lang = "ja">
<?php
include 'functions.php';
?>
<head>
<meta charset = "UTF-8">
<title>民主主義摩訶大大将棋.php</title>
</head>
<body>
<div>
<a href="index.php">戻る。</a>
</div>
<?php
$fx = $_GET["fx-axis"];
$fy = $_GET["fy-axis"];
$tx = $_GET["tx-axis"];
$ty = $_GET["ty-axis"];
$fx_str=strval($fx);
$fy_str=strval($fy);
$tx_str=strval($tx);
$ty_str=strval($ty);
$vote = "a";
$vote = substr_replace($vote,"\n",0,1);//aを置換。
$vote = substr_replace($vote,$ty_str,0,0);//先頭に。
$vote = substr_replace($vote,".",0,0);//先頭にピリオド。
$vote = substr_replace($vote,$tx_str,0,0);//先頭に。
$vote = substr_replace($vote,".",0,0);//先頭にピリオド。
$vote = substr_replace($vote,$fy_str,0,0);//先頭に。
$vote = substr_replace($vote,".",0,0);//先頭にピリオド。
$vote = substr_replace($vote,$fx_str,0,0);//先頭に。
//echo $vote;
$times_vote = file_get_contents("投票ボタンが押された回数");
$int_times_vote = intval($times_vote);
if($int_times_vote!=0){
$vote_sofar = file_get_contents("投票内容");
$box = "a";
$box = substr_replace($box,$vote,0,1);//先頭に。
$box = substr_replace($box,$vote_sofar,0,0);//先頭に。
file_put_contents("投票内容",$box);
file_put_contents("投票ボタンが押された回数",$int_times_vote + 1);
}else if($int_times_vote==0){
file_put_contents("投票内容",$vote);
file_put_contents("投票ボタンが押された回数","1");
}
/*
echo "これまでの投票";
$vote_sofar = file("投票内容");
$number=0;
for ($x=0 ; $x<$int_times_vote+1 ; $x++){
echo $vote_sofar[$x].'/';
}
*/
show_votes();
?>
</body>
</html>
3.19.8.13
2.19.8.13
3.19.8.13
3.19.8.13
3.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.8.13
2.19.7.13
2.19.7.13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.