xx000

package sho;
 
public class pro {
 
    String[] koma=new String[7];
  int[] pos=new int[7];
  String[] hand=new String[7];  
  int[][] ban=new int[10][2];
 
 
String mode;
 
int number;
 String[] hash_chx=new String[101];
String[][][] link=new String[10][5000][21];
String[][] dic=new String[10][5000];
int[] number_dic=new int[10];
int[][] number_link=new int[10][5000];
 
int game;
int[][] point=new int[7][5000];
int[][] pointx=new int[7][5000];
 
 
    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;
        ban[n][0]=x1;
        ban[n][1]=y1;        
        }}
 
        String hhh=hash();
 
       dic[1][1]=hhh;
       number_dic[1]=1;
       int tr;
       int don;
       for(don=1;don<6;don++){
       for(tr=1;tr<number_dic[don]+1;tr++){ 
       decode(dic[don][tr]);
       int z=0;
       if(mode.equals("先手"))z=100;
       if(mode.equals("後手"))z=100;
       number=0;
       if(z>40){
       game sub=new game();
       sub.ban=ban;
       sub.koma=koma;
       sub.makedata(dic[don][tr]);
       number=sub.number_chx;
       hash_chx=sub.hash_chx;
       }
 
       int s;
       for(s=1;s<number+1;s++){
       link[don][tr][s]=hash_chx[s];    
       }
       number_link[don][tr]=number;
       }
       int c=0;
       int sx,s;
       for(s=1;s<number_dic[don]+1;s++){
       for(sx=1;sx<number_link[don][s]+1;sx++){
       c=c+1;
       dic[don+1][c]=link[don][s][sx];    
       }
       }
       number_dic[don+1]=c;
       }
 
 
       int s;
       for(s=1;s<number_dic[6]+1;s++){
       decode(dic[6][s]);
       point[6][s]=50;
       pointx[6][s]=50;
       if(mode.equals("後手勝利"))pointx[6][s]=100;
       if(mode.equals("後手勝利"))point[6][s]=0;
       }
 
       int sx;
      int sig;
      for(sig=1;sig<6;sig++){
      int t=6-sig;
      int m;
      for(m=1;m<number_dic[t]+1;m++){
      decode(dic[t][m]);
      int maxp=-999;
      for(sx=1;sx<number_link[t][m]+1;sx++){
      int p1=0;
      int sxs=search(link[t][m][sx],t+1);
      if(mode.equals("先手"))p1=point[t+1][sxs];
      if(mode.equals("後手"))p1=pointx[t+1][sxs];
     if (p1>maxp)maxp=p1;
      }
      if(mode.equals("先手"))point[t][m]=maxp;
      if(mode.equals("先手"))pointx[t][m]=100-maxp;
      if(mode.equals("後手"))pointx[t][m]=maxp;;
      if(mode.equals("後手"))point[t][m]=100-maxp;;
      if(mode.equals("先手勝利"))point[t][m]=100;
      if(mode.equals("先手勝利"))pointx[t][m]=0;
      if(mode.equals("後手勝利"))pointx[t][m]=100;
      if(mode.equals("後手勝利"))point[t][m]=0;
       }
      }
 
    for(s=1;s<number_dic[1]+1;s++){  
    System.out.println(point[1][s]);
    }
 
 
 
 
 
    }
int search(String x1,int m){
 
    int s,sx;
    sx=0;
    for(s=1;s<number_dic[m];s++){
    if(dic[m][s].equals(x1))sx=s;    
    }
 
    return sx; 
}
 
 
 
String hash(){
 
       String ha="";
       if (mode.equals("先手"))ha=ha+"w";
       if (mode.equals("後手"))ha=ha+"x";
       if (mode.equals("先手勝利"))ha=ha+"y";
       if (mode.equals("後手勝利"))ha=ha+"z";
 
       int s;
       for(s=1;s<7;s++){
       if(hand[s].equals("先手"))ha=ha+"p";    
       if(hand[s].equals("後手"))ha=ha+"q"; 
       }
 
       String w1="a,b,c,d,e,f,g,h,i,j";
       String[] ww=w1.split(",");
 
       for(s=1;s<7;s++){
       int sx=pos[s];    
       ha=ha+ww[sx];
       }
 
 
        return ha; 
}
 
void decode(String hxp){
 
    String m1=hxp.substring(0,1);
    String[] h1=new String[7];
    String[] p1=new String[7];
    int s;
    for(s=1;s<7;s++){
    h1[s]=hxp.substring(s,s+1);
    }
    for(s=1;s<7;s++){
    p1[s]=hxp.substring(s+6,s+7);
    }
 
    if(m1.equals("w"))mode="先手";
    if(m1.equals("x"))mode="後手";  
    if(m1.equals("y"))mode="先手勝利";
    if(m1.equals("z"))mode="後手勝利";  
 
 
    for(s=1;s<7;s++){
    if(h1[s].equals("p"))hand[s]="先手";
    if(h1[s].equals("q"))hand[s]="後手";       
    }
 
 
    for(s=1;s<7;s++){
    if(p1[s].equals("a"))pos[s]=0;
    if(p1[s].equals("b"))pos[s]=1;       
    if(p1[s].equals("c"))pos[s]=2;
    if(p1[s].equals("d"))pos[s]=3; 
    if(p1[s].equals("e"))pos[s]=4;
    if(p1[s].equals("f"))pos[s]=5; 
    if(p1[s].equals("g"))pos[s]=6;
    if(p1[s].equals("h"))pos[s]=7; 
    if(p1[s].equals("i"))pos[s]=8;
    if(p1[s].equals("j"))pos[s]=9; 
    }
 
 
 
 
 
 
 
 
}
 
 
 
 
 
 
 
 
 }
 
 
 
 
 
