人机对抗代码 五子棋的简单算法——评分法( 三 )

< this.chessboard.length) {position[2] = this.chessboard[x + 1][y];} else {position[2] = 0;}if (x + 2 < this.chessboard.length) {position[3] = this.chessboard[x + 2][y];} else {position[3] = 0;}int sum = 0;sum += calculate(position);return sum;}// 上下方向评分private int mark2(int x, int y) {int[] position = new int[4];if (y - 2 >= 0) {position[0] = this.chessboard[x][y - 2];} else {position[0] = 0;}if (y - 1 >= 0) {position[1] = this.chessboard[x][y - 1];} else {position[1] = 0;}if (y + 1 < this.chessboard.length) {position[2] = this.chessboard[x][y + 1];} else {position[2] = 0;}if (y + 2 < this.chessboard.length) {position[3] = this.chessboard[x][y + 2];} else {position[3] = 0;}int sum = 0;sum += calculate(position);return sum;}// 主对角线方向评分private int mark3(int x, int y) {int[] position = new int[4];if (x - 2 >= 0 && y - 2 >= 0) {position[0] = this.chessboard[x - 2][y - 2];} else {position[0] = 0;}if (x - 1 >= 0 && y - 1 >= 0) {position[1] = this.chessboard[x - 1][y - 1];} else {position[1] = 0;}if (x + 1 < this.chessboard.length && y + 1 < this.chessboard.length) {position[2] = this.chessboard[x + 1][y + 1];} else {position[2] = 0;}if (x + 2 < this.chessboard.length && y + 2 < this.chessboard.length) {position[3] = this.chessboard[x + 2][y + 2];} else {position[3] = 0;}int sum = 0;sum += calculate(position);return sum;}// 副对角线方向评分private int mark4(int x, int y) {int[] position = new int[4];if (x - 2 >= 0 && y + 2 < this.chessboard.length) {position[0] = this.chessboard[x - 2][y + 2];} else {position[0] = 0;}if (x - 1 >= 0 && y + 1 < this.chessboard.length) {position[1] = this.chessboard[x - 1][y + 1];} else {position[1] = 0;}if (x + 1 < this.chessboard.length && y - 1 >= 0) {position[2] = this.chessboard[x + 1][y - 1];} else {position[2] = 0;}if (x + 2 < this.chessboard.length && y - 2 >= 0) {position[3] = this.chessboard[x + 2][y - 2];} else {position[3] = 0;}int sum = 0;sum += calculate(position);return sum;}// 八个方向评分private int mark5(int x, int y) {int sum = 0;int[] position = new int[4];// 上方向if (x - 1 >= 0) {position[0] = this.chessboard[x - 1][y];} else {position[0] = 0;}if (x - 2 >= 0) {position[1] = this.chessboard[x - 2][y];} else {position[1] = 0;}if (x - 3 >= 0) {position[2] = this.chessboard[x - 3][y];} else {position[2] = 0;}if (x - 4 >= 0) {position[3] = this.chessboard[x - 4][y];} else {position[3] = 0;}sum += calculate2(position);// 下方向if (x + 1 < this.chessboard.length) {position[0] = this.chessboard[x + 1][y];} else {position[0] = 0;}if (x + 2 < this.chessboard.length) {position[1] = this.chessboard[x + 2][y];} else {position[1] = 0;}if (x + 3 < this.chessboard.length) {position[2] = this.chessboard[x + 3][y];} else {position[2] = 0;}if (x + 4 < this.chessboard.length) {position[3] = this.chessboard[x + 4][y];} else {position[3] = 0;}sum += calculate2(position);// 左方向if (y - 1 >= 0) {position[0] = this.chessboard[x][y - 1];} else {position[0] = 0;}if (y - 2 >= 0) {position[1] = this.chessboard[x][y - 2];} else {position[1] = 0;}if (y - 3 >= 0) {position[2] = this.chessboard[x][y - 3];} else {position[2] = 0;}if (y - 4 >= 0) {position[3] = this.chessboard[x][y - 4];} else {position[3] = 0;}sum += calculate2(position);// 右方向if (y + 1 < this.chessboard.length) {position[0] = this.chessboard[x][y + 1];} else {position[0] = 0;}if (y + 2 < this.chessboard.length) {position[1] = this.chessboard[x][y + 2];} else {position[1] = 0;}if (y + 3 < this.chessboard.length) {position[2] = this.chessboard[x][y + 3];} else {position[2] = 0;}if (y + 4 < this.chessboard.length) {position[3] = this.chessboard[x][y + 4];} else {position[3] = 0;}sum += calculate2(position);// 左斜上方向if (x - 1 >= 0 && y - 1 >= 0) {position[0] = this.chessboard[x - 1][y - 1];} else {position[0] = 0;}if (x - 2 >= 0 && y - 2 >= 0) {position[1] = this.chessboard[x - 2][y - 2];} else {position[1] = 0;}if (x - 3 >= 0 && y - 3 >= 0) {position[2] = this.chessboard[x - 3][y - 3];} else {position[2] = 0;}if (x - 4 >= 0 && y - 4 >= 0) {position[3] = this.chessboard[x - 4][y - 4];} else {position[3] = 0;}sum += calculate2(position);// 左斜下方向if (x + 1