jardiacaj/finem_imperii

View on GitHub
battle/battle_tick.py

Summary

Maintainability
F
5 days
Test Coverage

Function create_next_turn has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
Open

def create_next_turn(battle: Battle):
    new_turn = battle.get_latest_turn()
    new_turn.id = None
    new_turn.num += 1
    new_turn.save()
Severity: Minor
Found in battle/battle_tick.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 get_target_distance_function has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
Open

def get_target_distance_function(battle_contubernium_in_turn: BattleContuberniumInTurn):
    order = battle_contubernium_in_turn.battle_unit_in_turn.battle_unit.get_order()
    enemy_contubernia = BattleContuberniumInTurn.objects.filter(
        battle_turn=battle_contubernium_in_turn.battle_turn
    ).exclude(
Severity: Minor
Found in battle/battle_tick.py - About 7 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

File battle_tick.py has 432 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import math
import random

import django
from django.db import transaction
Severity: Minor
Found in battle/battle_tick.py - About 6 hrs to fix

    Function find_path has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

    def find_path(battle_contubernium_in_turn: BattleContuberniumInTurn, target_distance_function, tile_availability_test) -> list:
        starting_coordinates = battle_contubernium_in_turn.coordinates()
        if target_distance_function(starting_coordinates) <= 0:
            return True
    
    
    Severity: Minor
    Found in battle/battle_tick.py - About 4 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

    Function optimistic_move_desire_resolving has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def optimistic_move_desire_resolving(battle: Battle):
        while BattleContuberniumInTurn.objects.filter(desires_pos=True, battle_turn=battle.get_latest_turn()).exists():
            bcuit = BattleContuberniumInTurn.objects.filter(desires_pos=True, battle_turn=battle.get_latest_turn())[0]
            contubernia_desiring_position = battle.get_latest_turn().get_contubernia_desiring_position(bcuit.desired_coordinates())
            desired_position_occupier = battle.get_latest_turn().get_contubernium_in_position(bcuit.desired_coordinates())
    Severity: Minor
    Found in battle/battle_tick.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

    Function unit_movement has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def unit_movement(battle: Battle):
        # first pass: desire positions / optimistic move
        for battle_unit_in_turn in BattleUnitInTurn.objects.filter(battle_turn=battle.get_latest_turn()):
            for battle_contubernium_in_turn in battle_unit_in_turn.battlecontuberniuminturn_set.all():
                target_distance_function = get_target_distance_function(battle_contubernium_in_turn)
    Severity: Minor
    Found in battle/battle_tick.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

    Avoid deeply nested control flow statements.
    Open

                            if not bcontubit.battlesoldierinturn_set.filter(
                                wound_status__lt=BattleSoldierInTurn.DEAD
                            ).exists():
                                continue
                            if (
    Severity: Major
    Found in battle/battle_tick.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if (
                                          not -50 <= bcontubit.x_pos <= 50 or
                                          not -50 <= bcontubit.z_pos <= 50
                              ):
                                  continue
      Severity: Major
      Found in battle/battle_tick.py - About 45 mins to fix

        Function safe_move has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def safe_move(battle_contubernium_in_turn: BattleContuberniumInTurn, target_distance_function):
            turn = battle_contubernium_in_turn.battle_turn
        
            def tile_availability_test(coords: Coordinates):
                return True if turn.get_contubernium_in_position(coords) is None else False
        Severity: Minor
        Found in battle/battle_tick.py - About 45 mins 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

        Avoid deeply nested control flow statements.
        Open

                            for soldier in contubernium.battlesoldier_set.all():
                                try:
                                    bsit = BattleSoldierInTurn.objects.get(
                                        battle_turn=prev_turn,
                                        battle_soldier=soldier
        Severity: Major
        Found in battle/battle_tick.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if desirer.coordinates() == desired_position_occupier.desired_coordinates():
                                  grant_position_swap(desirer, desired_position_occupier)
                                  continue
                          # TODO: try to move blocking contubernium before giving up
                          contubernia_desiring_position.update(desires_pos=False)
          Severity: Major
          Found in battle/battle_tick.py - About 45 mins to fix

            Function unit_attack_ranged has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def unit_attack_ranged(contubernium: BattleContuberniumInTurn,
                                   target_contubernium: BattleContuberniumInTurn):
                for soldier in contubernium.battlesoldierinturn_set.all():
                    target_soldier = random.choice(
                        target_contubernium.battlesoldierinturn_set.all()[:]
            Severity: Minor
            Found in battle/battle_tick.py - About 35 mins 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 unit_attack has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def unit_attack(battle: Battle):
                contubernia = list(BattleContuberniumInTurn.objects.filter(
                    battle_turn=battle.get_latest_turn()
                ))
                random.shuffle(contubernia)
            Severity: Minor
            Found in battle/battle_tick.py - About 35 mins 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 check_end has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def check_end(battle: Battle):
                for side in battle.battleside_set.all():
                    if not BattleSoldierInTurn.objects.filter(
                        battle_turn=battle.get_latest_turn(),
                        battle_contubernium_in_turn__battle_contubernium__battle_unit__battle_side=side,
            Severity: Minor
            Found in battle/battle_tick.py - About 35 mins 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

            Avoid too many return statements within this function.
            Open

                        return result
            Severity: Major
            Found in battle/battle_tick.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return result
              Severity: Major
              Found in battle/battle_tick.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return result
                Severity: Major
                Found in battle/battle_tick.py - About 30 mins to fix

                  Function coordinate_neighbours has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def coordinate_neighbours(coord: Coordinates):
                      result = []
                      for dx in (-1, 0, 1):
                          for dz in (-1, 0, 1):
                              if not dx == dz == 0:
                  Severity: Minor
                  Found in battle/battle_tick.py - About 25 mins 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 check_if_order_done has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def check_if_order_done(battle_unit_in_turn: BattleUnitInTurn):
                      order = battle_unit_in_turn.battle_unit.get_order()
                      if order:
                          if order.what == Order.MOVE:
                              if euclidean_distance(battle_unit_in_turn.coordinates(), order.target_location_coordinates()) == 0:
                  Severity: Minor
                  Found in battle/battle_tick.py - About 25 mins 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 unit_attack_melee has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def unit_attack_melee(contubernium: BattleContuberniumInTurn,
                                        target_contubernium: BattleContuberniumInTurn):
                      for soldier in contubernium.battlesoldierinturn_set.all():
                          target_soldier = random.choice(
                              target_contubernium.battlesoldierinturn_set.all()[:]
                  Severity: Minor
                  Found in battle/battle_tick.py - About 25 mins 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

                  There are no issues that match your filters.

                  Category
                  Status