ocadotechnology/rapid-router

View on GitHub
game/random_road.py

Summary

Maintainability
F
5 days
Test Coverage

Function generate_random_path has a Cognitive Complexity of 92 (exceeds 5 allowed). Consider refactoring.
Open

def generate_random_path(num_road_tiles, branchiness_factor, loopiness_factor, curviness_factor):
    def pick_adjacent_node(nodes, connections, branchiness_factor, curviness_factor):
        for attempts in range(5):
            origin = pick_origin_node(nodes, connections, branchiness_factor)
            possibles = []
Severity: Minor
Found in game/random_road.py - About 1 day to fix

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

Function generate_decor has a Cognitive Complexity of 68 (exceeds 5 allowed). Consider refactoring.
Open

def generate_decor(path, num_tiles):
    DECOR_DATA = decor_data()
    DECOR_SUM = decor_sum()

    def find_node_by_coordinate(x, y, dec, nodes):
Severity: Minor
Found in game/random_road.py - About 1 day to fix

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

File random_road.py has 329 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from __future__ import absolute_import

import json
import math
import random
Severity: Minor
Found in game/random_road.py - About 3 hrs to fix

    Function generate_traffic_lights has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def generate_traffic_lights(path):
        degree2Nodes = []
        degree3or4Nodes = []
    
        for node in path:
    Severity: Minor
    Found in game/random_road.py - About 2 hrs to fix

    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

    Consider simplifying this complex logical expression.
    Open

                if (
                    coord["x"] // GRID_SIZE == x
                    and coord["y"] // GRID_SIZE == y
                    or (
                        elem == "pond"
    Severity: Critical
    Found in game/random_road.py - About 1 hr to fix

      Function create has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def create(episode=None):
      
          num_tiles = episode.r_num_tiles if episode else DEFAULT_NUM_TILES
          branchiness = episode.r_branchiness if episode else DEFAULT_BRANCHINESS
          loopiness = episode.r_loopiness if episode else DEFAULT_LOOPINESS
      Severity: Minor
      Found in game/random_road.py - About 1 hr to fix

      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

      Function generate_random_map_data has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def generate_random_map_data(
      Severity: Major
      Found in game/random_road.py - About 50 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if adjacent_node_index > node_index and adjacent_node != nodes[0]:
                                    if adjacent_node_index not in connections[node_index]:
                                        possible_loops.append((node_index, adjacent_node_index))
        
        
        Severity: Major
        Found in game/random_road.py - About 45 mins to fix

          Function append_decor has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def append_decor(decor, x, y, dec, dx=0, dy=0):
          Severity: Minor
          Found in game/random_road.py - About 45 mins to fix

            Function pick_destination_node has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def pick_destination_node(nodes, connections, origin, possibles, curviness_factor):
            Severity: Minor
            Found in game/random_road.py - About 35 mins to fix

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                      x = x * GRID_SIZE + int((GRID_SIZE - decor_object.width) * 0.5 * (1 - dx))
              Severity: Major
              Found in game/random_road.py and 1 other location - About 1 hr to fix
              game/random_road.py on lines 369..369

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

              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

                      y = y * GRID_SIZE + int((GRID_SIZE - decor_object.height) * 0.5 * (1 - dy))
              Severity: Major
              Found in game/random_road.py and 1 other location - About 1 hr to fix
              game/random_road.py on lines 368..368

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

              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

              There are no issues that match your filters.

              Category
              Status