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: 5 C: 19
79%
M: 1 C: 3
75%
M: 1 C: 3
75%
M: 1 C: 4
80%
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.Optional;
4: import java.util.Random;
5:
6: import de.fhdw.gaming.core.domain.GameException;
7: import de.fhdw.gaming.ipspiel23.ht.domain.IHTPlayer;
8: import de.fhdw.gaming.ipspiel23.ht.domain.IHTState;
9: import de.fhdw.gaming.ipspiel23.ht.moves.IHTMove;
10: import de.fhdw.gaming.ipspiel23.ht.moves.factory.IHTMoveFactory;
11: import de.fhdw.gaming.ipspiel23.ht.strategy.impl.HTStrategy;
12:
13: /**
14: *
15: * implements {@link HTStrategy} by choosing one of the three possible answers.
16: *
17: */
18: public class HTMixedStrategy extends HTStrategy {
19:
20: /**
21: * Random to determine the Answer to Choose.
22: */
23: private static final Random RND = new Random();
24:
25: /**
26: * Constructor.
27: *
28: * @param moveFactory moveFactory.
29: */
30: protected HTMixedStrategy(final IHTMoveFactory moveFactory) {
31: super(moveFactory);
32: }
33:
34: @Override
35: public Optional<IHTMove> computeNextMove(final int gameId, final IHTPlayer player, final IHTState state)
36: throws GameException, InterruptedException {
37:• switch (RND.nextInt(3)) {
38: case 0: {
39: return Optional.of(getMoveFactory().createHeadsMove());
40: }
41: case 1: {
42: return Optional.of(getMoveFactory().createTailsMove());
43: }
44: case 2: {
45: return Optional.of(getMoveFactory().createEdgeMove());
46: }
47: default: {
48: throw new IllegalArgumentException("Value has to be in Range: 0-2.");
49: }
50: }
51: }
52: }