采用简单的
public class Test {
static int[][] qipan = new int[15][15];
public static void main(String[] args) {
qipan[1][1] = 2;
qipan[2][2] = 2;
qipan[3][3] = 2;
qipan[4][4] = 2;
qipan[5][5] = 2;
System.out.println(isWin(qipan,2));
}
/**
* 判断五子棋棋盘数组是否存在连5
* @param qipan 棋盘数组,int类型,默认值为0
* @param color 棋子颜色,int类型,1为黑,2为白
* @return 如果存在连5,则返回True
*/
public static boolean isWin(int[][] qipan,int color){
boolean colsWcoln = false;
int colors = (int) Math.pow(color, 5);
for(int row = 0;row<15;row++){
for(int col=0;col<15;col++){
//第一种
if(row<=10 && col<4){
//int x = qcolpan[col][row]*qcolpan[col][row]*qcolpan[col][row]*qcolpan[col][row]*qcolpan[col][row]//→
int x = qipan[col][row]*qipan[col+1][row]*qipan[col+2][row]*qipan[col+3][row]*qipan[col+4][row];//→
int y = qipan[col][row]*qipan[col+1][row+1]*qipan[col+2][row+2]*qipan[col+3][row+3]*qipan[col+4][row+4]; //→
int z = qipan[col][row]*qipan[col][row+1]*qipan[col][row+2]*qipan[col][row+3]*qipan[col][row+4]; //→
if(x == colors || y == colors || z == colors){
colsWcoln = true;
}
}
//第二种
if(row<=10 && col>=4 && col<=10 ){
int x = qipan[col][row]*qipan[col+1][row]*qipan[col+2][row]*qipan[col+3][row]*qipan[col+4][row];//→
int y = qipan[col][row]*qipan[col+1][row+1]*qipan[col+2][row+2]*qipan[col+3][row+3]*qipan[col+4][row+4]; //→
int z = qipan[col][row]*qipan[col][row+1]*qipan[col][row+2]*qipan[col][row+3]*qipan[col][row+4]; //→
int m = qipan[col][row]*qipan[col-1][row]*qipan[col-2][row]*qipan[col-3][row]*qipan[col-4][row];//→
int n = qipan[col][row]*qipan[col-1][row+1]*qipan[col-2][row+2]*qipan[col-3][row+3]*qipan[col-4][row+4];//→
if(x == colors || y == colors || z == colors || m == colors || n == colors){
colsWcoln = true;
}
}
//第三种
if(row<=10 && col>10 ){
int z = qipan[col][row]*qipan[col][row+1]*qipan[col][row+2]*qipan[col][row+3]*qipan[col][row+4]; //→
int m = qipan[col][row]*qipan[col-1][row]*qipan[col-2][row]*qipan[col-3][row]*qipan[col-4][row];//→
int n = qipan[col][row]*qipan[col-1][row+1]*qipan[col-2][row+2]*qipan[col-3][row+3]*qipan[col-4][row+4];//→
if( z == colors || m == colors || n==colors){
colsWcoln = true;
}
}
//第四种
if(row>10 && col<4){
int x = qipan[col][row]*qipan[col+1][row]*qipan[col+2][row]*qipan[col+3][row]*qipan[col+4][row];//→
if(x == colors){
colsWcoln = true;
}
}
//第五种
if(row>10 && col>=4 && col<=10){
int x = qipan[col][row]*qipan[col+1][row]*qipan[col+2][row]*qipan[col+3][row]*qipan[col+4][row];//→
int m = qipan[col][row]*qipan[col-1][row]*qipan[col-2][row]*qipan[col-3][row]*qipan[col-4][row];//→
if(x == colors || m == colors)
{
colsWcoln = true;
}
}
//第六种
if(row>10 && col>10)
{
int m = qipan[col][row]*qipan[col-1][row]*qipan[col-2][row]*qipan[col-3][row]*qipan[col-4][row];//→
if(m == colors ){
colsWcoln = true;
}
}
}
}
return colsWcoln;
}
}