Skip to content

Package: KopfundZahlundKanteRandomStrategy

KopfundZahlundKanteRandomStrategy

nameinstructionbranchcomplexitylinemethod
KopfundZahlundKanteRandomStrategy(KopfundZahlundKanteMoveFactory)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
computeNextMove(int, KopfundZahlundKantePlayer, KopfundZahlundKanteState)
M: 10 C: 16
62%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 2 C: 4
67%
M: 0 C: 1
100%
toString()
M: 0 C: 3
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.ipspiel22.kopfundzahlundkante.strategy;
2:
3: import java.util.Optional;
4:
5: import de.fhdw.gaming.core.domain.GameException;
6: import de.fhdw.gaming.ipspiel22.kopfundzahlundkante.domain.KopfundZahlundKantePlayer;
7: import de.fhdw.gaming.ipspiel22.kopfundzahlundkante.domain.KopfundZahlundKanteState;
8: import de.fhdw.gaming.ipspiel22.kopfundzahlundkante.domain.KopfundZahlundKanteStrategy;
9: import de.fhdw.gaming.ipspiel22.kopfundzahlundkante.moves.KopfundZahlundKanteMove;
10: import de.fhdw.gaming.ipspiel22.kopfundzahlundkante.moves.factory.KopfundZahlundKanteMoveFactory;
11:
12: /**
13: * Implements {@link KopfundZahlundKanteStrategy} by choose random between "Head","Tail" and "Edge".
14: */
15: public final class KopfundZahlundKanteRandomStrategy implements KopfundZahlundKanteStrategy {
16:
17: /**
18: * The factory for creating KopfundZahl moves.
19: */
20: private final KopfundZahlundKanteMoveFactory moveFactory;
21:
22: /**
23: * Creates an {@link KopfundZahlundKanteRandomStrategy}.
24: *
25: * @param moveFactory The factory for creating KopfundZahl moves.
26: */
27: KopfundZahlundKanteRandomStrategy(final KopfundZahlundKanteMoveFactory moveFactory) {
28: this.moveFactory = moveFactory;
29: }
30:
31: @Override
32: public Optional<KopfundZahlundKanteMove> computeNextMove(final int gameId, final KopfundZahlundKantePlayer player,
33: final KopfundZahlundKanteState state)
34: throws GameException, InterruptedException {
35: final int value = (int) (Math.random() * 3);
36:• if (value == 1) {
37: return Optional.of(this.moveFactory.createHeadMove());
38:• } else if (value == 2) {
39: return Optional.of(this.moveFactory.createTailMove());
40: } else {
41: return Optional.of(this.moveFactory.createEdgeMove());
42: }
43: }
44:
45: @Override
46: public String toString() {
47: return KopfundZahlundKanteRandomStrategy.class.getSimpleName();
48: }
49:
50: }