package sho;
 
 
public class game {
 
    String[] koma=new String[7];
  int[] pos=new int[7];
  String[] hand=new String[7];  
  int[][] ban=new int[10][2];
 
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];
String[] mode_chx=new String[101];
int number_chx;
 String[] hash_chx=new String[101];
 
 
    void makedata(String hhh){
 
        decode(hhh);
 
        int x1,y1;
        int n=0;
 
        select_koma();
 
 int tr,d;
 number_ch=0;
 for(tr=1;tr<number_sel+1;tr++){
 int kk=koma_sel[tr];
 makedir(hand[kk],koma[kk]);
 for(d=1;d<number_dir+1;d++){     
 int d1=pos[kk];
 x1=ban[d1][0]+dx[d];
 y1=ban[d1][1]+dy[d];
 int p1=point(x1,y1);
 if(p1>0){
 int s;
 number_ch=number_ch+1;
 for(s=1;s<7;s++){ 
 pos_ch[number_ch][s]=pos[s];
 }
 pos_ch[number_ch][kk]=p1;
 }
 }
 }       
 
 
 change();
 
 
 int q;
 for(q=1;q<number_chx+1;q++){
 invade(q); 
    }
 
 for(q=1;q<number_chx+1;q++){
 match(q);
 }
 for(q=1;q<number_chx+1;q++){
 hash_chx[q]=hash(q);
 
 }
 
 
 decode(hash_chx[1]);
 
 
    }
 
 
String hash(int q){
 
       String ha="";
       if (mode_chx[q].equals("先手"))ha=ha+"w";
       if (mode_chx[q].equals("後手"))ha=ha+"x";
       if (mode_chx[q].equals("先手勝利"))ha=ha+"y";
       if (mode_chx[q].equals("後手勝利"))ha=ha+"z";
 
       int s;
       for(s=1;s<7;s++){
       if(hand_chx[q][s].equals("先手"))ha=ha+"p";    
       if(hand_chx[q][s].equals("後手"))ha=ha+"q"; 
       }
 
       String w1="a,b,c,d,e,f,g,h,i,j";
       String[] ww=w1.split(",");
 
       for(s=1;s<7;s++){
       int sx=pos_chx[q][s];    
       ha=ha+ww[sx];
       }
 
 
        return ha; 
}
 
void decode(String hxp){
 
    String m1=hxp.substring(0,1);
    String[] h1=new String[7];
    String[] p1=new String[7];
    int s;
    for(s=1;s<7;s++){
    h1[s]=hxp.substring(s,s+1);
    }
    for(s=1;s<7;s++){
    p1[s]=hxp.substring(s+6,s+7);
    }
 
    if(m1.equals("w"))mode="先手";
    if(m1.equals("x"))mode="後手";  
    if(m1.equals("y"))mode="先手勝利";
    if(m1.equals("z"))mode="後手勝利";  
 
 
    for(s=1;s<7;s++){
    if(h1[s].equals("p"))hand[s]="先手";
    if(h1[s].equals("q"))hand[s]="後手";       
    }
 
 
    for(s=1;s<7;s++){
    if(p1[s].equals("a"))pos[s]=0;
    if(p1[s].equals("b"))pos[s]=1;       
    if(p1[s].equals("c"))pos[s]=2;
    if(p1[s].equals("d"))pos[s]=3; 
    if(p1[s].equals("e"))pos[s]=4;
    if(p1[s].equals("f"))pos[s]=5; 
    if(p1[s].equals("g"))pos[s]=6;
    if(p1[s].equals("h"))pos[s]=7; 
    if(p1[s].equals("i"))pos[s]=8;
    if(p1[s].equals("j"))pos[s]=9; 
    }
 
 
 
 
 
 
 
 
}
 
 
 
 
   void match(int q){
 
 
       String mm=mode;
       if(mm=="先手")mode_chx[q]="後手";
       if(mm=="後手")mode_chx[q]="先手";
 
       if(hand_chx[q][1]=="後手")mode_chx[q]="後手勝利";
       if(hand_chx[q][4]=="先手")mode_chx[q]="先手勝利";
 
   } 
 
 
    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=ban[p1][0];
        int y1=ban[p1][1];
        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(ban[s][0]==xs)h=h+1;
      if(ban[s][1]==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年03月01日 08:33