Method search
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
public List<N> search(GraphFactory<N> graphFactory, N sourceNode, N goalNode) {
final Map<N, Double> gScore = new HashMap<>();
final Map<N, Double> fScore = new HashMap<>();
final Map<N, N> parentNode = new HashMap<>();
Method pickAMove
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
@Nonnull
public M pickAMove(S state, Set<M> bestMovesSet) {
List<M> bestMoves = Lists.newArrayList(bestMovesSet);
if (bestMoves.isEmpty()) {
throw new RuntimeException("No moves to select from!");
Method search
has 37 lines of code (exceeds 25 allowed). Consider refactoring.
public List<N> search(GraphFactory<N> graphFactory, N sourceNode, N goalNode) {
final Map<N, Double> gScore = new HashMap<>();
final Map<N, Double> fScore = new HashMap<>();
final Map<N, N> parentNode = new HashMap<>();
Method run
has 33 lines of code (exceeds 25 allowed). Consider refactoring.
public void run() {
checkNotNull(stateReader);
checkNotNull(nextStateBuilder);
S state = stateReader.get();
Method runGameLoop
has 28 lines of code (exceeds 25 allowed). Consider refactoring.
protected void runGameLoop(S state) {
int round = 0;
while ( ! gameOverTester.isGameOver(state)) {
round++;
Method search
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
@Override
public List<N> search(GraphFactory<N> graphFactory, N sourceNode, N targetNode) {
Set<N> visited = new HashSet<>();
Queue<N> queue = new LinkedList<>();
Map<N, N> parentNodes = new HashMap<>();
Method searchDelegate
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
private List<N> searchDelegate(GraphFactory<N> graphFactory, Set<N> visited, N currentNode, N endNode) {
for (N childNode : graphFactory.getSuccessors(currentNode)) {
if (childNode.equals(endNode)) {
return ImmutableList.of(endNode);
}
Method run
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
public void run() {
checkNotNull(stateReader);
checkNotNull(nextStateBuilder);
S state = stateReader.get();
Method dfs
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
private boolean dfs(GraphFactory<N> graphFactory, N sourceVertex, N targetVertex, int depthLevel, Map<N, N> parentNodes) {
Stack<N> stack = new Stack<>();
stack.push(sourceVertex);
Map<N, Integer> depths = new HashMap<>();
Similar blocks of code found in 3 locations. Consider refactoring.
public Direction oppositeDirection() {
switch (this) {
case UP: return DOWN;
case DOWN: return UP;
case LEFT: return RIGHT;
board/src/main/java/io/github/ddebree/game/ai/board/geometry/Direction.java on lines 64..72 board/src/main/java/io/github/ddebree/game/ai/board/geometry/Direction.java on lines 74..82 Similar blocks of code found in 3 locations. Consider refactoring.
public Direction leftTurnDirection() {
switch (this) {
case UP: return LEFT;
case DOWN: return RIGHT;
case LEFT: return DOWN;
board/src/main/java/io/github/ddebree/game/ai/board/geometry/Direction.java on lines 54..62 board/src/main/java/io/github/ddebree/game/ai/board/geometry/Direction.java on lines 74..82 Similar blocks of code found in 3 locations. Consider refactoring.
public Direction rightTurnDirection() {
switch (this) {
case UP: return RIGHT;
case DOWN: return LEFT;
case LEFT: return UP;
board/src/main/java/io/github/ddebree/game/ai/board/geometry/Direction.java on lines 54..62 board/src/main/java/io/github/ddebree/game/ai/board/geometry/Direction.java on lines 64..72 Similar blocks of code found in 2 locations. Consider refactoring.
@Override
public int scoreState(State state, TwoPlayerKey twoPlayer) {
Optional<TwoPlayerKey> winner = gameOverTester.getWinner(state);
if (winner.isPresent()) {
return winner.get() == twoPlayer ? +1 : -1;
core/src/main/java/io/github/ddebree/game/ai/core/strategy/minmax/MinMaxStrategy.java on lines 90..96 Similar blocks of code found in 2 locations. Consider refactoring.
private int scoreState(S state, TwoPlayerKey maximizingPlayer) {
Optional<TwoPlayerKey> winner = gameOverTester.getWinner(state);
if (winner.isPresent()) {
return winner.get() == maximizingPlayer ? +1 : -1;
}
tictactoe/src/main/java/io/github/ddebree/game/ai/tictactoe/StateScorer.java on lines 13..20 Method dfs
has 5 arguments (exceeds 4 allowed). Consider refactoring.
private boolean dfs(GraphFactory<N> graphFactory, N sourceVertex, N targetVertex, int depthLevel, Map<N, N> parentNodes) {
Method findMaximumSolution
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
public S findMaximumSolution(ToDoubleFunction<S> temperatureFunction) {
double temperature = startTemperature;
S currentBest = initialState;
double currentTemperature = temperatureFunction.applyAsDouble(currentBest);
Similar blocks of code found in 2 locations. Consider refactoring.
public MinMaxStrategy(@Nonnull IMoveFactory<S, TwoPlayerKey, M> moveFactory,
@Nonnull IGameOverTester<S, TwoPlayerKey> gameOverTester,
@Nonnull INextStateBuilder<S, TwoPlayerKey, M> nextStateBuilder) {
this.moveFactory = checkNotNull(moveFactory);
this.gameOverTester = checkNotNull(gameOverTester);
core/src/main/java/io/github/ddebree/game/ai/core/strategy/score/SimpleScoreStrategy.java on lines 33..39 Similar blocks of code found in 2 locations. Consider refactoring.
public SimpleScoreStrategy(@Nonnull final IMoveFactory<S, P, M> moveFactory,
@Nonnull final IStateScorer<S, P> stateScorer,
@Nonnull final INextStateBuilder<S, P, M> nextStateFactory) {
this.moveFactory = checkNotNull(moveFactory);
this.nextStateFactory = checkNotNull(nextStateFactory);
core/src/main/java/io/github/ddebree/game/ai/core/strategy/minmax/MinMaxStrategy.java on lines 30..36 Avoid too many return
statements within this method.
return true;
Method getBestMoves
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
@Nonnull
@Override
public Set<M> getBestMoves(@Nonnull final S state, @Nonnull final P playerKey) {
checkNotNull(state);
checkNotNull(playerKey);