Package: FGmixedFootballStrategy
FGmixedFootballStrategy
| name | instruction | branch | complexity | line | method | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| FGmixedFootballStrategy(FGMoveFactory) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| computeNextMove(int, FGPlayer, FGState, long) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| toString() | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
Coverage
1: 
2: package de.fhdw.gaming.ipspiel24.fg.strategy;
3: 
4: import java.security.SecureRandom;
5: import java.util.Optional;
6: 
7: import de.fhdw.gaming.ipspiel24.fg.domain.FGPlayer;
8: import de.fhdw.gaming.ipspiel24.fg.domain.FGState;
9: import de.fhdw.gaming.ipspiel24.fg.domain.FGStrategy;
10: import de.fhdw.gaming.ipspiel24.fg.moves.FGMove;
11: import de.fhdw.gaming.ipspiel24.fg.moves.factory.FGMoveFactory;
12: 
13: /**
14:  * Implements {@link FGStrategy} by always saying "no".
15:  */
16: public final class FGmixedFootballStrategy implements FGStrategy {
17: 
18:     /**
19:      * The factory for creating FG moves.
20:      */
21:     private final FGMoveFactory moveFactory;
22:     /**
23:      * Generates random numbers.
24:      */
25:     private final SecureRandom random;
26: 
27:     /**
28:      * Creates an {@link FGmixedFootballStrategy}.
29:      *
30:      * @param moveFactory The factory for creating FG moves.
31:      */
32:     FGmixedFootballStrategy(final FGMoveFactory moveFactory) {
33:         this.moveFactory = moveFactory;
34:         this.random = new SecureRandom();
35:     }
36: 
37:     @Override
38:     public Optional<FGMove> computeNextMove(
39:             final int gameId,
40:             final FGPlayer player,
41:             final FGState state,
42:             final long maxComputationTimePerMove) {
43:•        if (this.random.nextInt(3) < 2) {
44:             return Optional.of(this.moveFactory.createFootballMove());
45:         }
46:         return Optional.of(this.moveFactory.createCinemaMove());
47:     }
48: 
49:     @Override
50:     public String toString() {
51:         return FGmixedFootballStrategy.class.getSimpleName();
52:     }
53: }