Skip to content

Package: State

State

Coverage

1: /*
2: * Copyright © 2020-2023 Fachhochschule für die Wirtschaft (FHDW) Hannover
3: *
4: * This file is part of gaming-core.
5: *
6: * Gaming-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: * Gaming-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: * gaming-core. If not, see <http://www.gnu.org/licenses/>.
18: */
19: package de.fhdw.gaming.core.domain;
20:
21: import java.util.Map;
22: import java.util.Set;
23:
24: /**
25: * Represents the state of a game.
26: * <p>
27: * Note that CRTP (Curiously Recurring Template Pattern) is used to retain the
28: * subtype of the state. This allows clients to clone a state via
29: * {@link #deepCopy()} while retaining its type at compile-time.
30: *
31: * @param <P> The type of allowed players.
32: * @param <S> The type of game states.
33: */
34: public interface State<P extends Player<P>, S extends State<P, S>> extends Stateful {
35:
36: /**
37: * Returns all the players of the game.
38: */
39: Map<String, P> getPlayers();
40:
41: /**
42: * Computes the set of players being able to do the next move.
43: *
44: * @return A set of players that can act next (possibly in parallel). Can be
45: * empty if no players have remained.
46: */
47: Set<P> computeNextPlayers();
48:
49: /**
50: * This operation is called after each move and also if no valid move has been
51: * found for the set of currently active players.
52: */
53: void nextTurn();
54:
55: @Override
56: S deepCopy();
57: }