public class Temp {
private static int CHESS = 1;
private static int EMPTY = 0;
void test() {
Scanner scanner = new Scanner(System.in);
int n = 6;
int[][] chessBoard = new int[n][n];
List<Integer[]> list = chessBoard(chessBoard);
print(list);
}
void print(List<Integer[]> list) {
for (Integer[] item : list) {
System.out.print(item);
}
}
List<Integer[]> chessBoard(int[][] chessboard) {
List<Integer[]> list = new ArrayList<>();
for (int x = 0; x < chessboard.length; x++) {
for (int y = 0; y < chessboard.length; y++) {
if (isWin(x, y,chessboard)) {
Integer[] integers = new Integer[2];
integers[0] = x;
integers[1] = y;
list.add(integers);
}
}
}
return list;
}
int[][] getDirection() {
int[][] data = new int[][]{
{0, 1},
{0, -1},
{1, 0},
{-1, 0},
{-1, -1},
{1, -1},
{-1, 1},
{1, 1}
};
return data;
}
boolean isWin(int i, int j, int[][] chessboard) {
int[][] directions = getDirection();
for (int[] direction : directions) {
if (isWin(direction, i, j, chessboard)) {
return true;
}
}
return false;
}
boolean isWin(int[] direction, int x, int y, int[][] chessboard) {
int i = x;
int j = y;
int count = 0;
while (i >= 0 && j < direction.length) {
if (chessboard[i][j] != CHESS) {
return false;
}
if (count == 4) {
return true;
}
i += direction[0];
j += direction[1];
++count;
}
return false;
}
}
|