Skip to content

Package: VierConnectsField

VierConnectsField

Coverage

1: /*
2: * Copyright © 2021-2023 Fachhochschule für die Wirtschaft (FHDW) Hannover
3: *
4: * This file is part of ipspiel24-VierConnects-core.
5: *
6: * ipspiel24-VierConnects-core is free software: you can redistribute it and/or modify it under
7: * the terms of the GNU General Public License as published by the Free Software
8: * Foundation, either version 3 of the License, or (at your option) any later
9: * version.
10: *
11: * ipspiel24-VierConnects-core is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14: * details.
15: *
16: * You should have received a copy of the GNU General Public License along with
17: * ipspiel24-VierConnects-core. If not, see <http://www.gnu.org/licenses/>.
18: */
19: package de.fhdw.gaming.ipspiel24.VierConnects.core.domain;
20:
21: import de.fhdw.gaming.core.domain.GameException;
22:
23: /**
24: * Represents a single field on a {@link VierConnectsBoard board}.
25: * <p>
26: * A field has a {@link VierConnectsPosition position}. This position is fixed and does not change.
27: * <p>
28: * A field has a {@link VierConnectsFieldState state}. The state may change, but only the following state transitions
29: * are
30: * allowed:
31: * <ul>
32: * <li>{@link VierConnectsFieldState#EMPTY EMPTY} -> {@link VierConnectsFieldState#CROSS CROSS}</li>
33: * <li>{@link VierConnectsFieldState#EMPTY EMPTY} -> {@link VierConnectsFieldState#NOUGHT NOUGHT}</li>
34: * </ul>
35: * In other words, a non-empty field may never change again.
36: * <p>
37: * The state of a field cannot be changed directly. Instead, a conforming move has to be submitted to the rule engine.
38: */
39: public interface VierConnectsField {
40:
41: /**
42: * Returns the board this field belongs to.
43: */
44: VierConnectsBoard getBoard();
45:
46: /**
47: * Returns the position of this field.
48: */
49: VierConnectsPosition getPosition();
50:
51: /**
52: * Returns the current state of this field.
53: */
54: VierConnectsFieldState getState();
55:
56: /**
57: * Determines whether there is a neighbour field in a given direction.
58: *
59: * @param direction The direction to use.
60: * @return {@code true} if there is a neighbour field in the given direction, otherwise {@code false}.
61: */
62: boolean hasNeighbour(VierConnectsDirection direction);
63:
64: /**
65: * Returns a neighbour field in a given direction.
66: *
67: * @param direction The direction to use.
68: * @return The corresponding neighbour field.
69: * @throws IllegalArgumentException if there is no neighbour field in the given direction.
70: */
71: VierConnectsField getNeighbour(VierConnectsDirection direction) throws IllegalArgumentException;
72:
73: /**
74: * Changes the state of this field. Requires this field to be empty.
75: *
76: * @param state The new state of the field.
77: * @throws GameException if placing a token of the given type is not allowed according to the rules of the game.
78: */
79: void changeState(VierConnectsFieldState state) throws GameException;
80: }