package de.fhdw.gaming.ipspiel21.dilemmaOriginal.strategy;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import de.fhdw.gaming.core.domain.GameException;
import de.fhdw.gaming.ipspiel21.dilemmaOriginal.domain.DilemmaPlayer;
import de.fhdw.gaming.ipspiel21.dilemmaOriginal.domain.DilemmaState;
import de.fhdw.gaming.ipspiel21.dilemmaOriginal.domain.DilemmaStrategy;
import de.fhdw.gaming.ipspiel21.dilemmaOriginal.moves.DilemmaMove;
import de.fhdw.gaming.ipspiel21.dilemmaOriginal.moves.factory.DilemmaMoveFactory;
import de.fhdw.gaming.ipspiel21.dilemmaOriginal.moves.impl.DilemmaBeSilentMove;
import de.fhdw.gaming.ipspiel21.dilemmaOriginal.moves.impl.DilemmaConfessMove;
/**
* Implements {@link DilemmaStrategy} by saying that what was set before the game started.
*/
public final class DilemmaCustomStrategy implements DilemmaStrategy {
/**
* Constant that represents the identifier when the opponent moves are {@link DilemmaConfessMove) for 100 percent.
*/
private static final String IDENTIFIER_100_CONFESS = new DilemmaConfessMove().toString() + " Numberbased100";
/**
* Constant that represents the identifier when the opponent moves are {@link DilemmaConfessMove) for >50 percent.
*/
private static final String IDENTIFIER_50_CONFESS = new DilemmaConfessMove().toString() + " Numberbased50";
/**
* Constant that represents the identifier when the opponent moves are {@link DilemmaBeSilentMove) for 100 percent.
*/
private static final String IDENTIFIER_100_BESILENT = new DilemmaBeSilentMove().toString() + " Numberbased100";
/**
* Constant that represents the identifier when the opponent moves are {@link DilemmaBeSilentMove) for >50 percent.
*/
private static final String IDENTIFIER_50_BESILENT = new DilemmaBeSilentMove().toString() + " Numberbased50";
/**
* The provided Data.
*/
private Map<String, DilemmaMove> providedMoveData;
/**
* Amount of considered games.
*/
private Integer amountOfGames;
/**
* Default move of player.
*/
private DilemmaMove initialMove;
/**
* The factory for creating Dilemma moves.
*/
private final DilemmaMoveFactory moveFactory;
Perhaps 'moveFactory' could be replaced by a local variable.
Reports fields which may be converted to a local variable. This is so because
in every method where the field is used, it is assigned before it is first read.
Hence, the value that the field had before the method call may not be observed,
so it might as well not be stored in the enclosing object.
Limitations: We can only check private fields for now.
public class Foo {
private int x; // this will be reported
public int foo(int y) {
x = y + 5; // assigned before any read
return x;
}
public int fooOk(int y) {
int z = y + 5; // might as well be a local like here
return z;
}
}