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<>();

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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!");

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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<>();

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        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);
                    }

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        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();

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        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<>();

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        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

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 51.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        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

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 51.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        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

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 51.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        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

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 49.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        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

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 49.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        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);

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          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

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 44.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          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

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 44.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          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);

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Severity
            Category
            Status
            Source
            Language