Skip to content

Package: DilemmaPavlovStrategy

DilemmaPavlovStrategy

nameinstructionbranchcomplexitylinemethod
DilemmaPavlovStrategy(IDilemmaMoveFactory)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
computeNextMove(int, IDilemmaPlayer, IDilemmaState)
M: 0 C: 36
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
requestedMemoryCapacity()
M: 0 C: 2
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.ipspiel23.dilemma.strategy.internals.pavlov;
2:
3: import java.util.Optional;
4:
5: import de.fhdw.gaming.core.domain.GameException;
6: import de.fhdw.gaming.ipspiel23.dilemma.domain.IDilemmaPlayer;
7: import de.fhdw.gaming.ipspiel23.dilemma.domain.IDilemmaState;
8: import de.fhdw.gaming.ipspiel23.dilemma.moves.IDilemmaMove;
9: import de.fhdw.gaming.ipspiel23.dilemma.moves.IDilemmaMoveFactory;
10: import de.fhdw.gaming.ipspiel23.dilemma.strategy.internals.DilemmaMemoryStrategy;
11: import de.fhdw.gaming.ipspiel23.dilemma.strategy.internals.DilemmaRoundData;
12: import de.fhdw.gaming.ipspiel23.memory.GameMemoryCapacity;
13: import de.fhdw.gaming.ipspiel23.memory.IGameMemory;
14: import de.fhdw.gaming.ipspiel23.memory.IGameMemoryCapacity;
15:
16: /**
17: * Cooperates if it and its opponent moved alike in previous move and defects if they moved differently.
18: */
19: public class DilemmaPavlovStrategy extends DilemmaMemoryStrategy {
20:
21: /**
22: * Creates a new instance of the {@link DilemmaPavlovStrategy} class using the given {@link IDilemmaMoveFactory}.
23: *
24: * @param moveFactory the move factory to use
25: */
26: protected DilemmaPavlovStrategy(final IDilemmaMoveFactory moveFactory) {
27: super(moveFactory);
28: }
29:
30: @Override
31: public Optional<IDilemmaMove> computeNextMove(final int gameId, final IDilemmaPlayer player,
32: final IDilemmaState state)
33: throws GameException, InterruptedException {
34: final IGameMemory<DilemmaRoundData> memory = getMemoryForPlayer(player, state);
35: final IDilemmaMoveFactory moveFactory = getMoveFactory();
36: // let's be nice on the first round ...
37:• if (memory.size() == 0) {
38: return Optional.of(moveFactory.createCooperateMove());
39: }
40: final DilemmaRoundData previousRound = memory.getRound(0, true);
41: // ... and cooperates if our opponent moved alike in previous move, otherwise defect if they moved differently.
42: return Optional.of(
43:• previousRound.player1Data().answer().equals(previousRound.player2Data().answer())
44: ? moveFactory.createCooperateMove()
45: : moveFactory.createDefectMove());
46: }
47:
48: @Override
49: protected IGameMemoryCapacity requestedMemoryCapacity() {
50: return GameMemoryCapacity.unlimited();
51: }
52: }