import java.util.*;
public class Gobang {
public static void main(String[] args) {
/*创建游戏*/
Scanner sc=new Scanner(System.in);
boolean finish=false;
int flagnum=1;
char flagch;
int x=0,y=0;
/*生成棋盘*/
game:while(!finish) {
char checkerboard[][]=new char[15][15];
for(int i=0;i<checkerboard.length;i++) {
Arrays.fill(checkerboard[i],'-');
}
System.out.println("############################################");
System.out.println(" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15");
for(int i=0;i<checkerboard.length;i++) {
System.out.println((char)(i+65)+" ");
for(int j=0;j<checkerboard[i].length;j++) {
System.out.print(" "+checkerboard[i][j]+' ');
} System.out.println();
}
System.out.println("############################################");
/*判断当前下棋者*/
if(flagnum==1) {
flagch='*';
System.out.println("请*输入棋子坐标");
}else {
flagch='o';
System.out.println("请o输入棋子坐标");
}
/*输入棋子坐标*/
String str=sc.nextLine();
char ch=str.toUpperCase().charAt(0);
x=(int)ch-65;
y=Integer.parseInt(str.substring(1))-1;
/*判断坐标是否在棋盘内*/
if(x<0||x>14||y<0||y>14) {
System.out.println("***输入的坐标有误,请重新输入***");
continue;
}
/*判断是否有棋子*/
if(checkerboard[x][y]=='-'){
checkerboard [x][y]=flagch;//!!!!!!!!!!!!
}else {
System.out.println("位置上已有其他棋子,请重新输入");
continue;
}
/*胜利条件1*/
if(y+4<=14){if(checkerboard[x][y+1]==flagch
&&checkerboard[x][y+2]==flagch
&&checkerboard[x][y+3]==flagch
&&checkerboard[x][y+4]==flagch) {
finish=true;
break game;
}}
/*胜利条件2*/
if(y-4>=0){if(checkerboard[x][y-1]==flagch
&&checkerboard[x][y-2]==flagch
&&checkerboard[x][y-3]==flagch
&&checkerboard[x][y-4]==flagch) {
finish=true;
break game;
}}
/*胜利条件3*/
if(x-4>=0){if(checkerboard[x-1][y]==flagch
&&checkerboard[x-2][y]==flagch
&&checkerboard[x-3][y]==flagch
&&checkerboard[x-4][y]==flagch) {
finish=true;
break game;
}}
/*胜利条件4*/
if(x+4<=14){if(checkerboard[x+1][y]==flagch
&&checkerboard[x+2][y]==flagch
&&checkerboard[x+3][y]==flagch
&&checkerboard[x+4][y]==flagch) {
finish=true;
break game;
}}
/*胜利条件5*/
if(x-4>=0&&y-4>=0){if(checkerboard[x-1][y-1]==flagch
&&checkerboard[x-2][y-2]==flagch
&&checkerboard[x-3][y-3]==flagch
&&checkerboard[x-4][y-4]==flagch) {
finish=true;
break game;
}}
/*胜利条件6*/
if(x+4<=14&&y-4>=0){if(checkerboard[x+1][y-1]==flagch
&&checkerboard[x+2][y-2]==flagch
&&checkerboard[x+3][y-3]==flagch
&&checkerboard[x+4][y-4]==flagch) {
finish=true;
break game;
}}
/*胜利条件7*/
if(x-4>=0&&y+4<=14){if(checkerboard[x-1][y+1]==flagch
&&checkerboard[x-2][y+2]==flagch
&&checkerboard[x-3][y+3]==flagch
&&checkerboard[x-4][y+4]==flagch) {
finish=true;
break game;
}}
/*胜利条件8*/
if(x+4<=14&&y+4<=14){if(checkerboard[x+1][y+1]==flagch
&&checkerboard[x+2][y+2]==flagch
&&checkerboard[x+3][y+3]==flagch
&&checkerboard[x+4][y+4]==flagch) {
finish=true;
break game;
}}
/*更换玩家*/
flagnum*=-1;
}
/*游戏结束*/
if(flagnum==1) {
System.out.println("*玩家获胜");
}else {
System.out.println("o玩家获胜");
}}}