-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntelligence.pde
85 lines (69 loc) · 2.18 KB
/
Intelligence.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
public class Intelligence {
Intelligence() {
}
void step(Cell[][] cells) {
flagObvious(cells);
if (!removeFull(cells)) {
Cell lltbc = lessLikelyToBeBombCell(cells);
lltbc.uncover();
}
}
void flagObvious(Cell[][] cells) {
for (Cell myCell : allUncoveredCells(cells)) {
if (myCell.isFullOfMines(cells)) {
for (Cell toFlagCell : myCell.surroundingCoveredCells(cells)) {
toFlagCell.flag();
}
}
}
}
boolean removeFull(Cell[][] cells) {
boolean removedSomething = false;
for (Cell myCell : allUncoveredCells(cells)) {
if (myCell.isFull(cells)) {
for (Cell toUncoverCell : myCell.surroundingCoveredAndNotFlaggedCells(cells)) {
toUncoverCell.uncover();
removedSomething =true;
}
}
}
return removedSomething;
}
boolean anyFullCell(ArrayList<Cell> surrCells, Cell[][] cells) {
for (Cell myCell : surrCells) {
if (myCell.cantTouchingBombs() == myCell.surroundingCoveredCells(cells).size()) return true;
}
return false;
}
Cell lessLikelyToBeBombCell(Cell[][] cells) {
Cell lessLikelyCell = randomCoveredCell(cells);
//for (Cell myCell : allCoveredCells(cells)) {
// if (myCell.probabilityToBeBomb(cells) < lessLikelyCell.probabilityToBeBomb(cells)) lessLikelyCell = myCell;
//}
return lessLikelyCell;
}
Cell randomCoveredCell(Cell[][] cells) {
ArrayList<Cell> covCells = allCoveredCells(cells);
return covCells.get(int(random(covCells.size())));
}
ArrayList<Cell> allCoveredCells(Cell[][] cells) {
ArrayList<Cell> coveredCells= new ArrayList();
for (int i = 0; i < xCells; i++) {
for (int j = 0; j < yCells; j++) {
Cell cell = cells[i][j];
if (!cell.isUncovered() && !cell.flagged) coveredCells.add(cell);
}
}
return coveredCells;
}
ArrayList<Cell> allUncoveredCells(Cell[][] cells) {
ArrayList<Cell> uncoveredCells= new ArrayList();
for (int i = 0; i < xCells; i++) {
for (int j = 0; j < yCells; j++) {
Cell cell = cells[i][j];
if (cell.isUncovered()) uncoveredCells.add(cell);
}
}
return uncoveredCells;
}
}