Skip to content

Package: Player

Player

Coverage

1: /*
2: * Copyright © 2020 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.Optional;
22:
23: /**
24: * Represents a player, i.e.some participant of the game that acts for itself
25: * and aims at winning the game. It does not necessarily have to be a human.
26: * <p>
27: * Note that CRTP (Curiously Recurring Template Pattern) is used to retain the
28: * subtype of the player. This allows clients to clone a player via
29: * {@link #deepCopy()} while retaining its type at compile-time.
30: *
31: * @param <P> The type of allowed players.
32: */
33: public interface Player<P extends Player<P>> extends Stateful {
34:
35: /**
36: * Returns the name of this player.
37: */
38: String getName();
39:
40: /**
41: * Returns the state of this player.
42: */
43: PlayerState getState();
44:
45: /**
46: * Changes the state of this player. If the new state is
47: * {@link PlayerState#PLAYING}, any outcome previously set by calling
48: * {@link #setOutcome(double)} is removed.
49: *
50: * @param newState The new state.
51: */
52: void setState(PlayerState newState);
53:
54: /**
55: * Returns the outcome of this player (if available). The outcome is unavailable
56: * if the player is in the state {@link PlayerState#PLAYING}. Otherwise, if no
57: * outcome has been set, the outcome shall be computed from the player's state by calling
58: * {@link AbstractPlayer#mapStateToOutcome(PlayerState)}.
59: */
60: Optional<Double> getOutcome();
61:
62: /**
63: * Sets the outcome of this player. Requires that this player's state is not
64: * {@link PlayerState#PLAYING}.
65: *
66: * @param newOutcome The new outcome.
67: * @throws IllegalStateException if this player is in the state {@link PlayerState#PLAYING}.
68: */
69: void setOutcome(double newOutcome);
70:
71: @Override
72: P deepCopy();
73: }