# android开发五子棋人机对战

1.checkBlackTwoTwo(BlackPoint)

2.checkWhiteTwoTwo(WhitePoint)

3.checkBlackFourInLine(BlackPoint)

 private boolean checkBlackFourInLine(ArrayList<Point> point) {
for (Point p : point) {
int x = p.x;
int y = p.y;
boolean checkHorizontal = checkBlackFourHorizontalInLine(x, y, point);
if (checkHorizontal) {
return true;
}
boolean checkVertical = checkBlackFourVerticalInLine(x, y, point);
if (checkVertical) {
return true;
}
boolean checkLeftDiagonal = checkBlackFourLeftInLine(x, y, point);
if (checkLeftDiagonal) {
return true;
}
boolean checkRightDiagonal = checkBlackFourRightInLine(x, y, point);
if (checkRightDiagonal) {
return true;
}
}
return false;
}

 int count = 1;
for (int i = 1; i < 4; i++) {
if (point.contains(new Point(x - i, y))) {
count++;
} else {
break;
}
}
if (count == 4) {
if (x - 4 < 0) {
if (!BlackPoint.contains(new Point(x + 1, y)) && !WhitePoint.contains(new Point(x + 1, y))) {
return true;
}
} else if (x + 1 > MAX_LINE - 1) {
if (!BlackPoint.contains(new Point(x - 4, y)) && !WhitePoint.contains(new Point(x - 4, y))) {
return true;
}
} else if (!BlackPoint.contains(new Point(x - 4, y)) && !BlackPoint.contains(new Point(x + 1, y))) {
if (!WhitePoint.contains(new Point(x - 4, y)) && !WhitePoint.contains(new Point(x + 1, y))) {
BlackPoint.add(Math.random() > 0.5 ? new Point(x - 4, y) : new Point(x + 1, y));
return true;
} else if (WhitePoint.contains(new Point(x - 4, y)) && !WhitePoint.contains(new Point(x + 1, y))) {
return true;
} else if (WhitePoint.contains(new Point(x + 1, y)) && !WhitePoint.contains(new Point(x - 4, y))) {
return true;
}
}
}
return false;

(count == 4) {
if (x - 4 < 0) {
if (!BlackPoint.contains(new Point(x + 1, y)) && !WhitePoint.contains(new Point(x + 1, y))) {
return true;
}
} else if (x + 1 > MAX_LINE - 1) {
if (!BlackPoint.contains(new Point(x - 4, y)) && !WhitePoint.contains(new Point(x - 4, y))) {
return true;
}
}

4.checkFourInLine(WhitePoint)
5.checkBlackTwoOne(BlackPoint)【这就是上面我所说的2202的情况】
6.checkWhiteTwoOne(WhitePoint)

7.checkThreeInLine(WhitePoint)
8.checkBlackThreeInLine(BlackPoint)

9.checkBlackTwoInLine(BlackPoint)
10.checkTwoInLine(WhitePoint)

1.如果白子两两不相连，黑子也两两不相连，白子落完，黑子怎么走？

 private boolean checkOneBlackLeft(ArrayList<Point> point) {
for (Point p : point) {
int x = p.x;
int y = p.y;
if (!WhitePoint.contains(new Point(x - 1, y)) && !BlackPoint.contains(new Point(x - 1, y))) {
return true;
}
}
return false;

 private boolean NoPieceConnect() {
for (int x = 0; x < 15; x++) {
for (int y = 0; y < 15; y++) {
if (!WhitePoint.contains(new Point(x, y)) && !BlackPoint.contains(new Point(x, y))) {
return true;
}
}
}
return false;
}

if (WhitePoint.size() == 1) {
for (Point p : WhitePoint) {
int x = p.x;
int y = p.y;
if (x == 0 || y == 0 || x == MAX_LINE - 1 || y == MAX_LINE - 1) {
BlackPoint.add(new Point(MAX_LINE / 2, MAX_LINE / 2));
} else if (x == MAX_LINE - 1 && y == 0) {
BlackPoint.add(Math.random() > 0.5 ? new Point(x - 1, y) : new Point(x, y + 1));
} else if (x == 0 && y == MAX_LINE - 1) {
BlackPoint.add(Math.random() > 0.5 ? new Point(0, y - 1) : new Point(x + 1, y));
} else if (Math.random() > 0.5) {
BlackPoint.add(Math.random() > 0.5 ? new Point(x + 1, y) : new Point(x - 1, y));
} else {
BlackPoint.add(Math.random() > 0.5 ? new Point(x, y + 1) : new Point(x, y - 1));
}
}

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客