package sh;
import java.util.Random;
public class pro {
String[] koma=new String[7];
int[] pos=new int[7];
String[] hand=new String[7];
int[] x=new int[10];
int[] y=new int[10];
int[] dy=new int[100];
int[] dx=new int[100];
int number_dir;
String mode;
int number_sel;
int[] koma_sel=new int[11];
int[][] pos_ch=new int[101][7];
int number_ch;
int[][] pos_chx=new int[101][7];
String[][] hand_chx=new String[101][7];
int number_chx;
int game;
public static void main(String[] args) {
pro t=new pro();
}
pro(){
mode="先手";
koma[1]="王";
koma[2]="歩";
koma[3]="歩";
koma[4]="王";
koma[5]="歩";
koma[6]="歩";
pos[1]=2;
pos[2]=1;
pos[3]=3;
pos[4]=8;
pos[5]=7;
pos[6]=9;
hand[1]="先手";
hand[2]="先手";
hand[3]="先手";
hand[4]="後手";
hand[5]="後手";
hand[6]="後手";
int x1,y1;
int n=0;
for (y1=1;y1<4;y1++){
for (x1=1;x1<4;x1++){
n=n+1;
x[n]=x1;
y[n]=y1;
}}
game=0;
while(game<50){
select_koma();
int s,sx;
for(s=1;s<101;s++){
for(sx=1;sx<7;sx++){
pos_ch[s][sx]=-1;
}}
number_ch=0;
int tr;
for (tr=1;tr<number_sel+1;tr++){
rev(koma_sel[tr]);
}
fresh();
change();
for(tr=1;tr<number_chx+1;tr++){
invade(tr);
}
Random rnd = new Random();
int rand = rnd.nextInt(number_chx)+1;
for(s=1;s<7;s++){
hand[s]=hand_chx[rand][s];
pos[s]=pos_chx[rand][s];
}
String mm=mode;
if(mm.equals("先手"))mode="後手";
if(mm.equals("後手"))mode="先手";
match();
String strx=mode;
for(s=1;s<7;s++){
strx=strx+","+pos[s]+"("+hand[s]+")";
}
System.out.println(strx);
}
}
void match(){
if(hand[1]=="後手")game=100;
if(hand[4]=="先手")game=100;
if(hand[1]=="後手")mode="後手勝利";
if(hand[4]=="先手")mode="先手勝利";
}
void invade(int tr){
int s;
int[] c=new int[21];
for(s=1;s<10;s++){
c[s]=0;
}
for(s=1;s<7;s++){
int h=0;
int p1=pos_chx[tr][s];
if(p1>0)h=h+1;
if(hand[s].equals(mode))h=h+1;
if(h==2)c[p1]=100;
}
String mm="後手";
if(mode.equals("後手"))mm="先手";
for(s=1;s<7;s++){
int h=0;
int p1=pos_chx[tr][s];
if(p1>0)h=h+1;
if(hand[s].equals(mm))h=h+1;
if(c[p1]>50)h=h+1;
if(h==3)hand_chx[tr][s]=mode;
if(h==3)pos_chx[tr][s]=0;
}
}
void change(){
int tr,s;
number_chx=0;
for(tr=1;tr<number_ch+1;tr++){
int ch=check(tr);
if(ch<50){
number_chx=number_chx+1;
for(s=1;s<7;s++){
pos_chx[number_chx][s]=pos_ch[tr][s];
hand_chx[number_chx][s]=hand[s];
}
}
}
}
int check(int tr){
int s;
int[] c=new int[21];
for(s=1;s<10;s++){
c[s]=0;
}
for(s=1;s<7;s++){
int h=0;
int p1=pos_ch[tr][s];
if(p1>0)h=h+1;
if(hand[s].equals(mode))h=h+1;
if(h==2)c[p1]=c[p1]+1;
}
int chx=0;
for(s=1;s<9;s++){
if(c[s]>1)chx=100;
}
return chx;
}
void fresh(){
int sx,s;
for(s=1;s<number_ch+1;s++){
for(sx=1;sx<7;sx++){
if(pos_ch[s][sx]==-1)pos_ch[s][sx]=pos[sx];
}}
}
void rev(int nx){
String h1=hand[nx];
String k1=koma[nx];
makedir(h1,k1);
int s;
int p1=pos[nx];
int x1=x[p1];
int y1=y[p1];
for(s=1;s<number_dir+1;s++){
int x2=x1+dx[s];
int y2=y1+dy[s];
p1=point(x2,y2);
if(p1>0)number_ch=number_ch+1;
if(p1>0)pos_ch[number_ch][nx]=p1;
}
}
int point(int xs,int ys){
int pppp=-1;
int s;
for(s=1;s<10;s++){
int h=0;
if(x[s]==xs)h=h+1;
if(y[s]==ys)h=h+1;
if(h==2)pppp=s;
}
return pppp;
}
void select_koma(){
int s,sx;
sx=0;
for(s=1;s<7;s++){
int h=0;
if(hand[s].equals(mode))h=h+1;
if(pos[s]>0)h=h+1;
if(h==2)sx=sx+1;
if(h==2)koma_sel[sx]=s;
}
number_sel=sx;
}
void makedir(String h1,String k1){
if (k1.equals("王")){
dx[1]=1;
dy[1]=0;
dx[2]=-1;
dy[2]=0;
dx[3]=0;
dy[3]=1;
dx[4]=0;
dy[4]=-1;
dx[5]=1;
dy[5]=1;
dx[6]=-1;
dy[6]=1;
dx[7]=1;
dy[7]=-1;
dx[8]=-1;
dy[8]=-1;
number_dir=8;
}
int h=0;
if (k1.equals("歩"))h=h+1;
if (h1.equals("先手"))h=h+1;
if (h==2){
dx[1]=0;
dy[1]=1;
number_dir=1;
}
h=0;
if (k1.equals("歩"))h=h+1;
if (h1.equals("後手"))h=h+1;
if (h==2){
dx[1]=0;
dy[1]=-1;
number_dir=1;
}
}
}
最終更新:2018年01月06日 22:26