Skip to content

Package: DilemmaSuspiciousTitForTatStrategy

DilemmaSuspiciousTitForTatStrategy

nameinstructionbranchcomplexitylinemethod
DilemmaSuspiciousTitForTatStrategy(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: 33
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
requestedMemoryCapacity()
M: 0 C: 4
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.suspicious_tit_for_tat;
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.dilemma.strategy.internals.DilemmaRoundPlayerData;
13: import de.fhdw.gaming.ipspiel23.memory.GameMemoryCapacity;
14: import de.fhdw.gaming.ipspiel23.memory.IGameMemory;
15: import de.fhdw.gaming.ipspiel23.memory.IGameMemoryCapacity;
16:
17: /**
18: * Defects on the first round and imitates the opponent's previous move thereafter.
19: */
20: public class DilemmaSuspiciousTitForTatStrategy extends DilemmaMemoryStrategy {
21:
22: /**
23: * Creates a new instance of the {@link DilemmaSuspiciousTitForTatStrategy} class.
24: * @param moveFactory the move factory to use
25: */
26: protected DilemmaSuspiciousTitForTatStrategy(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) throws GameException, InterruptedException {
33: final IGameMemory<DilemmaRoundData> memory = getMemoryForPlayer(player, state);
34: final IDilemmaMoveFactory moveFactory = getMoveFactory();
35:• if (memory.size() == 0) { // defect for first round
36: return Optional.of(moveFactory.createDefectMove());
37: }
38:
39: // imitate opponents move every other round thereafter
40: final DilemmaRoundData previousRound = memory.getRound(0, true);
41: final DilemmaRoundPlayerData otherPlayersAction = previousRound.forOpponentOf(player);
42: final IDilemmaMove myMove = moveFactory.sameAs(otherPlayersAction.move());
43: return Optional.of(myMove);
44: }
45:
46: @Override
47: protected IGameMemoryCapacity requestedMemoryCapacity() {
48: return GameMemoryCapacity.of(1);
49: }
50: }