ddebree/game-ai

View on GitHub

Showing 20 of 20 total issues

Method search has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

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.
Open

@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.
Open

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.
    Open

    public void run() {
    checkNotNull(stateReader);
    checkNotNull(nextStateBuilder);
     
    S state = stateReader.get();

      Method runGameLoop has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      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.
        Open

        @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.
        Open

        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.
        Open

        public void run() {
        checkNotNull(stateReader);
        checkNotNull(nextStateBuilder);
         
        S state = stateReader.get();

        Method dfs has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        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.
        Open

        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.
        Open

        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.
        Open

        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.
        Open

        @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.
        Open

        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.
        Open

        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.
          Open

          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.
          Open

          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.
          Open

          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.
          Open

          return true;
          Severity: Major
          Found in board/src/main/java/io/github/ddebree/game/ai/board/geometry/Point.java - About 30 mins to fix

            Method getBestMoves has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            @Nonnull
            @Override
            public Set<M> getBestMoves(@Nonnull final S state, @Nonnull final P playerKey) {
            checkNotNull(state);
            checkNotNull(playerKey);
            Severity
            Category
            Status
            Source
            Language