📄 ruchy.java
字号:
&&
plansza[i-2][j-2] == Gra.PUSTE)
return true;
break;
case Gra.B_DAMKA:
if (i+2<8)
{
if (j+2<8)
if ( (plansza[i+1][j+1] == Gra.CZARNE ||
plansza[i+1][j+1] == Gra.C_DAMKA )
&&
plansza[i+2][j+2] == Gra.PUSTE)
return true;
if (j-2>-1)
if ( (plansza[i+1][j-1] == Gra.CZARNE ||
plansza[i+1][j-1] == Gra.C_DAMKA )
&&
plansza[i+2][j-2] == Gra.PUSTE)
return true;
}
if (i-2>-1)
{
if (j+2<8)
if ( (plansza[i-1][j+1] == Gra.CZARNE ||
plansza[i-1][j+1] == Gra.C_DAMKA )
&&
plansza[i-2][j+2] == Gra.PUSTE)
return true;
if (j-2>-1)
if ( (plansza[i-1][j-1] == Gra.CZARNE ||
plansza[i-1][j-1] == Gra.C_DAMKA )
&&
plansza[i-2][j-2] == Gra.PUSTE)
return true;
}
break;
case Gra.C_DAMKA:
if (i+2<8)
{
if (j+2<8)
if ( (plansza[i+1][j+1] == Gra.BIALE ||
plansza[i+1][j+1] == Gra.B_DAMKA )
&&
plansza[i+2][j+2] == Gra.PUSTE)
return true;
if (j-2>-1)
if ( (plansza[i+1][j-1] == Gra.BIALE ||
plansza[i+1][j-1] == Gra.B_DAMKA )
&&
plansza[i+2][j-2] == Gra.PUSTE)
return true;
}
if (i-2>-1)
{
if (j+2<8)
if ( (plansza[i-1][j+1] == Gra.BIALE ||
plansza[i-1][j+1] == Gra.B_DAMKA )
&&
plansza[i-2][j+2] == Gra.PUSTE)
return true;
if (j-2>-1)
if ( (plansza[i-1][j-1] == Gra.BIALE ||
plansza[i-1][j-1] == Gra.B_DAMKA )
&&
plansza[i-2][j-2] == Gra.PUSTE)
return true;
}
break;
} // switch
return false;
} // czyMozeBic()
static boolean czyMozliwePosuniecie(int[][] plansza, int i, int j)
{
switch ( plansza[i][j] )
{
case Gra.BIALE:
if ( czyPuste(plansza,i+1,j+1) || czyPuste(plansza,i-1,j+1) )
return true;
break;
case Gra.CZARNE:
if ( czyPuste(plansza,i+1,j-1) || czyPuste(plansza,i-1,j-1) )
return true;
break;
case Gra.B_DAMKA:
case Gra.C_DAMKA:
if ( czyPuste(plansza,i+1,j+1) || czyPuste(plansza,i+1,j-1)
|| czyPuste(plansza,i-1,j+1) || czyPuste(plansza,i-1,j-1) )
return true;
} // switch
return false;
} // czyMozliwePosuniecie()
private static boolean czyPuste(int[][] position, int i, int j)
{
if (i>-1 && i<8 && j>-1 && j<8)
if (position[i][j] == Gra.PUSTE)
return true;
return false;
} // czyPuste()
static int kolor(int pion)
{
switch (pion)
{
case Gra.BIALE:
case Gra.B_DAMKA:
return Gra.BIALE;
case Gra.CZARNE:
case Gra.C_DAMKA:
return Gra.CZARNE;
}
return Gra.PUSTE;
}
private static boolean wPlanszy(int i, int j)
{
return (i>-1 && i<8 && j>-1 && j<8);
}
static Vector generujRuchy(int[][] plansza, int czyjRuch) {
Vector listaRuchow = new Vector();
int ruch;
for (int i=7; i>=0; i--)
for (int j=0; j<8; j++)
if (czyjRuch==kolor(plansza[i][j])) {
if (czyMozeBic(plansza,czyjRuch)) {
for (int k=-2; k<=2; k+=4)
for (int l=-2; l<=2; l+=4)
{
ruch=czyRuchDozwolony(plansza,i,j,i+k,j+l,czyjRuch);
if (ruch == NIEKOMPLETNY)
{
int[] int_array = new int[4];
int_array[0]=i; int_array[1]=j;
int_array[2]=i+k; int_array[3]=j+l;
int[][] kopiaPlansza = Silnik.kopiujPlansze(plansza);
ruch = Ruchy.WykonajRuch(kopiaPlansza,i,j,i+k,j+l);
if (ruch == NIEKOMPLETNY)/*(czyMozeBic(kopiaPlansza,i+k,j+l))*/
{
przymusoweBicie(kopiaPlansza, czyjRuch, int_array,listaRuchow,10);
}
else
{
listaRuchow.addElement(int_array);
}
} // if (ruch)
} // if (wPlanszy)
}
else {
for (int k=-1; k<=2; k+=2)
for (int l=-1; l<=2; l+=2){
if (wPlanszy(i+k,j+l))
{
ruch=czyPosuniecieDozwolone(plansza,i,j,i+k,j+l,czyjRuch);
if (ruch == DOZWOLONY)
{
int[] int_array = new int[4];
int_array[0]=i; int_array[1]=j;
int_array[2]=i+k; int_array[3]=j+l;
listaRuchow.addElement(int_array);
} // if (ruch)
} // if (wPlanszy)
} //end for k,l
}
}//end if
return listaRuchow;
}//generujRuchy
static void rusz(int[][] plansza, int[] ruch)
{
int startx = ruch[0];
int starty = ruch[1];
int endx = ruch[2];
int endy = ruch[3];
//System.out.println(startx+" "+starty+" "+endx+" "+endy);
while (endx>0 || endy>0)
{
WykonajRuch(plansza,startx,starty,endx%10,endy%10);
startx = endx%10;
starty = endy%10;
endx /= 10;
endy /= 10;
//System.out.println(startx+" "+starty+" "+endx+" "+endy);
}
}
private static void przymusoweBicie(int[][] plansza, int czyjRuch, int[] ruch, Vector listaRuchow,int inc){
int newx = ruch[2], newy = ruch[3], opponent;
while (newx>7 || newy>7){
newx/=10;
newy/=10;
}//end while
for (int i=-2; i<=2; i+=4)
for (int j=-2; j<=2; j+=4)
if (wPlanszy(newx+i,newy+j)) {
int[][] kopiaPlansza = Silnik.kopiujPlansze(plansza);
int wynik = WykonajRuch(kopiaPlansza,newx,newy,newx+i,newy+j);
if (wynik == DOZWOLONY) {
int[] nowy_ruch = new int[4];
nowy_ruch[0] = ruch[0];
nowy_ruch[1] = ruch[1];
nowy_ruch[2] = ruch[2]+(newx+i)*inc;
nowy_ruch[3] = ruch[3]+(newy+j)*inc;
listaRuchow.addElement(nowy_ruch);
} // if (wynik == DOZWOLONY)
else if (wynik == NIEKOMPLETNY)
{
int[] nowy_ruch = new int[4];
nowy_ruch[0] = ruch[0];
nowy_ruch[1] = ruch[1];
nowy_ruch[2] = ruch[2]+(newx+i)*inc;
nowy_ruch[3] = ruch[3]+(newy+j)*inc;
przymusoweBicie(kopiaPlansza, czyjRuch, nowy_ruch, listaRuchow, inc*10);
}
} //end if for
}//przymusoweBicie
} // class Ruchy
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -