$B7W;;5!%W%m%0%i%_%s%0-5(B($B2PMK#58B!'EDCfE/O/6541C4Ev(B)$B!!:G=*2]Bj(B
$BM}2J0lN`(B12$BAH(B
340365E
$B9S@8!!H%(B
$B35MW(B
$B%K%C%W$H$$$&%2!<%`$r:n$j$^$7$?!#$3$l$O%*%;%m%2!<%`$K;w$F$$$k$N$G$9$,;HMQ$5$l$kHW$,0c$$!"1&2<$K$"$k$h$&$JHW$r;H$o$l$^$9!#0[$J$kE@$H$7$F$O3J;RE@$K@P$rCV$/$3$H!"30<~$,1_7A$K$J$C$F$$$F3Q$,$J$$!"$J$I$H$$$&E@$,>e$2$i$l$^$9!#(B
$B%k!<%k$O4pK\E*$K%*%;%m$HF1$8$G$9!#Aj!GT$,7h$^$j$^$9!#$^$?!"30<~$G$O0l2U=j7d4V$r6u$1$F$"$H$O$9$Y$FAj
$B%=!<%9%3!<%I(B
import java.awt.*;
import java.awt.event.*;
//$B%2!<%`$N2hLL$r:n@.$9$k(BNipCanvas$B%/%i%9(B
class NipCanvas extends Canvas implements KeyListener,MouseListener{
//$B%2!<%`HW$r%U%!%$%k$+$i%m!<%I$9$k:]$KBeF~$9$kJQ?t(B
Image image;
//$B9u$N8D?t(B
int pB;
//$BGr$N8D?t(B
int pW;
//$BuBV$rI=$9G[Ns$G(B0$B$O2?$b$J$7!"(B1$B$O9u!"(B2$B$OGr!#(B
int BoW[][][]=new int[49][10][10];
//$B30<~$N>uBV$rI=$9G[Ns(B(3,1)$B$+$i;~7W2s$j$G=g$K$D$1$F$$$/!#(B20$B!A(B22$B$OI,$:(B0$B$K$9$k!#(B
int Circle[]=new int[23];
//$B=gHV$rI=$9JQ?t$G(Btrue$B$,9uHV(B
boolean bw;
//$B%3%s%9%H%i%/%?!<(B
public NipCanvas(){
super();
image=Toolkit.getDefaultToolkit().getImage("nipboard.png");
//$B=i4|G[CV(B
BoW[0][4][4]=1;
BoW[0][5][5]=1;
BoW[0][4][5]=2;
BoW[0][5][4]=2;//$B$3$3$^$G(B
setSize(650,675);
addKeyListener(this);
addMouseListener(this);
}
//$B%@%V%k%P%C%U%!%j%s%0(B
Image offScreenImage;
Graphics offScreenGraphics;
public void update(Graphics g){
if(offScreenImage==null){
offScreenImage=createImage(650,675);
offScreenGraphics=offScreenImage.getGraphics();
}
paint(offScreenGraphics);
g.drawImage(offScreenImage,0,0,this);
}//$B$3$3$^$G(B
public void paint(Graphics g){
g.drawImage(image,25,25,this);
//$B@P$N8D?t$r(B0$B$K$9$k(B
pW=0;
pB=0;
//$BHW$NItJ,$N(BBoW$B$NCM$+$i9u$+Gr$+$rH=CG(B
for(int i=1;i<9;i++){
for(int j=1;j<9;j++){
//$B9u$N>l9g(B
if(BoW[n][i][j]==1){
//$B:BI8JQ49(B((a,b)$B"*(B(x2,y2))
Recoordinate recoordinate=new Recoordinate(i-1,j-1);
g.setColor(Color.black);
g.fillOval(recoordinate.x2,recoordinate.y2,50,50);
//$B@P$N?t$N%+%&%s%H(B
pB++;
}//$B$3$3$^$G(B
//$BGr$N>l9g(B
if(BoW[n][i][j]==2){
//$B:BI8JQ49(B((a,b)$B"*(B(x2,y2))
Recoordinate recoordinate=new Recoordinate(i-1,j-1);
g.setColor(Color.white);
g.fillOval(recoordinate.x2,recoordinate.y2,50,50);
//$B@P$N?t$N%+%&%s%H(B
pW++;
}//$B$3$3$^$G(B
}
}
g.setColor(Color.black);
//bw$B$NCM$K$h$C$FI=<($rJQ99(B
if(bw) g.drawString("$B8=:_!"9u$NHV$G$9!#(B",25,570);
else g.drawString("$B8=:_!"Gr$NHV$G$9!#(B",25,570);
//$BESCf7P2a(B
g.drawString("$B8=:_(B $BGr(B"+pW+"$BBP9u(B"+pB+"$B$G$9!#(B",25,590);
//$B=*N;;~(B
if(pW+pB==52){
if(pW>pB) g.drawString("$B%2!<%`=*N;!#Gr$N>!$A$G$9!#(B",25,610);
else if(pW!$A$G$9!#(B",25,610);
else g.drawString("$B%2!<%`=*N;!#0z$-J,$1$G$9!#(B",25,610);
}
}
//$B%-!<$r2!$7$?$H$-(B
public void keyPressed(KeyEvent e){
int key=e.getKeyChar();
if(key=='q') quitLine();
if(key=='p') passLine();
if(key=='u') undoLine();
if(key=='r') redoLine();
}
public void keyReleased(KeyEvent e){
}
public void keyTyped(KeyEvent e){
}
//$B%^%&%9$r%/%j%C%/$7$?$H$-(B
public void mouseClicked(MouseEvent e){
//$B%/%j%C%/$7$?:BI8(B(x1,y1)
int x1=e.getX();
int y1=e.getY();
System.out.println("mouseClicked("+e+","+x1+","+y1+")");
//Coordinate$B%/%i%9$G:BI8JQ49(B((x1,y1)$B"*(B(a,b))
Coordinate coordinate=new Coordinate(x1,y1);
int a=coordinate.a+1;
int b=coordinate.b+1;
//$B=gHV$N$[$&$N(BBoW$B$NCM(B
int fr;
//$BE($NJ}$N(BBoW$B$NCM(B
int en;
//$B$R$C$/$jJV$7$?Kg?t(B
int r=0;
//$Be$r%/%j%C%/$7(B(a!=0)$B$+$D$=$N%/%j%C%/$7$?0LCV$,$I$A$i$N@P$bCV$$$F$J$$$H$-(B
if(a!=0&&BoW[n][a][b]==0){
//$B9u(B
if(bw){
BoW[n+1][a][b]=1;
fr=1;
en=2;
}
//$BGr(B
else{
BoW[n+1][a][b]=2;
fr=2;
en=1;
}
//$BCM$rJQ$($F<~0O$N>u67$r8+$k$?$a$NJQ?t(B(a1,b1)
int a1=a;
int b1=b;
//$B30<~$N>u67$r%3%T!<$9$k(B
for(int i=0;i<4;i++){
Circle[i]=BoW[n+1][i+3][1];
}
Circle[4]=BoW[n+1][7][2];
for(int i=5;i<9;i++){
Circle[i]=BoW[n+1][8][i-2];
}
Circle[9]=BoW[n+1][7][7];
for(int i=10;i<14;i++){
Circle[i]=BoW[n+1][16-i][8];
}
Circle[14]=BoW[n+1][2][7];
for(int i=15;i<19;i++){
Circle[i]=BoW[n+1][1][21-i];
}
Circle[19]=BoW[n+1][2][2];//$B$3$3$^$G(B
//$B%/%j%C%/$7$?:BI8$N30<~>e$N$I$NE@$KEv$?$k$+$r<($9JQ?t(B
int c;
//c$B$NCM$r7W;;(B
if(a==1&&(b>2||b<7)) c=21-b;
else if(a==8&&(b>2||b<7)) c=b+2;
else if(b==1&&(a>2||a<7)) c=a-3;
else if(b==8&&(a>2||a<7)) c=16-a;
else if(a==7&&b==2) c=4;
else if(a==7&&b==7) c=9;
else if(a==2&&b==7) c=14;
else if(a==2&&b==2) c=19;
//$B30<~$K$J$$>l9g(B
else c=21;//$B$3$3$^$G(B
//$BCM$rJQ$($F<~0O$N>u67$r8+$k$?$a$NJQ?t(Bc1
int c1=c;
//$B;~7W2s$j(B
while(true){
//$B;~7W2s$j$KF0$/(B
if(c1==19) c1=0;
else c1++;
//$B0\F0@h$K2?$b$J$+$C$?$i$R$C$/$jJV$;$J$$$N$G(Bc1$B$NCM$rLa$7$F%k!<%W$+$iH4$1$k(B
if(Circle[c1]==0){
c1=c;
break;
}
//$BAjl=j$KLa$k$^$G0l8D$:$DLa$k(B
while(c1!=c){
//$B?t9g$o$;(B
r--;
while(c1!=c){
if(c1==0) c1=19;
else c1--;
//$B<+J,$N@P$K$9$k(B
Circle[c1]=fr;
r++;
}
}
}
break;
}//$B$3$3$^$G(B
//$BH?;~7W2s$j(B($B;~7W2s$j$HF1MM(B)
while(true){
if(c1==0) c1=19;
else c1--;
if(Circle[c1]==0){
c1=c;
break;
}
else if(Circle[c1]==en){
continue;
}
else{
while(c1!=c){
r--;
while(c1!=c){
if(c1==19) c1=0;
else c1++;
Circle[c1]=fr;
r++;
}
}
}
break;
}
//BoW$B$KCM$rLa$9(B
for(int i=0;i<4;i++){
BoW[n+1][i+3][1]=Circle[i];
}
BoW[n+1][7][2]=Circle[4];
for(int i=5;i<9;i++){
BoW[n+1][8][i-2]=Circle[i];
}
BoW[n+1][7][7]=Circle[9];
for(int i=10;i<14;i++){
BoW[n+1][16-i][8]=Circle[i];
}
BoW[n+1][2][7]=Circle[14];
for(int i=15;i<19;i++){
BoW[n+1][1][21-i]=Circle[i];
}
BoW[n+1][2][2]=Circle[19];//$B$3$3$^$G(B
//$B:8B&(B
while(true){
//$B0\F0(B
a1--;
//$B0\F0@h$K2?$b$J$$>l9g$O%k!<%W$+$iH4$1$k(B
if(BoW[n][a1][b1]==0){
a1=a;
b1=b;
break;
}
//$BAjl=j$KLa$k$^$GLa$j$J$,$i$R$C$/$jJV$7$F$$$/(B
else{
for(a1=a1+1;a1a;a1--){
BoW[n+1][a1][b1]=fr;
r++;
}
}
break;
}
//$B>eB&(B
while(true){
b1--;
if(BoW[n][a1][b1]==0){
a1=a;
b1=b;
break;
}
else if(BoW[n][a1][b1]==en) continue;
else{
for(b1=b1+1;b1b;b1--){
BoW[n+1][a1][b1]=fr;
r++;
}
}
break;
}
//$B:8>e(B
while(true){
a1--;
b1--;
if(BoW[n][a1][b1]==0){
a1=a;
b1=b;
break;
}
else if(BoW[n][a1][b1]==en) continue;
else{
for(a1=a1+1,b1=b1+1;a1e(B
while(true){
a1++;
b1--;
if(BoW[n][a1][b1]==0){
a1=a;
b1=b;
break;
}
else if(BoW[n][a1][b1]==en) continue;
else{
for(a1=a1-1,b1=b1+1;a1>a;a1--){
BoW[n+1][a1][b1]=fr;
r++;
b1++;
}
}
break;
}
//$B1&2<(B
while(true){
a1++;
b1++;
if(BoW[n][a1][b1]==0){
a1=a;
b1=b;
break;
}
else if(BoW[n][a1][b1]==en) continue;
else{
for(a1=a1-1,b1=b1-1;a1>a;a1--){
BoW[n+1][a1][b1]=fr;
r++;
b1--;
}
}
break;
}
//$B0l8D$b$R$C$/$jJV$7$F$$$J$$>l9g$O85$KLa$9(B
if(r==0){
BoW[n+1][a][b]=0;
}
else{
//$B96l=j<~JU$N:BI8$+$i3J;RE@$N0LCV$r=P$9(B
public Coordinate(int x1,int y1){
a=(x1-25)/75;
b=(y1-24)/74;
if(a<0) a=0;
if(a>7) a=7;
if(b<0) b=0;
if(b>7) b=7;
//$B6a$/$K3J;RE@$,$J$$>l9g(B
if(!(a+b>1&&a+b<13&&a-b>-6&&a-b<6)) a=-1;
}
}
//$B:BI8JQ49(B((a,b)$B"*(B(x2,y2))
class Recoordinate{
int x2;
int y2;
public Recoordinate(int a,int b){
if(a==0||a==7){
if(b==2||b==5){
x2=72*a+48;
y2=77*b+30;
}
if(b==3||b==4){
x2=78*a+27;
y2=77*b+30;
}
}
else if(b==0||b==7){
if(a==2||a==5){
x2=80*a+20;
y2=71*b+51;
}
if(a==3||a==4){
x2=80*a+20;
y2=78*b+27;
}
}
else{
x2=80*a+20;
y2=77*b+30;
}
}
}
//GUI$BItIJ$N@_Dj(B
class Nip extends Frame implements ActionListener{
NipCanvas nipcanvas;
Button quitButton,passButton,undoButton,redoButton;
public Nip(){
super("Nip");
Panel panel=new Panel();
panel.setLayout(new FlowLayout());
panel.add(passButton=new Button("Pass(p)"));
passButton.addActionListener(this);
panel.add(undoButton=new Button("Undo(u)"));
undoButton.addActionListener(this);
panel.add(redoButton=new Button("Redo(r)"));
redoButton.addActionListener(this);
panel.add(quitButton=new Button("Quit(q)"));
quitButton.addActionListener(this);
setLayout(new BorderLayout());
add(panel,"South");
add(nipcanvas=new NipCanvas(),"North");
passButton.addKeyListener(nipcanvas);
undoButton.addKeyListener(nipcanvas);
redoButton.addKeyListener(nipcanvas);
quitButton.addKeyListener(nipcanvas);
setSize(getPreferredSize());
setVisible(true);
}
public void actionPerformed(ActionEvent e){
System.out.println(e);
Object source=e.getSource();
if(source.equals(passButton)){
nipcanvas.passLine();
}
else if(source.equals(undoButton)){
nipcanvas.undoLine();
}
else if(source.equals(redoButton)){
nipcanvas.redoLine();
}
else if(source.equals(quitButton)){
nipcanvas.quitLine();
}
}
public static void main(String args[]){
Nip frame=new Nip();
}
}//$B$3$3$^$G(B
$B46A[(B
$BK\Ev$O%3%s%T%e!<%?BP@o$r2DG=$K$7$?$+$C$?$s$G$9$1$I!"7h$a$k$N$,CY$9$.$F4V$K9g$$$^$;$s$G$7$?!#$^$?:#EY!"2~NI$7$F:n$C$F$_$h$&$+$H;W$C$F$^$9!#$^$?!"0l$+$i%W%m%0%i%_%s%0$r$7$F$H$F$bBgJQ$G$7$?!#$R$C$/$jJV$9;EAH$_$J$I$O$9$Y$FFH<+$J$N$G!"$H$F$b8zN($,0-$$$H;W$$$^$9!#K\Ev$KHh$l$^$7$?!#(B