Package: KopfundZahlundKanteRandomStrategy
KopfundZahlundKanteRandomStrategy
| name | instruction | branch | complexity | line | method | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| KopfundZahlundKanteRandomStrategy(KopfundZahlundKanteMoveFactory) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| computeNextMove(int, KopfundZahlundKantePlayer, KopfundZahlundKanteState) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| toString() | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
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: }