Navigation

    TripleA Logo

    TripleA Forum

    • Register
    • Login
    • Search
    • TripleA Website
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Tags

    Game Engine Rules (AI Training)

    Development
    3
    8
    80
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Kindwind
      Kindwind last edited by Kindwind

      I decided to try some Claude code. Trying to make sure I have all the rules for the map Triplea revised. I am trying to get a better ai for the community on the map revised. I have like 1000 games trained but the rules were wrong. I just need another pair of eyes on my rules to make sure they are 100% right. # Colossus Rules Implementation Audit. If you have coded before would you mind looking at this to map sure this is right?

      Updated: # Colossus Rules Implementation Audit

      This document provides a comprehensive audit of all game rules implemented in the Colossus Axis & Allies engine.

      Legend:

      • ✅ Verified - Rule implemented correctly with test coverage
      • ⚠️ Untested - Rule implemented but lacks dedicated tests
      • ❌ Bug - Known issue with implementation

      1. Unit Properties

      File: unit.rs

      Unit Cost Attack Defense Movement Notes Status
      Infantry 3 1 2 1 Transport cost: 2 ✅ Verified
      Artillery 4 2 2 1 Transport cost: 3, supports infantry ✅ Verified
      Armour 5 3 3 2 Transport cost: 3, can blitz ✅ Verified
      AA Gun 5 0 0 1 Transport cost: 3, special AA fire ✅ Verified
      Fighter 10 3 4 4 Carrier cost: 1, +2 with Long Range ✅ Verified
      Bomber 15 4 1 6 SBR capable, +2 with Long Range ✅ Verified
      Submarine 8 2 2 2 First strike, submerge ✅ Verified
      Destroyer 12 3 3 2 Negates sub abilities ✅ Verified
      Transport 8 0 1* 2 Capacity: 5 points ✅ Verified
      Carrier 16 1 3 2 Holds 2 fighters ✅ Verified
      Battleship 24 4 4 2 2 hit points, shore bombard ✅ Verified
      Factory 15 0 0 0 Production building ✅ Verified

      *Transport defense is configurable (0 or 1 via config.transport_defense)

      Transport Capacity (Point-Based)

      Files: unit.rs:98-99, generation_fixed.rs

      Unit Transport Cost
      Infantry 2 points
      Artillery 3 points
      Armour 3 points
      AA Gun 3 points

      Total transport capacity: 5 points

      Valid loadouts:

      • 2 Infantry (4 points) ✅
      • 1 Infantry + 1 Artillery/Armour/AA (5 points) ✅
      • 1 Artillery/Armour/AA only (3 points) ✅

      Test Coverage: unit.rs:182-198 ✅ Verified


      2. Turn Sequence

      File: phase.rs

      Turn Order

      Phase Description Status
      1. Tech Purchase technology dice (5 IPCs each) ✅ Verified
      2. TechActivation Roll tech dice, gain technology ✅ Verified
      3. Purchase Buy units (placed at end of turn) ✅ Verified
      4. CombatMove Move units to attack ✅ Verified
      5. Battle Resolve all combat ✅ Verified
      6. NonCombatMove Move remaining units ✅ Verified
      7. Place Place purchased units ✅ Verified
      8. EndTurn Collect income, repair units ✅ Verified

      Player Order

      1. Russians → 2. Germans → 3. British → 4. Japanese → 5. Americans

      File: phase.rs:15-28 ✅ Verified

      Bid Phases (Pre-Game)

      Phase Description
      RussiansBid Place Russian bid units
      GermansBid Place German bid units
      BritishBid Place British bid units
      JapaneseBid Place Japanese bid units
      AmericansBid Place American bid units

      File: phase.rs, game_options.rs:184-204 ✅ Verified


      3. Movement Rules

      3.1 Combat Move Phase

      File: generation_fixed.rs

      Rule Implementation Status
      Land units can attack adjacent territories gen_combat_moves ✅ Verified
      Ships can attack adjacent sea zones gen_combat_moves ✅ Verified
      Aircraft can attack within movement range gen_combat_moves ✅ Verified
      AA guns CANNOT move during combat if unit_type == UnitType::AaGun { continue; } ✅ Verified
      AA guns CANNOT load on transports during combat gen_transport_loads_combat_dedup ✅ Verified
      Transports can load infantry/artillery/armour gen_transport_loads_combat_dedup ✅ Verified
      Amphibious assaults from transports gen_amphibious_assaults ✅ Verified
      Bombers CAN attack sea zones Must have valid landing spot for return ✅ Verified

      Test Coverage: generation_fixed.rs:745-923 ✅ Verified

      3.2 Non-Combat Move Phase

      File: generation_fixed.rs

      Rule Implementation Status
      Units move to friendly territories gen_noncombat_moves ✅ Verified
      AA guns CAN move during NCM gen_noncombat_moves ✅ Verified
      AA guns CAN load on transports gen_transport_loads_dedup ✅ Verified
      Aircraft must land with valid capacity validation/aircraft.rs ✅ Verified
      Transports can unload cargo gen_transport_unloads ✅ Verified
      Bombers CANNOT land in sea zones if unit_type == UnitType::Bomber && to_terr.is_water { continue; } ✅ Verified

      Test Coverage: generation_fixed.rs:871-923 ✅ Verified

      3.3 Blitzing

      File: validation/movement.rs:130-153

      Rule Description Status
      Only armour can blitz Movement 2 required ✅ Verified
      Must pass through EMPTY enemy territory No enemy units present ✅ Verified
      Cannot blitz through defended territory can_blitz function ✅ Verified
      Territory captured during blitz Ownership changes ✅ Verified
      AA guns block blitzing can_blitz check ✅ Verified

      Test Coverage: movement.rs:295-433 ✅ Verified

      3.4 Canal Restrictions

      File: generation_fixed.rs:611-634

      Canal Required Territories Status
      Suez Canal Egypt ✅ Verified
      Panama Canal Panama, Central America ✅ Verified

      Ships cannot pass through canals unless controlling player owns required territories.

      Implementation: can_pass_canal function ✅ Verified

      3.5 Aircraft Landing

      File: validation/aircraft.rs

      Rule Description Status
      Fighters land on friendly territory can_land function ✅ Verified
      Fighters land on carriers has_carrier_capacity ✅ Verified
      Carrier capacity: 2 fighters Per carrier ✅ Verified
      Bombers land on friendly territory only Cannot use carriers ✅ Verified
      Must have movement remaining remaining_movement ✅ Verified
      Long Range Air: +2 movement Technology bonus ✅ Verified

      Test Coverage: aircraft.rs:163-217 ✅ Verified

      3.6 Movement Tracking

      Files: fixed.rs, apply.rs, undo.rs, generation_fixed.rs

      Rule Description Status
      Units move once per phase units_moved_count tracking array ✅ Verified
      Walk-then-load blocked (Combat Move) Load tracks unit at source territory ✅ Verified
      Unload-then-walk blocked (both phases) Unload tracks unit at destination ✅ Verified
      NCM bridging allowed Load NOT tracked in Non-Combat Move ✅ Verified
      MCTS apply/unapply works unrecord_units_moved() restores state ✅ Verified
      Phase transition clears tracking clear_movement_tracking() on phase change ✅ Verified

      Implementation:

      • units_moved_count[player][territory][unit_type] - Tracks how many units moved FROM each territory
      • remaining_movement[player][territory][unit_type] - For multi-space movers (future use)
      • record_units_moved() - Called in apply_unit_move(), apply_load() (CM only), apply_unload()
      • unrecord_units_moved() - Called in unapply_move() for MCTS backtracking
      • units_available_to_move() - Returns present count minus already moved count
      • clear_movement_tracking() - Called when leaving CombatMove or NonCombatMove phase

      Movement Tracking Matrix:

      Function Combat Move Non-Combat Move Track Location Reason
      apply_unit_move() ✅ Track ✅ Track DESTINATION Unit can't move again after arriving
      apply_load() ✅ Track ❌ No track SOURCE CM: prevents walk-then-load; NCM: allows bridging
      apply_unload() ✅ Track ✅ Track DESTINATION Unit can't move after unloading

      Note: Tracking at destination for apply_unit_move() is correct because the unit is physically removed from the source territory. Tracking the arriving unit at its destination prevents it from moving further.

      State Size Impact: Increased from 16KB to 32KB to accommodate tracking arrays.

      Test Coverage: battle_test.rs ✅ Verified


      4. Combat Rules

      4.1 Battle Resolution

      File: combat/resolve.rs

      Phase Description Status
      1. AA Fire AA guns fire at attacking aircraft ✅ Verified
      2. Submarine First Strike Subs attack before regular combat ✅ Verified
      3. Regular Combat Alternating fire rounds ✅ Verified
      4. Retreat Attacker may retreat ✅ Verified

      4.1.1 Territory Capture

      File: combat/resolve.rs

      Rule Description Status
      Territory ownership transfers Winner takes control ✅ Verified
      AA guns are CAPTURED, not destroyed capture_aa_guns() transfers ownership ✅ Verified
      AA guns do not participate in combat Non-combatant, defense = 0 ✅ Verified
      AA guns not selected as casualties Excluded from casualty selection ✅ Verified
      Allied AA guns NOT captured Only enemy AA guns transfer ✅ Verified

      Implementation:

      • capture_aa_guns() called when attacker wins battle
      • Iterates through all enemy players (skips self and allies)
      • Transfers AA gun ownership from old owner to new owner
      • Updates unit counts and territory masks
      • Called after bombardment victory AND after regular combat victory

      Test Coverage: test_aa_gun_captured_when_territory_falls, test_aa_gun_not_in_casualty_list, test_multiple_aa_guns_all_captured ✅ Verified

      4.1.2 Shore Bombardment

      Files: battle.rs, resolve.rs, bombardment.rs

      Rule Description Status
      Battleships bombard in amphibious assaults Fire BEFORE AA fire ✅ Verified
      One shot per battleship Attack value 4 ✅ Verified
      Only from adjacent sea zones Must have transport AND battleship ✅ Verified
      Casualties applied before combat Hits remove defenders immediately ✅ Verified
      Not in land-only attacks Only amphibious assaults ✅ Verified
      Low Luck bombardment 4/6 = 0.66 guaranteed hits per battleship ✅ Verified

      Implementation:

      • get_amphibious_info() - Detects amphibious assault by checking for transports in adjacent sea zones
      • resolve_bombardment_multi() - Fires all battleships from identified sea zones
      • Called at start of resolve_battle() before AA fire
      • Can end battle early if bombardment kills all defenders

      Test Coverage: battle_test.rs ✅ Verified

      4.2 AA Fire

      File: combat/resolve.rs, combat/dice.rs:29-37

      Rule Description Status
      Hits on 1 1/6 chance per aircraft ✅ Verified
      One shot per aircraft Max hits = aircraft count ✅ Verified
      Low Luck AA Guaranteed hits for 6+ aircraft ✅ Verified
      Choose casualties (optional) config.choose_aa_casualties ✅ Verified
      Always-on AA (flyover) config.always_on_aa ✅ Verified

      Test Coverage: resolve.rs:665-681, apply.rs:822-980 ✅ Verified

      4.3 Submarine Combat

      File: combat/resolve.rs

      Rule Description Status
      First strike Submarines fire first ✅ Verified
      Casualties don't return fire Unless destroyer present ✅ Verified
      Destroyer negates first strike has_destroyer check ✅ Verified
      Submerge option config.submersible_subs ✅ Verified
      Super Subs tech: Attack 3 Technology bonus ✅ Verified
      Super Subs defense bonus config.super_sub_defense_bonus ✅ Verified
      Defending subs fire back config.defending_subs_fire_back ✅ Verified
      Air cannot hit subs without destroyer air_can_hit_subs() check ✅ Verified
      Subs cannot hit aircraft get_sub_targetable_units() excludes aircraft ✅ Verified
      Air vs Sub stalemate Battle ends if only air vs only subs ✅ Verified

      Implementation (Fixed 2026-01):

      • air_can_hit_subs() - Returns true only if attacker has destroyer in territory
      • get_air_targetable_units() - Filters subs from targets when no destroyer present
      • get_sub_targetable_units() - Excludes fighters and bombers from sub targets
      • is_air_sub_stalemate() - Detects deadlock when only air vs only subs
      • Stalemate check runs BEFORE each combat round
      • If stalemate detected, battle ends with no winner

      Test Coverage: test_air_cannot_hit_subs_without_destroyer, test_air_can_hit_subs_with_destroyer, test_sub_hits_cannot_kill_aircraft, test_is_air_sub_stalemate_detection ✅ Verified

      4.4 Artillery Support

      File: combat/resolve.rs

      Rule Description Status
      1:1 support ratio Each artillery supports 1 infantry ✅ Verified
      Supported infantry attack at 2 Instead of 1 ✅ Verified

      Test Coverage: resolve.rs:613-621 ✅ Verified

      4.5 Two-Hit Battleships

      File: combat/resolve.rs

      Rule Description Status
      Battleships take 2 hits config.two_hit_battleship ✅ Verified
      Damaged state tracked state.damaged_battleships ✅ Verified
      Repair at end of turn config.units_repair_hits_end_turn ✅ Verified
      Repair at start of turn config.units_repair_hits_start_turn ✅ Verified

      Test Coverage: resolve.rs:684-709 ✅ Verified

      4.6 Transport Defense

      File: combat/resolve.rs

      Setting Behavior Status
      transport_defense = 0 Defenseless transports ✅ Verified
      transport_defense = 1 Transports defend at 1 ✅ Verified
      Combat unit check Transports count as combat when defending ✅ Verified

      Test Coverage: resolve.rs:711-784 ✅ Verified


      5. Strategic Bombing

      File: combat/bombing.rs

      Rule Description Status
      Bombers attack factories resolve_bombing_raid ✅ Verified
      AA fires at bombers Before damage ✅ Verified
      Damage = 1d6 per bomber Standard ✅ Verified
      Heavy Bombers: 2d6 With technology ✅ Verified
      LHTR Heavy: Best of 2d6 config.lhtr_heavy_bombers ✅ Verified
      Low Luck: 4 IPC per bomber config.low_luck_bombing ✅ Verified
      Low Luck Heavy: 7 IPC Per bomber ✅ Verified
      Territory turn limit config.territory_turn_limit ✅ Verified
      Factory damage tracked state.factory_damage ✅ Verified
      Repair costs 1 IPC per point repair_factory ✅ Verified

      Test Coverage: bombing.rs:152-260 ✅ Verified


      6. Economic Rules

      6.1 Income Collection

      File: game/income.rs

      Rule Description Status
      Income = sum of controlled territory production calculate_income ✅ Verified
      No income if capital captured state.capital_captured check ✅ Verified
      Income collected at end of turn collect_income ✅ Verified

      Test Coverage: income.rs:54-77 ✅ Verified

      6.2 Capital Capture

      File: game/capital.rs

      Rule Description Status
      Captor steals all IPCs handle_capital_capture ✅ Verified
      Victim loses income ability capital_captured flag ✅ Verified
      Liberation restores income check_capital_liberation ✅ Verified
      IPCs not returned on liberation Intended behavior ✅ Verified

      Test Coverage: capital.rs:101-144 ✅ Verified

      6.3 Unit Purchase

      Files: generation_fixed.rs, action_space.rs

      Rule Description Status
      Purchase during Purchase phase Phase check ✅ Verified
      Units placed during Place phase Deferred placement ✅ Verified
      Factory required for placement Factory presence check ✅ Verified
      Cannot use enemy factory Ownership check ✅ Verified
      Sea units placed in adjacent sea zone Naval placement ✅ Verified
      Factory damage reduces production effective_production ✅ Verified

      Test Coverage: generation_fixed.rs:996-1124 ✅ Verified


      7. Victory Conditions

      File: game/victory.rs

      Victory Type Cities Needed Status
      Projection of Power 9 VCs ✅ Verified
      Honorable Surrender 10 VCs ✅ Verified
      Total Victory 12 VCs ✅ Verified

      Implementation:

      • check_victory - Main victory check
      • count_victory_cities - Count per alliance
      • check_capitals - Alternative capital-based victory

      Test Coverage: victory.rs:106-126 ✅ Verified


      8. Technology System

      File: types/phase.rs, combat/dice.rs

      Available Technologies

      Technology Effect Status
      Jet Power Fighters attack/defend +1 ✅ Verified
      Rockets AA guns can SBR ✅ Verified
      Super Subs Submarines attack at 3 ✅ Verified
      Long Range Air Aircraft +2 movement ✅ Verified
      Industrial Tech Units cost 1 less ✅ Verified
      Heavy Bombers 2d6 bombing damage ✅ Verified

      Test Coverage: resolve.rs:814-1056 ✅ Verified (All technologies)

      Tech Research

      Rule Description Status
      Cost: 5 IPCs per die config.tech_cost_per_die ✅ Verified
      Success on 6 roll_tech ✅ Verified
      Low Luck: N dice = N/6 chance Guaranteed at 6 dice ✅ Verified

      Test Coverage: dice.rs:129-140 ✅ Verified


      9. Low Luck System

      File: combat/dice.rs

      Type Formula Status
      Combat hits = floor(power/6) + roll for remainder ✅ Verified
      AA Fire hits = floor(aircraft/6) + roll ✅ Verified
      Tech 6 dice = guaranteed, else roll ≤ N ✅ Verified
      Bombing 4 IPC per normal, 7 per heavy ✅ Verified

      Configuration:

      • config.low_luck - Combat
      • config.low_luck_aa - AA fire
      • config.low_luck_tech - Technology
      • config.low_luck_bombing - Strategic bombing

      Test Coverage: dice.rs:91-162 ✅ Verified


      10. Configuration Options

      File: config/game_options.rs

      Combat Options

      Option Default (TRAINING) Status
      low_luck true ✅ Verified
      low_luck_aa true ✅ Verified
      low_luck_tech true ✅ Verified
      low_luck_bombing true ✅ Verified
      always_on_aa true ✅ Verified
      roll_aa_individually true ✅ Verified
      choose_aa_casualties true ✅ Verified
      kamikaze_airplanes false ✅ Verified
      territory_turn_limit true ✅ Verified

      Technology Options

      Option Default (TRAINING) Status
      technology_enabled false ✅ Verified
      tech_cost_per_die 5 ✅ Verified
      lhtr_heavy_bombers true ✅ Verified
      heavy_bomber_dice_rolls 2 ✅ Verified
      super_sub_defense_bonus 0 ✅ Verified

      Unit Options

      Option Default (TRAINING) Status
      two_hit_battleship true ✅ Verified
      units_repair_hits_end_turn true ✅ Verified
      units_repair_hits_start_turn false ✅ Verified
      submersible_subs true ✅ Verified
      defending_subs_fire_back true ✅ Verified
      transport_defense 1 ✅ Verified
      produce_fighters_on_carriers true ✅ Verified
      move_existing_fighters_to_new_carriers true ✅ Verified
      lhtr_carrier_production false ✅ Verified
      allied_air_dependents true ✅ Verified

      Movement Options

      Option Default (TRAINING) Status
      neutrals_are_impassable true ✅ Verified
      neutrals_are_blitzable false ✅ Verified
      sub_control_sea_zone_restricted false ✅ Verified

      Victory Options

      Option Default (TRAINING) Status
      victory_type TotalVictory (12 VCs) ✅ Verified

      Test Coverage: game_options.rs:544-848 ✅ Verified


      11. Presets

      File: config/game_options.rs

      Preset Description Key Differences
      TRAINING Your preferred settings Low Luck ON, 12 VCs, German bid 9
      TOURNAMENT Competitive play Low Luck ON, 9 VCs, no bids
      CASUAL Standard dice Low Luck OFF, 9 VCs
      TRIPLEA_DEFAULT Matches TripleA Low Luck OFF, no LHTR

      Summary Statistics

      Category Verified Untested Bugs Total
      Unit Properties 12 0 0 12
      Turn Sequence 8 0 0 8
      Movement Rules 21 0 0 21
      Combat Rules 27 0 0 27
      Economic Rules 9 0 0 9
      Victory 3 0 0 3
      Technology 7 0 0 7
      Configuration 29 0 0 29
      TOTAL 116 0 0 116

      Coverage: 100% verified, 0% untested, 0% bugs


      Known Fixed Issues

      AA Gun Transport Rules (Fixed 2024-12)

      Files Modified: generation_fixed.rs

      Bug Fix
      AA guns could load during Combat Move Created gen_transport_loads_combat_dedup excluding AA guns
      Transport loading not generated during NCM Added gen_transport_loads_dedup to gen_noncombat_moves

      Test Cases Added:

      1. test_aa_gun_cannot_load_during_combat_move
      2. test_aa_gun_can_load_during_noncombat_move
      3. test_infantry_can_load_during_combat_move
      4. test_artillery_can_load_during_combat_move
      5. test_aa_gun_can_unload_during_noncombat_move
      6. test_aa_gun_can_amphibious_assault

      Test Coverage Expansion (2026-01)

      Added comprehensive tests for previously untested rules:

      Combat Rules (submarines.rs, resolve.rs😞

      • test_subs_can_submerge_no_destroyer
      • test_subs_cannot_submerge_with_enemy_destroyer
      • test_sub_attack_power_normal
      • test_sub_attack_power_super_subs
      • test_first_strike_checks_correct_enemy
      • test_resolve_battle_with_defending_subs_fire_back
      • test_resolve_battle_without_defending_subs_fire_back
      • test_submersible_subs_first_strike_enabled

      Technology Effects (resolve.rs😞

      • test_jet_power_increases_fighter_attack
      • test_jet_power_increases_fighter_defense
      • test_jet_power_only_affects_fighters
      • test_super_subs_increases_attack

      Movement/Blitz (movement.rs😞

      • test_blitz_through_empty_enemy_territory
      • test_blitz_blocked_by_any_enemy_unit
      • test_blitz_blocked_by_aa_gun
      • test_blitz_tracker_records_correctly
      • test_only_armour_can_blitz_movement_check
      • test_blitz_path_length_validation

      Factory Placement (generation_fixed.rs):

      • test_placement_requires_factory
      • test_placement_with_factory
      • test_sea_unit_placement_requires_adjacent_sea_zone
      • test_cannot_place_in_enemy_factory

      Technologies - Rockets & Industrial Tech (resolve.rs😞

      • test_rockets_tech_defined
      • test_rockets_tech_can_be_granted
      • test_rockets_allows_aa_sbr
      • test_industrial_tech_defined
      • test_industrial_tech_can_be_granted
      • test_industrial_tech_reduces_unit_cost
      • test_industrial_tech_all_unit_types

      Config Options (game_options.rs):

      • test_kamikaze_airplanes_default_training
      • test_kamikaze_airplanes_default_tournament
      • test_kamikaze_airplanes_can_be_enabled
      • test_produce_fighters_on_carriers_enabled
      • test_produce_fighters_on_carriers_all_presets
      • test_move_existing_fighters_to_new_carriers_enabled
      • test_move_existing_fighters_to_new_carriers_all_presets
      • test_lhtr_carrier_production_disabled_by_default
      • test_lhtr_carrier_production_all_presets
      • test_lhtr_carrier_production_can_be_enabled
      • test_allied_air_dependents_enabled
      • test_allied_air_dependents_all_presets
      • test_allied_air_dependents_can_be_disabled
      • test_neutrals_are_blitzable_disabled_by_default
      • test_neutrals_are_blitzable_all_presets
      • test_neutrals_are_blitzable_can_be_enabled
      • test_neutrals_impassable_takes_precedence
      • test_sub_control_sea_zone_restricted_disabled_by_default
      • test_sub_control_sea_zone_restricted_all_presets
      • test_sub_control_sea_zone_restricted_can_be_enabled
      • test_sub_control_affects_transport_passage

      Last updated: 2026-01

      Movement Rules Overhaul (Fixed 2026-01)

      Files Modified:

      • generation_fixed.rs
      • fixed.rs
      • apply.rs
      • undo.rs
      • resolve.rs
      Bug Description Fix
      AA guns could move in Combat Move AA guns have movement=1, weren't excluded Added if unit_type == UnitType::AaGun { continue; } in gen_combat_moves()
      Bombers could land in sea zones (NCM) No explicit check for bomber sea landing Added if unit_type == UnitType::Bomber && to_terr.is_water { continue; } in gen_noncombat_moves()
      AA guns destroyed on capture AA guns vanished when territory fell Added capture_aa_guns() to transfer ownership to attacker
      Movement tracking not used Units could move unlimited times Added units_moved_count tracking - see Section 3.6

      Note: Bombers CAN move to sea zones during Combat Move (to attack ships). The fix only prevents landing in sea zones during Non-Combat Move.

      Test Cases Added:

      • test_aa_gun_cannot_move_during_combat_move
      • test_aa_gun_can_move_during_noncombat
      • test_bomber_cannot_move_to_sea_zone_ncm
      • test_aa_gun_captured_when_territory_falls
      • test_aa_gun_not_in_casualty_list
      • test_multiple_aa_guns_all_captured

      Impact: These bugs meant the AI was learning invalid strategies during training. Training should be restarted from scratch after these fixes.

      Shore Bombardment Implementation (Added 2026-01)

      Files Modified:

      • battle.rs - Added get_amphibious_info() helper
      • resolve.rs - Added bombardment logic before AA fire
      • bombardment.rs - resolve_bombardment_multi() function
      Feature Description
      Detection get_amphibious_info() checks for transports in adjacent sea zones
      Firing Battleships fire at attack value 4 (Low Luck: 4/6 = 0.66 hits each)
      Timing Fires BEFORE AA fire, casualties applied immediately
      Multi-zone Supports battleships from multiple adjacent sea zones
      Early victory Can end battle if bombardment kills all defenders

      Rule Details:

      • Only battleships can bombard (WW2v2 has no cruisers)
      • One bombardment shot per battleship per battle
      • Bombardment only happens in amphibious assaults (requires transport unloading)
      • Defender selects casualties from bombardment hits

      Test Cases (tests/battle_test.rs):

      • test_bombardment_in_amphibious_assault - Bombardment fires during amphibious assault
      • test_no_bombardment_without_amphibious - No bombardment for land-only attacks
      • test_multiple_battleships_bombard - Multiple battleships all fire
      • test_bombardment_before_aa_fire - Bombardment happens before AA fire in battle sequence

      Movement Tracking Implementation (Added 2026-01)

      Files Modified:

      • fixed.rs - Added units_moved_count and remaining_movement arrays
      • apply.rs - Track in apply functions, untrack in unapply
      • undo.rs - Added movement tracking fields to UndoInfo
      • generation_fixed.rs - Use units_available_to_move() for move generation
      Issue Description Fix
      Units could move multiple times No tracking of which units moved Added units_moved_count array
      Walk-then-load exploit Infantry walk to coast, then load same turn Track load at source (Combat Move only)
      Unload-then-walk exploit Tank unload from transport, then walk inland Track unload at destination (both phases)
      MCTS state corruption Movement not restored on unapply Added unrecord_units_moved() in unapply
      NCM bridging broken Bridging requires load→sail→unload in one phase Don't track load in Non-Combat Move

      State Size Impact: Increased from 16KB to 32KB to accommodate tracking arrays.

      MCTS Compatibility:

      • apply_move() records movement in UndoInfo
      • unapply_move() calls unrecord_units_moved() to restore state
      • Phase transitions call clear_movement_tracking() to reset arrays

      Test Cases (tests/battle_test.rs):

      • test_movement_tracking_basic - Basic record_units_moved functionality
      • test_unit_move_tracks_movement - Unit moves are tracked at destination
      • test_mcts_apply_unapply_preserves_movement - MCTS cycle restores movement state
      • test_phase_transition_clears_tracking - Tracking cleared on phase change
      • test_clear_movement_tracking_directly - Direct clear function works
      • test_moved_units_not_in_move_generation - Moved units excluded from legal moves
      • test_unload_tracks_at_destination - Unloaded units tracked at destination
      • test_full_combat_round_with_tracking - Full battle with tracking
      • test_aa_gun_cannot_combat_move - AA guns excluded from Combat Move
      • test_aa_gun_can_noncombat_move - AA guns can move in Non-Combat Move
      • test_bomber_cannot_land_in_sea_zone_ncm - Bombers can't land in sea zones

      Production Limit Implementation (Fixed 2026-01)

      Files Modified:

      • fixed.rs - Added units_placed_count array and helper methods
      • apply.rs - Track placements in apply_place(), untrack in unapply_move()
      • undo.rs - Added placement_territory and placement_count to UndoInfo
      • generation_fixed.rs - Use remaining_production_capacity() in gen_placements()
      Rule Description Status
      Production = territory IPC Max units placeable = territory production value ✅ Verified
      Factory damage reduces capacity Effective limit = production - damage ✅ Verified
      Tracking per territory units_placed_count[territory] tracks placements ✅ Verified
      Reset at end of turn clear_placement_tracking() on phase transition ✅ Verified

      Implementation:

      • remaining_production_capacity(territory, production) - Returns available capacity
      • record_units_placed(territory, count) - Increments placement count
      • unrecord_units_placed(territory, count) - Decrements for MCTS unapply
      • clear_placement_tracking() - Resets all counts (called when leaving Place phase)

      Bug Fixed:
      Previously, gen_placements() retrieved let _production = map.territory(tid).production; but NEVER USED IT. This allowed unlimited unit placement at any factory, breaking game balance.

      Test Cases:

      • test_production_limited_by_territory_ipc - Placement capped at territory IPC
      • test_production_reduced_by_factory_damage - Damage reduces capacity
      • test_no_placement_at_capacity - No placements when at capacity
      • test_remaining_production_capacity_helper - Helper function works correctly

      Air vs Submarine Rules Implementation (Fixed 2026-01)

      Files Modified:

      • resolve.rs - Added stalemate detection and target filtering
      Rule Description Status
      Air cannot hit subs without destroyer air_can_hit_subs() check in combat ✅ Verified
      Subs cannot hit aircraft Sub hits filtered to exclude fighters/bombers ✅ Verified
      Stalemate detection Battle ends if only air vs only subs (no destroyer) ✅ Verified

      Implementation:

      • has_only_subs() - Checks if player only has submarines remaining
      • has_only_air_no_destroyer() - Checks if player has only air and no destroyer
      • is_air_sub_stalemate() - Detects when combat cannot continue
      • get_air_targetable_units() - Filters subs from air targets when no destroyer
      • get_sub_targetable_units() - Excludes aircraft from sub targets

      Bug Fixed:
      The air_can_hit_subs() function in submarines.rs existed but was NEVER CALLED in combat resolution. This meant aircraft could always hit submarines regardless of destroyer presence.

      Test Cases:

      • test_air_cannot_hit_subs_without_destroyer - Stalemate when only air vs subs
      • test_air_can_hit_subs_with_destroyer - Normal combat with destroyer
      • test_sub_hits_cannot_kill_aircraft - Sub hits go to non-aircraft
      • test_has_only_subs_helper - Helper function works
      • test_has_only_air_no_destroyer_helper - Helper function works
      • test_is_air_sub_stalemate_detection - Stalemate detection works
      • test_get_air_targetable_units_filters_subs - Target filtering works
      • test_get_sub_targetable_units_excludes_aircraft - Aircraft excluded from sub targets

      Canal Blocking Tests (Added 2026-01)

      Files Modified:

      • generation_fixed.rs - Added canal blocking test cases
      Rule Description Status
      Suez Canal blocking Ships cannot pass Suez if enemy controls Anglo Egypt OR Trans-Jordan ✅ Verified
      Panama Canal blocking Ships cannot pass Panama if enemy controls Panama ✅ Verified
      Both territories required Suez requires control of BOTH Anglo Egypt AND Trans-Jordan ✅ Verified
      Allied canal access Allied ships can use canals controlled by friendly powers ✅ Verified

      Implementation:

      • can_pass_canal() in generation_fixed.rs already implemented correctly
      • Tests added to verify canal blocking works as expected

      Test Cases:

      • test_suez_canal_blocked_without_control - British ships blocked when Germans control Suez
      • test_suez_canal_open_with_control - British ships pass when British control Suez
      • test_panama_canal_blocked_without_control - Japanese ships blocked when Allies control Panama
      • test_panama_canal_open_with_control - American ships pass when Americans control Panama
      • test_suez_requires_both_territories - Suez blocked if only one territory controlled
      • test_allied_can_use_friendly_canal - British can use American-controlled Panama

      Amphibious Retreat Rules Implementation (Fixed 2026-01)

      Files Modified:

      • fixed.rs - Added amphibious_assault_territories tracking mask
      • apply.rs - Mark amphibious assaults, restrict retreat to aircraft
      • undo.rs - Added amphibious_territory and amphibious_territory_marked fields
      • generation_fixed.rs - Only generate retreat moves if aircraft present in amphibious battles
      Rule Description Status
      Ground units cannot retreat from amphibious Infantry, artillery, armour stay and fight to death ✅ Verified
      Aircraft can retreat from amphibious Fighters and bombers can retreat to friendly territory ✅ Verified
      Pure amphibious ground has no retreat If only ground units in amphibious, no retreat moves generated ✅ Verified
      Non-amphibious full retreat All units can retreat from non-amphibious battles ✅ Verified

      Implementation:

      • amphibious_assault_territories: TerritoryMask - Tracks which territories have amphibious landings
      • Set when apply_amphibious() is called during Combat Move phase
      • Cleared when leaving Battle phase
      • gen_battle_moves() - Only generates retreat if attacker has aircraft in amphibious battles
      • apply_retreat() - Only moves aircraft in amphibious battles, ground units stay

      Bug Fixed:
      Previously, all units could retreat from any battle. In amphibious assaults, ground units that landed from transports are committed to the battle and cannot retreat. Only aircraft (which flew in separately) can retreat.

      Test Cases:

      • test_amphibious_assault_no_retreat_without_air - No retreat moves when only ground units
      • test_amphibious_assault_air_can_retreat - Retreat available when aircraft present
      • test_non_amphibious_all_units_can_retreat - All units can retreat in land battles
      • test_amphibious_retreat_only_moves_aircraft - Only aircraft move when retreating from amphibious

      Submarine Submerge Implementation (Fixed 2026-01)

      Files Modified:

      • mod.rs - Added MOVE_SUBMERGE constant and Move::submerge() constructor
      • fixed.rs - Added submerged_subs tracking array and helper methods
      • undo.rs - Added submerge_territory, submerge_player, submerge_count, submerge_occurred fields
      • apply.rs - Added apply_submerge() and undo logic
      • generation_fixed.rs - Generate submerge option in gen_battle_moves()
      • battle.rs - Restore submerged subs after battle ends
      Rule Description Status
      Submerge option available Subs can submerge if no enemy destroyer present ✅ Verified
      Destroyer blocks submerge Enemy destroyer prevents submerge option ✅ Verified
      Submerged subs leave combat Submerged subs don't participate in remaining rounds ✅ Verified
      Submerged subs survive Submerged subs remain in territory after battle ✅ Verified
      Player choice Player can choose to submerge OR continue (stalemate) ✅ Verified

      Implementation:

      • submerged_subs: [[u8; MAX_TERRITORIES]; Player::COUNT] - Tracks submerged subs per player per territory
      • submerge_subs() - Moves subs from active units to submerged tracking
      • restore_submerged_subs() - Restores subs to active units after battle ends
      • unsubmerge_subs() - For MCTS unapply
      • gen_battle_moves() - Generates submerge option when subs present and no enemy destroyer
      • After resolve_battle(), restore_submerged_subs() is called for all players

      Bug Fixed:
      The subs_can_submerge() function existed but was never used in the game. Submarines couldn't choose to submerge to escape combat. Now the player can choose between:

      1. Submerge - Subs escape and remain in territory after battle
      2. Pass (continue) - Battle continues (with stalemate detection if only air vs subs)

      Test Cases:

      • test_submerge_option_available_without_destroyer - Submerge move generated when no destroyer
      • test_submerge_option_blocked_by_destroyer - No submerge option when enemy has destroyer
      • test_submerge_removes_subs_from_combat - Subs move to submerged tracking
      • test_submerged_subs_restored_after_battle - Subs restored to active units post-battle
      • test_submerge_vs_stalemate_gives_choice - Player has choice: submerge or continue to stalemate
      TheDog 1 Reply Last reply Reply Quote 4
      • TheDog
        TheDog @Kindwind last edited by

        @kindwind
        Looks impressive!
        Is the PU value of a territory taken into account?

        The built-in AI targets Capital and Victory Cities (vc), it looks like you cater for those. It also targets factories does the above?

        Kindwind 1 Reply Last reply Reply Quote 1
        • Kindwind
          Kindwind @TheDog last edited by

          @thedog What the neural network CAN SEE (encoded in the 48-channel tensor):
          Feature
          Channel
          How Encoded
          Territory PU values
          25
          Production value normalized (0-1, max 10)
          Victory Cities
          26
          Binary flag
          Capitals
          28
          Binary flag
          Factories
          30
          Binary "has factory" flag
          Factory damage
          29
          Damage level normalized
          So the network sees all this information, but here's the philosophical difference from TripleA's built-in AI:
          TripleA's AI: Has explicit targeting heuristics ("prioritize capitals → VCs → factories → high-PU territories")
          COLOSSUS: Has NO explicit targeting. It must discover through self-play that these things matter based on:
          Win condition: Victory City count (9/10/12 VCs) or capital capture
          Reward shaping: IPC advantage as a tie-breaker (which reflects total controlled PU)
          The theory is that after enough training games, the network should learn:
          "Capturing Moscow gives me all their IPCs" → value capitals
          "Controlling more VCs wins games" → value VCs
          "High-PU territories increase my IPC advantage" → value territory production
          "Factories let me place units there" → value factories (implicitly)
          The question is: Has training progressed far enough for this learning to emerge? Or does it need explicit reward shaping for intermediate strategic objectives?

          So it's an alpha go style. Should work used low luck instead of pure dice.

          It may not work out however!

          TheDog 1 Reply Last reply Reply Quote 2
          • TheDog
            TheDog @Kindwind last edited by

            @kindwind said in Game Engine Rules (AI Training):

            Or does it need explicit reward shaping for intermediate strategic objectives?

            TripleAs AI needs help to be better, in 1941 Global Command Decision (GCD) there are 82 Capital territories/TT and Sea Zones/SZ. A few Capitals are in the middle of the Pacific. I have used these excess Capitals to tell the AI what is important to the player.

            Also SZ have PU values, usually 1, but SZ that are part of a canal have 2PU, so the AI values these more.

            So does your AI value what the player values?

            Kindwind 1 Reply Last reply Reply Quote 2
            • Kindwind
              Kindwind @TheDog last edited by

              @thedog For right now I am doing the revised map. I will take on other maps later. Hopefully from my current project I can upgrade to something like a universal game engine for triplea that handles all the maps. That's a lot of work. The project is much simpler. Get an AI like alpha go for revised. Make sure it's right. Then expand. The AI can figure out how I build this and then make me a script for the universal engine from all the tirplea game boards. Remember, I don't code. I am just guy who can think is all. This is all AI and some wits. LOL. This will take months to do.

              RogerCooper 1 Reply Last reply Reply Quote 3
              • RogerCooper
                RogerCooper @Kindwind last edited by

                @kindwind Why don't you try the Minimap scenario? It uses a simplified version of the Revised rules with a small, simple map.

                Kindwind 1 Reply Last reply Reply Quote 2
                • Kindwind
                  Kindwind @RogerCooper last edited by

                  @rogercooper had no idea that was a thing. I just started to work with code using AI. I just build everything that I thought I would have needed. My AI uses an alpha go style MCST. That's all I know really.

                  RogerCooper 1 Reply Last reply Reply Quote 1
                  • RogerCooper
                    RogerCooper @Kindwind last edited by

                    @kindwind If you want to try a neural net AI for TripleA, you would need to modify TripleA to support repeated self-play. For example of programs that support repeated self-play checkout Ludii & Chess Arena.

                    Supporting repeated self-play would be project of moderate difficulty in Java. (TripleA already supports self-play). You would need to learn Java (Vibe coding doesn't cut it).. Repeated self-play would also be useful for balancing mods.

                    I don't know how well a neural net would play TripleA. The number of possible moves in Go is a most 361, far fewer than the number of possible moves in a TripleA game. An effort to get a neural net to play a 2-player Risk variant did not go well.

                    One advantage is that TripleA already has heuristic AI's that could be used to train a neural net.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Copyright © 2016-2018 TripleA-Devs | Powered by NodeBB Forums