Skip to content

Method: toString()

1: /*
2: * Copyright © 2021-2023 Fachhochschule für die Wirtschaft (FHDW) Hannover
3: *
4: * This file is part of ipspiel23-Ssp.
5: *
6: * Ipspiel23-Ssp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
7: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
8: * version.
9: *
10: * Ipspiel23-Ssp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
11: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12: *
13: * You should have received a copy of the GNU General Public License along with ipspiel23-Ssp. If not, see
14: * <http://www.gnu.org/licenses/>.
15: */
16: package de.fhdw.gaming.ipspiel23.ssp.domain.impl;
17:
18: import de.fhdw.gaming.core.domain.DefaultGame;
19: import de.fhdw.gaming.core.domain.ObserverFactoryProvider;
20: import de.fhdw.gaming.ipspiel23.ssp.domain.SspGame;
21: import de.fhdw.gaming.ipspiel23.ssp.domain.SspMoveChecker;
22: import de.fhdw.gaming.ipspiel23.ssp.domain.SspPlayer;
23: import de.fhdw.gaming.ipspiel23.ssp.domain.SspState;
24: import de.fhdw.gaming.ipspiel23.ssp.domain.SspStrategy;
25: import de.fhdw.gaming.ipspiel23.ssp.moves.SspMove;
26: import de.fhdw.gaming.ipspiel23.ssp.moves.factory.SspMoveFactory;
27: import de.fhdw.gaming.ipspiel23.ssp.moves.impl.SspDefaultMoveFactory;
28:
29: import java.util.Map;
30: import java.util.Optional;
31:
32: /**
33: * Implements the SSP game.
34: */
35: final class SspGameImpl extends DefaultGame<SspPlayer, SspState, SspMove, SspStrategy> implements SspGame {
36:
37: /**
38: * The move factory.
39: */
40: private final SspMoveFactory moveFactory;
41:
42: /**
43: * Creates a Ssp game.
44: *
45: * @param id The ID of this game.
46: * @param initialState The initial state of the game.
47: * @param strategies The players' strategies.
48: * @param maxComputationTimePerMove The maximum computation time per move in seconds.
49: * @param moveChecker The move checker.
50: * @param observerFactoryProvider The {@link ObserverFactoryProvider}.
51: * @throws IllegalArgumentException if the player sets do not match.
52: * @throws InterruptedException if creating the game has been interrupted.
53: */
54: SspGameImpl(final int id, final SspState initialState, final Map<String, SspStrategy> strategies,
55: final long maxComputationTimePerMove, final SspMoveChecker moveChecker,
56: final ObserverFactoryProvider observerFactoryProvider)
57: throws IllegalArgumentException, InterruptedException {
58:
59: super(id, initialState, strategies, maxComputationTimePerMove, moveChecker, observerFactoryProvider);
60: this.moveFactory = new SspDefaultMoveFactory();
61: }
62:
63: @Override
64: public Optional<SspMove> chooseRandomMove(final SspPlayer player, final SspState state) {
65: // Since all moves are equally good, just take stone...
66: return Optional.of(this.moveFactory.createStoneMove());
67: }
68:
69: @Override
70: public String toString() {
71: return String.format("SspGame[id=%d, %s]", this.getId(), this.gameToString());
72: }
73: }