Skip to content

Method: mayContainSolution(int)

1: package de.fhdw.gaming.ipspiel23.c4.domain.impl.evaluation;
2:
3: import de.fhdw.gaming.ipspiel23.c4.domain.C4Direction;
4: import de.fhdw.gaming.ipspiel23.c4.domain.impl.C4BoardSlim;
5:
6: /**
7: * Analyzes all diagonal solutions of a board.
8: */
9: public abstract class C4SolutionAnalyzerDiagonal extends C4SolutionAnalyzer {
10:
11: /**
12: * Contains all positions that are not part of a solution.
13: */
14: private final boolean[] isBlacklisted;
15:
16: /**
17: * Creates a new instance of {@link C4SolutionAnalyzerDiagonal}.
18: * @param board The board to be analyzed.
19: * @param searchDirection The search direction to be analyzed.
20: */
21: protected C4SolutionAnalyzerDiagonal(final C4BoardSlim board, final C4Direction searchDirection) {
22: super(board, searchDirection);
23:
24: // viable rows = board.getRowCount() - board.getMinimumSolutionSize() + 1
25: // viable columns = board.getColumnCount() - board.getMinimumSolutionSize()
26: // one less column, because the corner diagonal is included in rows
27: final int capacity = board.getRowCount() + board.getColumnCount() + 1 - 2 * board.getMinimumSolutionSize();
28: isBlacklisted = new boolean[capacity];
29: }
30:
31: /**
32: * Indicates whether a position may be part of a solution.
33: * @param index The index of the position.
34: * @return Whether a position may be part of a solution.
35: */
36: public boolean mayContainSolution(final int index) {
37:• return !isBlacklisted[index];
38: }
39:
40: /**
41: * Marks a position to not be part of a solution.
42: * @param index The index of the position.
43: */
44: public void noSolutionIn(final int index) {
45: isBlacklisted[index] = true;
46: }
47:
48: @Override
49: public void resetCache() {
50: for (int i = 0; i < isBlacklisted.length; i++) {
51: isBlacklisted[i] = false;
52: }
53: }
54: }