g341069@as301> cat > r
S1-27 341069I $B!!9b86!!;mO/(B
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;
class Start{//$B=i4|>uBV$rI=$9%/%i%9(B
public static void Start(){
for(int j = 0 ; j < Board.CellNumber ; j++){
for(int k = 0 ; k < Board.CellNumber ; k++){
Board.state[Board.count][j][k]= Board.Empty ;
}
}
Board.state[Board.count][3][3]=Board.White;
Board.state[Board.count][4][3]=Board.Black;
Board.state[Board.count][3][4]=Board.Black;
Board.state[Board.count][4][4]=Board.White;//$B=i4|CM(B
}
}
class Board{
public static final int BoardWidth=650,BoardHeight=600;//$BHW$N=D2#(B
public static final int CellWidth=60,CellHeight=60;//$B$^$9$N=D2#(B
public static final int CellNumber=8;//$B$^$9$N?t(B
public static final int White=-1,Empty=0, Black=1;//$B6p$N?'$KBP1~$9$k?t;z(B
public int Cellx,Celly;//$B$^$9$a$N0LCV(B
public static int count=0;//$B2?$l$NJ}8~$KD4$Y$k!'(Br$B$,1&(B,l$B$,:8!"(Bu$B$,>e!"(Bd$B$,2<$rI=$9(B
int No=0;//$B%3%T!<$7$FNI$$$+$r<($9(B
int virtualcount;
//$B$=$N$H$-$N>uBV$rI=$9G[Ns(B
public static int[][][] state = new int[61][8][8];
/**
$B$3$3$+$i3FJ}8~$K$R$C$/$jJV$;$k$+$I$&$+$r%A%'%C%/$9$k%a%=%C%I$,3+;O$7$^$9!#(B
$B$^$:(Bcount$B2sL\$NG[Ns$r(Bcount+1$B2sL\$N$b$N$K%3%T!<$7!"0l2s$b$R$C$/$jJV$5$J$+$C$?$i(B
$B:F$S(Bcount$B2sL\$N$b$N$rI=<($9$k$h$&$K$7$F$^$9!#(B
$B%A%'%C%/$N;EJ}$H$7$F$O!"9u$NHV$r9M$($k$H3FJ}8~$KBP$7$F$^$:NY$KGr$,$J$$$+$rD4$Y$F!"(B
$BGr$,$"$C$?$i$5$i$K$=$NNY$rD4$Y$^$9!#D4$Y$F9T$C$F9u$,$"$C$?$i$R$C$/$jJV$9!#$H$$$&:n6H$r9T$C$F$$$k$N$G(B
$B3FJ}8~$H9uGr$N>l9g$rA4ItD4$Y$F$$$k$?$aKDBg$JNL$K$J$C$F$7$^$C$F$$$^$9!#(B
*/
//
//
// $B9u$N%A%'%C%/3+;O!&!&!&!&(B
//
//
void checkBlack(){
if (No==0){
virtualcount=count;
for(int i=0; i<8;i++){
for(int j=0; j<8;j++){
state[count+1][i][j]=state[count][i][j];
}
No=1;
}
}//count$B2sL\$N>uBV$r(Bcount+1$B2sL\$N>uBV$K%3%T!<(B
//$B1&J}8~(B
if (Cellx<=6-ir && state[virtualcount][Cellx+1+ir][Celly]==Black){//$B$H$J$j$,9u$@$C$?$i(B
if (count==virtualcount && ir !=0){//$B$^$@$R$C$/$jJV$7$F$J$+$C$?$i(B
count++;//$B0l2s?J$a$F(B
}
for(int k=0 ; k <=ir ; k++){
state[count][Cellx+k][Celly]=1;//$B$R$C$/$jJV$9(B
}
}
else if (Cellx<=6-ir && state[virtualcount][Cellx+1+ir][Celly]==White){//$B$H$J$j$,Gr$@$C$?$i(B
ir++;
if(ir<=6)checkBlack();//$B$b$&0l8D$H$J$j$rC5:w(B
}
else if (Cellx<=6-ir && state[virtualcount][Cellx+1+ir][Celly]==Empty){
state[virtualcount][Cellx][Celly]=0;
}
//
//$B0J2e$N%a%=%C%I$r$3$3$G8F$S=P$9!#(B
//
//
public Board(int x , int y, int c){ //$B6p$r$R$C$/$jJV$9$?$a$N%a%=%C%I(B
Cellx=x;
Celly=y;
if(state[count][Cellx][Celly]!=Empty){//$BCV$$$?>l=j$K$b$H$b$H2?$+CV$$$F$"$C$?$i(B
System.out.println("Cannnot put");
MyCanvas.alart=1;//$B7Y9p$r=P$7$F(B
if(MyCanvas.color==1)MyCanvas.color=-1;
else if(MyCanvas.color==-1)MyCanvas.color=1;//$B?XHV$r$+$($J$$$h$&$K$9$k(B
}
else{
state[count][Cellx][Celly]=c;//$B2?$b$J$+$C$?$iCV$$$F$_$k!#(B
//$B$3$3$+$i$R$C$/$jJV$9$?$a$NH=CG!#(B
if (c==Black){//$BCV$$$?$N$,9u$@$C$?$i(B
ir=il=iu=id=No=idr=ird=iru=iur=ild=idl=ilu=iul=0;//$BC5:w8D?t$r=i4|2=$7$F(B
checkBlack();//$B$R$C$/$jJV$;$k$+%A%'%C%/(B
}
else if(c==White){//$BCV$$$?$N$,Gr$@$C$?$i(B
ir=il=iu=id=No=idr=ird=iru=iur=ild=idl=ilu=iul=0;//$BC5:w8D?t$r=i4|2=(B
checkWhite();//$B$R$C$/$jJV$;$k$+%A%'%C%/(B
}
}
}
}
//$B$3$3$^$G$,HW>e$N%/%i%9(B
//
//
//keyListener$B$H(B MouseListener$B$r;H$&!#$3$3$,%a%$%s!#(B
//$B$*$b$K2hLL$rI=<($7$^$9!#$[$+$K$O6p$N?t$r?t$($?$j!"%2!<%`=*N;$rH=CG$7$?$j$7$^$9!#(B
//
class MyCanvas extends Canvas implements KeyListener, MouseListener{
static int color=1;int col;//$B$O$8$a$O9u$+$i(B
int blacknumber=2,whitenumber=2;//$B$=$l$>$l$N6p$N?t$r?t$($k(B
static int alart=0;//$B7Y9p$r=P$9$H$-$O#1(B
public MyCanvas(){
super();
Start.Start();//$B=i4|2=(B
addKeyListener(this);
addMouseListener(this);
setSize(Board.BoardWidth,Board.BoardHeight);
}
Image offScreenImage;
Graphics offScreenGraphics;
public void update(Graphics g){
if(offScreenImage==null){
offScreenImage=createImage(Board.BoardWidth,Board.BoardHeight); // $B%*%U%9%/%j!<%s%$%a!<%8$r(B600x400$B$N%5%$%:$G:n@.(B
offScreenGraphics=offScreenImage.getGraphics(); // $B%*%U%9%/%j!<%s%$%a!<%8$KIA2h$9$k$?$a$N(B Graphics $B%*%V%8%'%/%H(B
}
paint(offScreenGraphics); // $B$l$N?t$r?t$($F(B
for(int j=0 ;j<8;j++){
if (Board.state[Board.count][i][j]<0){
whitenumber=whitenumber-Board.state[Board.count][i][j];
}
if (Board.state[Board.count][i][j]>0){
blacknumber=blacknumber+Board.state[Board.count][i][j];
}
}
}
g.setFont(new Font("Courier",Font.BOLD,15));//$B$=$l$rI=<((B
g.drawString("White : " + whitenumber,510,500);
g.drawString("Black : " + blacknumber,510,470);
if (alart==1){//$BCV$1$J$+$C$?$i7Y9p(B
g.setColor(Color.yellow);
g.drawString("You cannnot",510,250);
g.drawString(" put there" ,510,270);
alart=0;
}
if (Board.count==60){//$B#6#0!$AIi$1$rH=Dj(B
g.setFont(new Font("Courier",Font.BOLD,30));
g.setColor(Color.red);
if (whitenumber>blacknumber)g.drawString("White has won !!",100,250);//$BGr$,B?$+$C$?$i(B
else if (whitenumber0){
Board.count=Board.count-1;//$BeIt$K(B Panel
add(panel,"South");
// $B2