Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static int[][] d = new int[][]{{1, 1, 'P', 'b'}, {-1, 1, 'P'}, {1, -1, 'p'}, {-1, -1, 'p'}};
- private static int[][] o = new int[][]{{0, 1, '.', 'r'}, {0, -1, '.'}, {1, 0, '.'}, {-1, 0, '.'}};
- private static int[][][] all = {d, o};
- public static boolean canBeCaptured(int x, int y, char[][] board) {
- char color = color(board[y][x]);
- for (int[][] d_o : all) {
- for (int[] dir : d_o) {
- for (int i = 1; i < 8; i++) {
- char square = get(x + i * dir[0], y + i * dir[1], board);
- if (square == ' ') {
- continue;
- }
- if (color(square) == color|| square=='x') {
- break;
- }
- if (sameLtr(square, 'q') || sameLtr(square, (char) d_o[0][3]) || (i == 1 && (square == dir[2] || sameLtr(square, 'k')))) {
- return true;
- }
- break;
- }
- }
- }
- for (int[] dir : d) {
- for (int[] n : new int[][]{{2, 1}, {1, 2}}) {
- char square = get(x + n[0] * dir[0], y + n[1] * dir[1], board);
- if (sameLtr(square, 'n') && color(square) != color) {
- return true;
- }
- }
- }
- return false;
- }
- private static char get(int x, int y, char[][] board) {
- return (x > 7 || x < 0 || y > 7 || y < 0) ? 'x' : board[y][x];
- }
- private static boolean sameLtr(char ch, char ch2) {
- return Character.toUpperCase(ch) == Character.toUpperCase(ch2);
- }
- private static char color(char ch) {
- return Character.isUpperCase(ch) ? 'W' : 'b';
- }
Advertisement
Add Comment
Please, Sign In to add comment