Skip to contentMethod: FzgGameImpl(int, FzgState, Map, long, MoveChecker, ObserverFactoryProvider)
      1: package de.fhdw.gaming.ipspiel23.freizeitgestaltung.domain.impl;
2: 
3: import java.util.Map;
4: import java.util.Optional;
5: import java.util.concurrent.ThreadLocalRandom;
6: 
7: import de.fhdw.gaming.core.domain.DefaultGame;
8: import de.fhdw.gaming.core.domain.MoveChecker;
9: import de.fhdw.gaming.core.domain.ObserverFactoryProvider;
10: import de.fhdw.gaming.ipspiel23.freizeitgestaltung.domain.FzgGame;
11: import de.fhdw.gaming.ipspiel23.freizeitgestaltung.domain.FzgPlayer;
12: import de.fhdw.gaming.ipspiel23.freizeitgestaltung.domain.FzgState;
13: import de.fhdw.gaming.ipspiel23.freizeitgestaltung.domain.FzgStrategy;
14: import de.fhdw.gaming.ipspiel23.freizeitgestaltung.move.Answer;
15: import de.fhdw.gaming.ipspiel23.freizeitgestaltung.move.factory.AnswerFactory;
16: import de.fhdw.gaming.ipspiel23.freizeitgestaltung.move.impl.AnswerFactoryImpl;
17: 
18: /**
19:  * Implements {@link FzgGame}.
20:  *
21:  */
22: public class FzgGameImpl extends DefaultGame<FzgPlayer, FzgState, Answer, FzgStrategy> implements FzgGame {
23: 
24:     /**
25:      * AnswerFactory.
26:      */
27:     private final AnswerFactory answerFactory;
28: 
29:     /**
30:      * Constructor, creates a FzgGame.
31:      * 
32:      * @param id                        The ID of this game.
33:      * @param initialState              The initial state of the game.
34:      * @param strategies                The players' strategies.
35:      * @param maxComputationTimePerMove The maximum computation time per move in seconds.
36:      * @param moveChecker               The move checker.
37:      * @param observerFactoryProvider   The {@link ObserverFactoryProvider}.
38:      * @throws IllegalArgumentException if the player sets do not match.
39:      * @throws InterruptedException     if creating the game has been interrupted.
40:      */
41:     public FzgGameImpl(final int id, final FzgState initialState, final Map<String, FzgStrategy> strategies,
42:             final long maxComputationTimePerMove,
43:             final MoveChecker<FzgPlayer, FzgState, Answer> moveChecker,
44:             final ObserverFactoryProvider observerFactoryProvider)
45:             throws IllegalArgumentException, InterruptedException {
46:         super(id, initialState, strategies, maxComputationTimePerMove, moveChecker, observerFactoryProvider);
47:         this.answerFactory = new AnswerFactoryImpl();
48:     }
49: 
50:     @Override
51:     public Optional<Answer> chooseRandomMove(final FzgPlayer player, final FzgState state) {
52:         // 50/50 if Cinema or Football.
53:         // No specific strategy chosen, as one player is not trying to compete against the other.
54:         if (ThreadLocalRandom.current().nextBoolean()) {
55:             return Optional.of(this.answerFactory.createCinemaAnswer());
56:         }
57:         return Optional.of(this.answerFactory.createFootballAnswer());
58:     }
59: 
60:     @Override
61:     public String toString() {
62:         return String.format("FzgGame[id=%d, %s]", this.getId(), this.gameToString());
63:     }
64: }