Package: FGmixedMoveStrategy
FGmixedMoveStrategy
| name | instruction | branch | complexity | line | method | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| FGmixedMoveStrategy(FGMoveFactory) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| computeNextMove(int, FGPlayer, FGState, long) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| toString() | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
Coverage
1: package de.fhdw.gaming.ipspiel24.fg.strategy;
2: 
3: import java.security.SecureRandom;
4: import java.util.Optional;
5: 
6: import de.fhdw.gaming.core.domain.GameException;
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:  * Strategy to pick Random Move.
15:  */
16: public class FGmixedMoveStrategy implements FGStrategy {
17:     /**
18:      * MoveFactory.
19:      */
20:     private final FGMoveFactory moveFactory;
21:     /**
22:      * New SecureRandom to generate Random Move.
23:      */
24:     private final SecureRandom random;
25:     /**
26:      * Creates an {@link FGFootballStrategy}.
27:      *
28:      * @param moveFactory The factory for creating FG moves.
29:      */
30:     FGmixedMoveStrategy(final FGMoveFactory moveFactory) {
31:         this.moveFactory = moveFactory;
32:         this.random = new SecureRandom();
33:     }
34:     
35:     @Override
36:     public Optional<FGMove> computeNextMove(final int gameId, final FGPlayer player,
37:             final FGState state, final long maxComputationTimePerMove)
38:             throws GameException, InterruptedException {
39:         final double rand = random.nextInt(3);
40:•        if (state.getFirstPlayer().equals(player)) {
41:•            if (rand < 2) {
42:                 return Optional.of(this.moveFactory.createFootballMove());
43:             } else {
44:                 return Optional.of(this.moveFactory.createCinemaMove()); 
45:             }
46:         } else {
47:•            if (rand >= 2) {
48:                 return Optional.of(this.moveFactory.createFootballMove());
49:             } else {
50:                 return Optional.of(this.moveFactory.createCinemaMove()); 
51:             }
52:         }
53:     }
54: 
55:     
56:     @Override
57:     public String toString() {
58:         return FGmixedMoveStrategy.class.getSimpleName();
59:     }
60: }