アットウィキロゴ

じゅう

package koma5;
 
 
public class pro {
 
  String[] koma=new String[7];
  int[][] dx=new int[4][11];
      int[][] dy=new int[4][11];
  int[] number_dir=new int[4];
 
   int[] x=new int[7];
   int[] y=new int[7];
    String[] pos=new String[7];
 
   String mode,game;
 
   int[] point_koma=new int[70];
   int number_koma;
    int[] point_x=new int[70];
    int[] point_y=new int[70];
    int number_point;
 
 
 
        int[] x_change=new int[7];
        int[] y_change=new int[7];
        String[] pos_change=new String[7];
    String game_change;
 
 
    int[][] x_link=new int[41][7];
    int[][] y_link=new int[41][7];
    String[][] pos_link=new String[41][7];
    String[] game_link=new String[60];
    String[] mode_link=new String[60];
    int number_link;
 
 
    public static void main(String[] args) {
        pro test=new pro();
    }
    pro(){
 
        x[1]=2;
        y[1]=3;
        x[2]=1;
        y[2]=3;
        x[3]=3;
        y[3]=3;
 
        x[4]=2;
        y[4]=1;
        x[5]=1;
        y[5]=1;
        x[6]=3;
        y[6]=1;
 
        pos[1]="先手";
        pos[2]="先手";
        pos[3]="先手";
        pos[4]="後手";
        pos[5]="後手";
        pos[6]="後手";   
 
        mode="先手";
        game="";
 
 
          /**金の先手**/
 
dx[1][1]=1;
dy[1][1]=0;
dx[1][2]=-1;
dy[1][2]=0;
 
dx[1][3]=1;
dy[1][3]=-1;
dx[1][4]=-1;
dy[1][4]=-1;
dx[1][5]=0;
dy[1][5]=-1; 
 
dx[1][6]=0;
dy[1][6]=1; 
 
number_dir[1]=6;
 
  /**金の後手**/
 
dx[2][1]=1;
dy[2][1]=0;
dx[2][2]=-1;
dy[2][2]=0;
 
dx[2][3]=1;
dy[2][3]=1;
dx[2][4]=-1;
dy[2][4]=1;
dx[2][5]=0;
dy[2][5]=1; 
 
dx[2][6]=0;
dy[2][6]=-1; 
 
number_dir[2]=6; 
 
 /**王**/
 
dx[3][1]=1;
dy[3][1]=0;
dx[3][2]=-1;
dy[3][2]=0;
 
dx[3][3]=1;
dy[3][3]=-1;
dx[3][4]=-1;
dy[3][4]=-1;
dx[3][5]=0;
dy[3][5]=-1; 
 
dx[3][6]=-1;
dy[3][6]=1; 
dx[3][7]=0;
dy[3][7]=1;  
dx[3][8]=1;
dy[3][8]=1;
 
number_dir[3]=8;        
 
 
        koma[1]="王";
        koma[2]="金";
        koma[3]="金";
        koma[4]="王";
        koma[5]="金";
        koma[6]="金";
 
 
        int trs=0;
while(trs<100){        
select_koma();
 
double r1=number_koma*Math.random();
int r2=(int)r1+1;
 
int sig=point_koma[r2];
 
 
select_dir(sig);
 
r1=number_point*Math.random();
r2=(int)r1+1;
 
change(sig,point_x[r2],point_y[r2]);
game=watch();
System.out.println(koma[sig]+","+point_x[r2]+","+point_y[r2]+","+mode+","+game);
String mm="";
if(mode.equals("先手"))mm="後手";
if(mode.equals("後手"))mm="先手";
 
mode=mm;
 
if(game.length()>0)trs=100;
trs=trs+1;
 
 
    }
 
    }
  String watch(){
 
 
        String w="";
        if(pos_change[1].equals("後手"))w="後手";
        if(pos_change[4].equals("先手"))w="先手";
 
 
        return w;
    }
 
void change(int sig,int x1,int y1){
 
 
 
        int s;
        for(s=1;s<7;s++){
        x_change[s]=x[s];
        y_change[s]=y[s];
        pos_change[s]=pos[s];
        }
 
        x_change[sig]=x1;
        y_change[sig]=y1;
 
        for(s=1;s<7;s++){
        int h=0; 
        if(x_change[s]==x_change[sig])h=h+1;
        if(y_change[s]==y_change[sig])h=h+1;
        if(pos_change[s].equals(mode))h=0;
        if(h==2)x_change[s]=0;
        if(h==2)y_change[s]=0;
        if(h==2)pos_change[s]=mode;
        }
 
  for(s=1;s<7;s++){
        x[s]=x_change[s];
        y[s]=y_change[s];
        pos[s]=pos_change[s];
        }
 
 
 
    }
 
 
 
     void select_dir(int sig){
 
        int z=0;
        if(x[sig]==0)z=100;
         if(y[sig]==0)z=100;
 
         if(z<50)select_d1(sig);
         if(z>50)select_d2();
 
    }
 
      void select_d1(int sig){
 
        int s,sx;
        int k,h;
        k=0;
        if(koma[sig]=="王")k=3;
        h=0;
        if(koma[sig].equals("金"))h=h+1;
        if(pos[sig].equals("先手"))h=h+1;
        if(h==2)k=1;
        h=0;
        if(koma[sig].equals("金"))h=h+1;
        if(pos[sig].equals("後手"))h=h+1;
        if(h==2)k=2;
 
        sx=0;
 
 
        for(s=1;s<number_dir[k]+1;s++){ 
        int x1=x[sig]+dx[k][s];
        int y1=y[sig]+dy[k][s];
        int c=check(x1,y1);
        if(c<50)sx=sx+1;
        if(c<50)point_x[sx]=x1;
        if(c<50)point_y[sx]=y1;
        }
 
 
        number_point=sx;
 
 
    }
 
 
    int check(int x1,int y1){
 
        int s,ch;
        ch=0;
        for(s=1;s<7;s++){
        int h=0;    
        if(x[s]==x1)h=h+1;
        if(y[s]==y1)h=h+1;
        if(pos[s].equals(mode))h=h+1;
        if(h==3)ch=100;
        }
 
        if(x1>3)ch=100;
        if(y1>3)ch=100;
         if(x1<1)ch=100;
        if(y1<1)ch=100;
 
        return ch;
    }
 
      void select_d2(){
 
          int x1,y1,s,ch,sx;
     sx=0;
     for(x1=1;x1<4;x1++){
     for(y1=1;y1<4;y1++){
     int c=0;
     for(s=1;s<7;s++){
     int h=0;
     if(x[s]==x1)h=h+1;
     if(y[s]==y1)h=h+1;
     if(h==2)c=100;
     }
      if(c<50)sx=sx+1;
      if(c<50)point_x[sx]=x1;
      if(c<50)point_y[sx]=y1; 
     }
     }
 
       number_point=sx;
 
    }
 
 
 
 void select_koma(){
 
        int s,sx;
        sx=0;
        for(s=1;s<7;s++){
        if(pos[s].equals(mode))sx=sx+1;    
        if(pos[s].equals(mode))point_koma[sx]=s; 
        }
 
 
        number_koma=sx;
 
 
    }
 
 
 
}
 
最終更新:2017年10月26日 15:39