Package: GDRandomStrategy
GDRandomStrategy
| name | instruction | branch | complexity | line | method | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| GDRandomStrategy(GDMoveFactory) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| computeNextMove(int, GDPlayer, GDState, long) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| toString() | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
Coverage
1: /*
2:  * Copyright © 2021-2023 Fachhochschule für die Wirtschaft (FHDW) Hannover
3:  *
4:  * This file is part of ipspiel24-GD.
5:  *
6:  * ipspiel24-GD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
7:  * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
8:  * version.
9:  *
10:  * ipspiel24-GD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
11:  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12:  *
13:  * You should have received a copy of the GNU General Public License along with ipspiel24-GD. If not, see
14:  * <http://www.gnu.org/licenses/>.
15:  */
16: package de.fhdw.gaming.GefangenenDilemma.strategy;
17: 
18: import java.util.Optional;
19: 
20: import de.fhdw.gaming.GefangenenDilemma.domain.GDPlayer;
21: import de.fhdw.gaming.GefangenenDilemma.domain.GDState;
22: import de.fhdw.gaming.GefangenenDilemma.domain.GDStrategy;
23: import de.fhdw.gaming.GefangenenDilemma.moves.GDMove;
24: import de.fhdw.gaming.GefangenenDilemma.moves.factory.GDMoveFactory;
25: 
26: /**
27:  * Implements {@link GDStrategy} by always saying "yes".
28:  */
29: public final class GDRandomStrategy implements GDStrategy {
30: 
31:     /**
32:      * The factory for creating Gefangenen-Dilemma moves.
33:      */
34:     private final GDMoveFactory moveFactory;
35: 
36:     /**
37:      * Creates an {@link GDRandomStrategy}.
38:      *
39:      * @param moveFactory The factory for creating Gefangenen-Dilemma moves.
40:      */
41:     GDRandomStrategy(final GDMoveFactory moveFactory) {
42:         this.moveFactory = moveFactory;
43:     }
44: 
45:     @Override
46:     public Optional<GDMove> computeNextMove(
47:             final int gameId,
48:             final GDPlayer player,
49:             final GDState state,
50:             final long maxComputationTimePerMove) {
51: 
52:         return Optional.of(this.moveFactory.createRandomMove());
53: 
54:     }
55: 
56:     @Override
57:     public String toString() {
58:         return GDRandomStrategy.class.getSimpleName();
59:     }
60: }