Skip to content

Package: DemoGameImpl

DemoGameImpl

nameinstructionbranchcomplexitylinemethod
DemoGameImpl(int, DemoState, Map, long, DemoMoveChecker, ObserverFactoryProvider)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
chooseRandomMove(DemoPlayer, DemoState)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toString()
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * Copyright © 2021-2023 Fachhochschule für die Wirtschaft (FHDW) Hannover
3: *
4: * This file is part of ipspiel23-demo.
5: *
6: * Ipspiel23-demo 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-demo 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-demo. If not, see
14: * <http://www.gnu.org/licenses/>.
15: */
16: package de.fhdw.gaming.ipspiel23.demo.domain.impl;
17:
18: import java.util.Map;
19: import java.util.Optional;
20:
21: import de.fhdw.gaming.core.domain.DefaultGame;
22: import de.fhdw.gaming.core.domain.ObserverFactoryProvider;
23: import de.fhdw.gaming.ipspiel23.demo.domain.DemoGame;
24: import de.fhdw.gaming.ipspiel23.demo.domain.DemoMoveChecker;
25: import de.fhdw.gaming.ipspiel23.demo.domain.DemoPlayer;
26: import de.fhdw.gaming.ipspiel23.demo.domain.DemoState;
27: import de.fhdw.gaming.ipspiel23.demo.domain.DemoStrategy;
28: import de.fhdw.gaming.ipspiel23.demo.moves.DemoMove;
29: import de.fhdw.gaming.ipspiel23.demo.moves.factory.DemoMoveFactory;
30: import de.fhdw.gaming.ipspiel23.demo.moves.impl.DemoDefaultMoveFactory;
31:
32: /**
33: * Implements the Demo game.
34: */
35: final class DemoGameImpl extends DefaultGame<DemoPlayer, DemoState, DemoMove, DemoStrategy> implements DemoGame {
36:
37: /**
38: * The move factory.
39: */
40: private final DemoMoveFactory moveFactory;
41:
42: /**
43: * Creates a Demo 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: DemoGameImpl(final int id, final DemoState initialState, final Map<String, DemoStrategy> strategies,
55: final long maxComputationTimePerMove, final DemoMoveChecker moveChecker,
56: final ObserverFactoryProvider observerFactoryProvider)
57: throws IllegalArgumentException, InterruptedException {
58:
59: super(id, initialState, strategies, maxComputationTimePerMove, moveChecker, observerFactoryProvider);
60: this.moveFactory = new DemoDefaultMoveFactory();
61: }
62:
63: @Override
64: public Optional<DemoMove> chooseRandomMove(final DemoPlayer player, final DemoState state) {
65: // choose "no" to punish lame strategies
66: return Optional.of(this.moveFactory.createNoMove());
67: }
68:
69: @Override
70: public String toString() {
71: return String.format("DemoGame[id=%d, %s]", this.getId(), this.gameToString());
72: }
73: }