import java.util.Scanner;、
public class WZQ1 {
static String white = "○";
static String black = "●";
static String[][] qp = new String[15][15];//棋盘
static String[] num = {"⒈","⒉","⒊","⒋","⒌","⒍","⒎","⒏","⒐","⒑","⒒","⒓","⒔","⒕","⒖"};
static String line = "十";
public static void main(String[] args) {
intit();
print();
startGame();
print();
}
/**
输入棋盘
*/
public static void intit(){
for (int i = 0; i < qp.length ; i++) {
for (int j = 0; j < qp[i].length; j++) {
if (j == qp[i].length-1) {
qp[i][j]=num[i];
continue;
}
if (i == qp.length-1) {
qp[i][j]=num[j];
continue;
}
qp[i][j]=line;
}
}
}
/**
输出棋盘
*/
public static void print(){
for (int i = 0; i < qp.length; i++) {
for (int j = 0; j < qp[i].length ; j++) {
System.out.print(qp[i][j]);
}
System.out.println();
}
}
/**
开始下棋
*/
public static void startGame(){
boolean flag = true;
while (true){
if (flag == true) {
System.out.println("请输入横坐标");
Scanner scan1 = new Scanner(System.in);
int x = scan1.nextInt();
System.out.println("请输入横坐标");
Scanner scan2 = new Scanner(System.in);
int y = scan2.nextInt();
boolean res = check(x, y);
if (res) {
qp[x-1][y-1]=black;
print();
//判断输赢
boolean winer = win( x-1,y-1, black);
if (winer == true) {
System.out.println("黑棋胜利");
break;
}
flag = false;
}
else {
System.out.println("棋子越界或重复,请重新下棋");
}
}
else {
System.out.println("请输入横坐标");
Scanner scan1 = new Scanner(System.in);
int x = scan1.nextInt();
System.out.println("请输入横坐标");
Scanner scan2 = new Scanner(System.in);
int y = scan2.nextInt();
//判断越界
boolean res = check(x, y);
if (res) {
qp[x-1][y-1]=white;
print();
//判断输赢
boolean winer = win( x-1,y-1, white);
if (winer == true) {
System.out.println("白旗胜利");
break;
}
flag = true;
}
else {
System.out.println("棋子越界或重复,请重新下棋");
}
}
}
}
/**
判断是否重复
判断是否越界
*/
public static boolean check(int x, int y){
if (x<0||x>14||y<0||y>14) {
return false;
}
if (qp[x-1][y-1] != line) {
return false;
}
else
return true;
}
/**
输赢
*/
public static boolean win(int x,int y,String what){
int n = 1;
//水平向右
for (int righty = y+1; righty < qp[x].length ; righty++) {
if (qp[x][righty].equals(what)) {
n++;
}
else{
break;
}
}
if (n >= 5) {
return true;
}
//水平向左
for (int lefty = y-1; lefty >= 0 ; lefty--) {
if (qp[x][lefty].equals(what)) {
n++;
}
else{
break;
}
}
if (n >= 5) {
return true;
}
//判断列
n =1;
for (int downx = x+1; downx < qp.length ; downx++) {
if (qp[downx][y] == what) {
n++;
}
else {
break;
}
}
for (int upx = x-1; upx >=0; upx--) {
if (qp[upx][y] == what) {
n++;
}
else {
break;
}
}
if (n >= 5) {
return true;
}
//判断右下到左上
n=1;
for (int xx = x+1,xy = y+1; xx < qp.length-1&&xy<qp[x].length-1; xx++,xy++) {
if (qp[xx][xy] == what) {
n++;
}
else {
break;
}
if (n >= 5) {
return true;
}
return false;
}
for (int a = x-1,b = y-1; a >=0&&b>=0 ; a--,b--) {
if (qp[a][b] == what) {
n++;
}
else {
break;
}
}
if (n >= 5) {
return true;
}
//判断右上到左下
for (int xx = x-1,xy = y+1; xx>=0&&xy< qp.length ; xx--,xy++) {
if (qp[xx][xy] == what) {
n++;
}
else{
break;
}
if (n >= 5) {
return true;
}
return false;
}
for (int xx = x+1,xy=y-1; xx < qp.length&&xy>=0 ; xx++,xy--) {
if (qp[xx][xy] == what) {
n++;
}
}
if (n >= 5) {
return true;
}
return false;
}
}