新建 文本文档.txt
来自「用Java写的五子棋程序,可以运行」· 文本 代码 · 共 565 行 · 第 1/2 页
TXT
565 行
public void mouseClicked(MouseEvent e){
}
}
class Chess extends Frame{
ChessPad chesspad=new ChessPad();
Chess(){
setVisible(true);
setLayout(null);
Label label=new Label("五子棋",Label.CENTER);
add(label);label.setBounds(70,55,440,26);
label.setBackground(Color.orange);
add(chesspad);chesspad.setBounds(70,90,440,440);
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}
});
pack();setSize(600,550);
}
public static void main(String args[]){
Chess chess=new Chess();
}
}
class Evaluate{
int max_x,max_y,max;
public void evaluate(int shape[][][]){
int i=0,j=0;
for(i=0;i<19;i++)
for(j=0;j<19;j++){
switch(shape[i][j][0]) {
case 5:
shape[i][j][4]=200;
break;
case 4:
switch(shape[i][j][1]){
case 4:
shape[i][j][4]=150+shape[i][j][2]+
shape[i][j][3];
break;
case 3:
shape[i][j][4]=100+
shape[i][j][2]+
shape[i][j][3];
break;
default:
shape[i][j][4]=50+
shape[i][j][2]+
shape[i][j][3];
}
break;
case 3:
switch(shape[i][j][1]){
case 3:
shape[i][j][4]=75+
shape[i][j][2]+
shape[i][j][3];
break;
default:
shape[i][j][4]=20+
shape[i][j][2]+
shape[i][j][3];
}
break;
case 2:
shape[i][j][4]=10+shape[i][j][1]
+shape[i][j][2]
+shape[i][j][3];
break;
case 1:
shape[i][j][4]=shape[i][j][0]+shape[i][j][1]
+shape[i][j][2]
+shape[i][j][3];
default : shape[i][j][4]=0;
}
}
int x=0,y=0;
max=0;
for(x=0;x<19;x++)
for(y=0;y<19;y++)
if(max<shape[x][y][4]){
max=shape[x][y][4];
max_x=x;max_y=y;}
}
}
class Judge{
static boolean judge(int a[][],int color){
int i,j,flag;
for(i=0;i<19;i++){
flag=0;
for(j=0;j<19;j++)
if(a[i][j]==color){
flag++;
if (flag==5)
return true;}
else flag=0;
}
for(j=0;j<19;j++){
flag=0;
for(i=0;i<19;i++)
if(a[i][j]==color)
{flag++;
if(flag==5)
return true;}
else flag=0;
}
for(j=4;j<19;j++){
flag=0; int m=j;
for(i=0;i<=j;i++){
if(a[i][m--]==color){
flag++;
if(flag==5)
return true;}
else flag=0;}
}
for(j=14;j>=0;j--){
flag=0; int m=j;
for(i=0;i<=18-j;i++){
if(a[i][m++]==color){
flag++;
if(flag==5)
return true;}
else flag=0;}
}
for(i=14;i>=0;i--){
flag=0; int n=i;
for(j=0;j<19-i;j++){
if(a[n++][j]==color){
flag++;
if(flag==5)
return true;}
else flag=0;}
}
for(j=14;j>=0;j--){
flag=0; int m=j;
for(i=18;i>=j;i--){
if(a[i][m++]==color){
flag++;
if(flag==5)
return true;}
else flag=0;}
}
return false;}
}
class Scan{
int shape[][][]=new int[19][19][5];
void scan(int chesspad[][],int colour){
int i,j;
for(i=0;i<=18;i++)
for(j=0;j<=18;j++)
if(chesspad[i][j]==0){
int m=i,n=j;
while(n-1>=0&&chesspad[m][--n]==colour){
shape[i][j][0]++;
}
n=j;
while(n+1<=18&&chesspad[m][++n]==colour){
shape[i][j][0]++;
}
n=j;
while(m-1>=0&&chesspad[--m][n]==colour){
shape[i][j][1]++;
}
m=i;
while(m+1<=18&&chesspad[++m][n]==colour){
shape[i][j][1]++;
}
m=i;
while(m-1>=0&&n+1<=18&&chesspad[--m][++n]==colour){
shape[i][j][2]++;
}
m=i;n=j;
while(m+1<=18&&n-1>=0&&chesspad[++m][--n]==colour){
shape[i][j][2]++;
}
m=i;n=j;
while(m-1>=0&&n-1>=0&&chesspad[--m][--n]==colour){
shape[i][j][3]++;
}
m=i;n=j;
while(m+1<=18&&n+1<=18&&chesspad[++m][++n]==colour){
shape[i][j][3]++;
}
}
}
}
class Sort{
public void sort(int shape[][][]){
int temp;
for(int i=0;i<19;i++)
for(int j=0;j<19;j++){
for(int h=1;h<=4;h++){
for(int w=3;w>=h;w--){
if(shape[i][j][w-1]<shape[i][j][w]){
temp=shape[i][j][w-1];
shape[i][j][w-1]=shape[i][j][w];
shape[i][j][w]=temp;
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?