importjava.util.*;
publicclassFiveChess{
publicstaticvoidmain(String[]args){
char[][]state=newchar[16][16];
for(inti=0;i<state.length;i++){
for(intj=0;j<state.length;j++){
state[i][j]='*';
}
}
booleanisBlack=true;//当前是黑方下子
Scannerin=newScanner(System.in);
printState(state);
while(true){
System.out.println(请+(isBlack?黑:白)+方下子:);
Stringinput=in.next();
if(input.equals(exit)){
break;
}
intx=input.charAt(0)-'a';
inty=input.charAt(1)-'a';
if(state[x][y]!='*'){
System.out.println(该位置已经有棋子,请重新指定坐标!);
continue;
}
state[x][y]=(isBlack?'@':'O');
printState(state);
if(isWin(state,isBlack,x,y)){
System.out.println((isBlack?黑:白)+方胜利!);
break;
}
isBlack=!isBlack;
}
}
publicstaticvoidprintState(char[][]state){
for(inti=0;i<state.length;i++)
{
System.out.print((char)('a'+i)+);
for(intj=0;j<state.length;j++){
System.out.print(state[i][j]+);
}
System.out.println();
}
System.out.print();
for(inti=0;i<state[0].length;i++){
System.out.print((char)('a'+i)+);
}
System.out.println();
}
publicstaticbooleanisWin(char[][]state,booleanisBlack,intx,inty){
//charc=isBlack?'@':'O';
returnisShuipingWin(state,isBlack,x,y)||isChuizhiWin(state,isBlack,x,y)||
isZuoXieWin(state,isBlack,x,y)||isYouXieWin(state,isBlack,x,y);
}
publicstaticbooleanisShuipingWin(char[][]state,booleanisBlack,intx,inty){
charc=isBlack?'@':'O';
intcount=0;
do{
y--;
}
while(y>=0&&state[x][y]==c);
while(y<state[x].length&&state[x][y+1]==c){
y++;
count++;
if(y==state[x].length-1){
break;
}
}
if(count==5){
returntrue;
}
returnfalse;
}
publicstaticbooleanisChuizhiWin(char[][]state,booleanisBlack,intx,inty){
charc=isBlack?'@':'O';
intcount=0;
do{
x--;
}
while(x>=0&&state[x][y]==c);
while(x<state.length&&state[x+1][y]==c){
x++;
count++;
if(x==state.length-1){
break;
}
}
if(count==5){
returntrue;
}
returnfalse;
}
publicstaticbooleanisYouXieWin(char[][]state,booleanisBlack,intx,inty){
charc=isBlack?'@':'O';
intcount=0;
do{
x--;
y--;
}
while((x>=0&&y>=0)&&state[x][y]==c);
while(x<state.length&&y<state[0].length&&state[x+1][y+1]==c){
x++;
y++;
count++;
if(x==state.length-1||y==state[0].length-1){
break;
}
}
if(count==5){
returntrue;
}
returnfalse;
}
publicstaticbooleanisZuoXieWin(char[][]state,booleanisBlack,intx,inty){
charc=isBlack?'@':'O';
intcount=0;
do{
x--;
y++;
}
while((x>=0&&y<=state[0].length-1)&&state[x][y]==c);
while(x0&&state[x+1][y-1]==c)
{
x++;y--;
count++;
if(x==state.length-1||y==0){
break;
}
}
if(count==5){
returntrue;
}
returnfalse;
}
}