Skip to content

Package: HTMixedStrategy

HTMixedStrategy

nameinstructionbranchcomplexitylinemethod
HTMixedStrategy(IHTMoveFactory)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
computeNextMove(int, IHTPlayer, IHTState)
M: 0 C: 43
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
static {...}
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%

Coverage

1: package de.fhdw.gaming.ipspiel23.ht.strategy.impl.mixed;
2:
3: import java.util.ArrayList;
4: import java.util.List;
5: import java.util.Optional;
6: import java.util.Random;
7: import java.util.function.Supplier;
8:
9: import de.fhdw.gaming.core.domain.GameException;
10: import de.fhdw.gaming.ipspiel23.ht.domain.IHTPlayer;
11: import de.fhdw.gaming.ipspiel23.ht.domain.IHTState;
12: import de.fhdw.gaming.ipspiel23.ht.moves.IHTMove;
13: import de.fhdw.gaming.ipspiel23.ht.moves.factory.IHTMoveFactory;
14: import de.fhdw.gaming.ipspiel23.ht.strategy.impl.HTStrategy;
15:
16: /**
17: *
18: * implements {@link HTStrategy} by choosing one of the three possible answers.
19: *
20: */
21: public class HTMixedStrategy extends HTStrategy {
22:
23: /**
24: * Random to determine the Answer to Choose.
25: */
26: private static final Random RANDOM = new Random();
27:
28: /**
29: * Constructor.
30: *
31: * @param moveFactory moveFactory.
32: */
33: protected HTMixedStrategy(final IHTMoveFactory moveFactory) {
34: super(moveFactory);
35: }
36:
37: @Override
38: public Optional<IHTMove> computeNextMove(final int gameId, final IHTPlayer player, final IHTState state)
39: throws GameException, InterruptedException {
40: final IHTMoveFactory moveFactory = this.getMoveFactory();
41: final List<Supplier<IHTMove>> moveSuppliers = new ArrayList<>(3);
42: moveSuppliers.add(moveFactory::createHeadsMove);
43: moveSuppliers.add(moveFactory::createTailsMove);
44: moveSuppliers.add(moveFactory::createEdgeMove);
45: return Optional.of(moveSuppliers.get(RANDOM.nextInt(moveSuppliers.size())).get());
46: }
47: }