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()
- Read upRead up
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(
- Read upRead up
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
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
- Read upRead up
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())
- Read upRead up
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)
- Read upRead up
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 (
Avoid deeply nested control flow statements. Open
if (
not -50 <= bcontubit.x_pos <= 50 or
not -50 <= bcontubit.z_pos <= 50
):
continue
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
- Read upRead up
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
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)
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()[:]
- Read upRead up
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)
- Read upRead up
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,
- Read upRead up
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
Avoid too many return
statements within this function. Open
return result
Avoid too many return
statements within this function. Open
return result
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:
- Read upRead up
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:
- Read upRead up
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()[:]
- Read upRead up
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"