package com.aoduoyun.day08;
import java.util.Scanner;
public class Chess {
public static void main(String[] args){
//期盼长度
int len = 20;
//棋盘容器
String[][] chess = new String[len][len];
//期盼符号
String[] number = {"⒈","⒉","⒊","⒋","⒌","⒍","⒎","⒏","⒐","⒑","⒒","⒓","⒔","⒕","⒖","⒗","⒘","⒙","⒚","⒛"};
String add = "┼";
String black = "●";
String white = "○";
//初始化棋盘数据
for(int i = 0;i<chess.length;i++){
for(int j = 0; j<chess[i].length;j++){
//每一行的最后一列
if(j == len -1){
chess[i][j]= number[i];
}else if(i == len-1){
chess[i][j] = number[j];
}else{
chess[i][j] = add;
}
}
}
Scanner scan = new Scanner(System.in);
//白子和黑子
boolean flag = true; //白子
boolean bool = true; //判断状态
//打印棋盘
for(int i = 0; i<chess.length;i++){
for(int j = 0;j<chess[i].length;j++){
System.out.print(chess[i][j]);
}
System.out.println();
}
//当落子时
while(bool){
System.out.print("请"+((flag)?"黑":"白")+"子输入坐标");
//确定坐标点
int x = scan.nextInt()-1;
int y = scan.nextInt()-1;
//判断坐标点是否超出棋盘范围
if(x<0|| x>len-2|| y<0||y>len-2){
System.out.print("坐标超出棋盘范围请从新输入");
continue;
}
//判断坐标上是否有棋子
if(!chess[x][y].equals(add)){
System.out.println("坐标上已经有棋子,请从新输入");
continue;
}
//落子
String pieces = (flag)?black:white;
chess[x][y] = pieces;
//判断输赢
int count = right(chess,x,y,pieces)+left(chess,x,y,pieces+1);
if(count>=5){
System.out.println(((flag)?black:white)+"方赢");
bool = false;
}
//打印棋盘
for(int i = 0; i<chess.length;i++){
for(int j = 0;j<chess[i].length;j++){
System.out.print(chess[i][j]);
}
System.out.println();
}
flag = !flag;
}
}
//判断落子左边连续的棋子数
public static int left(String[][] goBang,int x,int y,String pieces){
int count = 0;
while(y>0){
y--;
if(goBang[x][y].equals(pieces)){
count++;
}else{
break;
}
}
return count;
}
public static int right(String[][] chess,int x,int y,String pieces){
int count =0;
while(y<18){
y++;
if(chess[x][y].equals(pieces)){
count++;
}else{
break;
}
}
return count;
}
}