Magic numbers without documentation in json_inference.py #8

Open
opened 2026-03-19 17:30:21 +00:00 by llabeyrie · 0 comments
Owner

Description

json_inference.py contains numerous hardcoded numeric constants with no explanation:

# line ~250
base + (matches * 10)         # Why 10?

# line ~275
base = 30 + max(0, attack_stat - 70) // 2   # Why 30, 70, /2?

# line ~277
min(160, ...)                 # Why 160?

# lines ~264-270
if retreat_cost > 120: ...    # Why 120?
elif retreat_cost > 90: ...   # Why 90?
elif retreat_cost > 70: ...   # Why 70?

Problems

  • Impossible to understand or tweak game-balance logic without trial and error
  • No way to know if these are TCG rules, design choices, or arbitrary values
  • Makes code review and maintenance difficult

Fix

Extract to named module-level constants with comments:

# TCG card balancing constants
MAX_HP = 160              # Maximum HP for generated cards
BASE_DAMAGE = 30          # Minimum attack damage
DAMAGE_SCALING_THRESHOLD = 70  # Attack stat threshold for bonus damage
RETREAT_THRESHOLDS = (120, 90, 70)  # Stat thresholds for retreat cost tiers
## Description `json_inference.py` contains numerous hardcoded numeric constants with no explanation: ```python # line ~250 base + (matches * 10) # Why 10? # line ~275 base = 30 + max(0, attack_stat - 70) // 2 # Why 30, 70, /2? # line ~277 min(160, ...) # Why 160? # lines ~264-270 if retreat_cost > 120: ... # Why 120? elif retreat_cost > 90: ... # Why 90? elif retreat_cost > 70: ... # Why 70? ``` ### Problems - Impossible to understand or tweak game-balance logic without trial and error - No way to know if these are TCG rules, design choices, or arbitrary values - Makes code review and maintenance difficult ### Fix Extract to named module-level constants with comments: ```python # TCG card balancing constants MAX_HP = 160 # Maximum HP for generated cards BASE_DAMAGE = 30 # Minimum attack damage DAMAGE_SCALING_THRESHOLD = 70 # Attack stat threshold for bonus damage RETREAT_THRESHOLDS = (120, 90, 70) # Stat thresholds for retreat cost tiers ```
llabeyrie added the code-qualitypriority: medium labels 2026-03-19 17:31:43 +00:00
Sign in to join this conversation.