Skip to content

Package: IC4Board

IC4Board

Coverage

1: package de.fhdw.gaming.ipspiel23.c4.domain;
2:
3: import java.util.Optional;
4: import java.util.Set;
5:
6: /**
7: * Represents an external facade for object oriented access to the connect four board.
8: */
9: public interface IC4Board extends IC4BoardBase {
10:
11: /**
12: * Retrieves the internal board for usage in performance critical scenarios.
13: */
14: IC4BoardSlim getInternalBoard();
15:
16: /**
17: * Retrieves the field at the specified position.
18: * @param position The position of the field.
19: * @return The field at the specified position, if it exists.
20: */
21: Optional<IC4Field> tryGetField(IC4Position position);
22:
23: /**
24: * Retrieves the field at the specified position.
25: * @param position The position of the field.
26: * @return The field at the specified position.
27: * @throws IndexOutOfBoundsException If the specified position is outside the bounds of the board.
28: */
29: IC4Field getField(IC4Position position);
30:
31: /**
32: * Retrieves all fields of the board in their object representation, not very efficient.
33: * @return All fields of the board.
34: */
35: IC4Field[][] getFields();
36:
37: /**
38: * Lazy evaluation for the first solution, e.g. the first n-in-a-row (where n is the number of
39: * tokens in a row required to win)
40: * @return the first solution, or {@link Optional#empty()} if no solution exists for the current board state
41: */
42: Optional<IC4Solution> tryFindFirstSolution();
43:
44: /**
45: * Eager evaluation for all solutions, e.g. all n-in-a-row (where n is the number of
46: * tokens in a row required to win)
47: * @return all solutions, or an empty set if no solution exists for the current board state
48: */
49: Set<IC4Solution> findAllSolutions();
50:
51: /**
52: * Checks whether the specified position is empty.
53: * @param position The position to check.
54: * @return {@code true} if the specified position is empty, {@code false} otherwise.
55: * @throws IndexOutOfBoundsException If the specified position is outside the bounds of the board.
56: */
57: boolean isEmpty(IC4Position position);
58:
59: /**
60: * Checks whether the specified position is empty.
61: * @param row The row of the position to check.
62: * @param column The column of the position to check.
63: * @return {@code true} if the specified position is empty, {@code false} otherwise.
64: * @throws IndexOutOfBoundsException If the specified position is outside the bounds of the board.
65: */
66: boolean isEmpty(int row, int column);
67:
68: /**
69: * Performs a bound check on the specified position.
70: * @param position The position to check.
71: * @return {@code true} if the specified position lies within the bounds of the board, {@code false} otherwise.
72: */
73: boolean checkBounds(IC4Position position);
74:
75: /**
76: * Checks whether the specified position is "solid" while respecting the bounds of the board.
77: * A position is solid if it occupied by a player, or if is one row below the bottom row (i.e., it is the "floor")
78: * @param position The position to check.
79: * @return {@code true} if the specified position is solid, {@code false} otherwise.
80: * @throws IndexOutOfBoundsException If the specified position is outside the bounds of the board.
81: */
82: boolean isSolid(IC4Position position);
83:
84: /**
85: * Checks whether the specified position is "solid" while respecting the bounds of the board.
86: * A position is solid if it occupied by a player, or if is one row below the bottom row (i.e., it is the "floor")
87: * @param row The row of the position to check.
88: * @param column The column of the position to check.
89: * @return {@code true} if the specified position is solid, {@code false} otherwise.
90: * @throws IndexOutOfBoundsException If the specified position is outside the bounds of the board.
91: */
92: boolean isSolid(int row, int column);
93:
94: /**
95: * Retrieves the player occupying the specified position, or {@link Optional#empty()} if the position is empty.
96: * @param position The position to check.
97: * @return The player occupying the specified position, or {@link Optional#empty()} if the position is empty.
98: * @throws IndexOutOfBoundsException If the specified position is outside the bounds of the board.
99: */
100: Optional<IC4Player> getOccupyingPlayerOrDefault(IC4Position position);
101:
102: /**
103: * Enumerates all empty positions of the board.
104: * @return All empty positions of the board.
105: */
106: IC4Position[] getEmptyPositions();
107:
108: /**
109: * Enumerates all positions occupied by the specified player.
110: * @param player The player to check.
111: * @return All positions occupied by the specified player.
112: */
113: IC4Position[] getPositionsByPlayer(IC4Player player);
114:
115: /**
116: * Enumerates all legal positions of the board where a token can be placed.
117: * @return All legal positions of the board.
118: */
119: IC4Position[] getLegalPositions();
120:
121: /**
122: * Counts the number of empty positions on the board.
123: * @return The number of empty positions on the board.
124: */
125: int countEmptyPositions();
126:
127: /**
128: * Counts the number of positions occupied by the specified player.
129: * @param player The player to check.
130: * @return The number of positions occupied by the specified player.
131: */
132: int countPositionsByPlayer(IC4Player player);
133:
134: /**
135: * Counts the number of legal positions on the board where a token can be placed.
136: * @return The number of legal positions on the board.
137: */
138: int countLegalPositions();
139:
140: @Override
141: IC4Board deepCopy();
142: }