babylon.engine.trap_detection

Trap detection system for the Wayne County Organizer.

Detects three ideological deviations that represent strategic dead ends in revolutionary organizing. Each trap is grounded in historical analysis of movement failure modes:

  1. Liberal Trap: Over-reliance on electoralism and institutional reform. Signs: high budget, low cadre, high “negotiate” and “campaign” usage, organizations drift toward ClassCharacter.PETTY_BOURGEOIS. Historical examples: DSA electoral focus, co-optation by Democratic Party.

  2. Ultra-Left Trap: Premature confrontation without mass base. Signs: high “attack” usage, low sympathizer labor, high heat, territory loss from state repression. Historical examples: Weather Underground, Red Army Faction.

  3. Rightist Trap: Organizational conservatism, avoiding conflict. Signs: only “aid” and “educate” actions, no mobilization, stagnant consciousness, growing fascist consolidation. Historical examples: CPUSA during WWII popular front, NGO-ification.

Each trap triggers warnings at mild/moderate severity, and can trigger endgame at severe level if uncorrected.

Functions

detect_liberal_trap(action_history, ...)

Detect liberal deviation.

detect_rightist_trap(action_history, ...[, ...])

Detect rightist deviation.

detect_traps(action_history, org_budget, ...)

Run all three trap detectors and produce a combined result.

detect_ultra_left_trap(action_history, ...)

Detect ultra-left deviation.

Classes

TrapDetectionResult(**data)

Full trap detection output for a single tick.

TrapSeverity(*values)

How deep into a trap the player has fallen.

TrapStatus(**data)

Current trap detection state for a player organization.

TrapType(*values)

The three strategic deviation traps.

class babylon.engine.trap_detection.TrapType(*values)[source]

Bases: StrEnum

The three strategic deviation traps.

LIBERAL = 'liberal'
ULTRA_LEFT = 'ultra_left'
RIGHTIST = 'rightist'
class babylon.engine.trap_detection.TrapSeverity(*values)[source]

Bases: StrEnum

How deep into a trap the player has fallen.

NONE = 'none'
MILD = 'mild'
MODERATE = 'moderate'
SEVERE = 'severe'
class babylon.engine.trap_detection.TrapStatus(**data)[source]

Bases: BaseModel

Current trap detection state for a player organization.

Parameters:
trap_type

Which deviation is detected.

severity

How deep the deviation is.

score

Continuous score [0, 1] for this trap.

indicators

Human-readable diagnostic strings.

ticks_at_moderate

Consecutive ticks at MODERATE or above.

trap_type: TrapType
severity: TrapSeverity
score: Probability
indicators: list[str]
ticks_at_moderate: int
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class babylon.engine.trap_detection.TrapDetectionResult(**data)[source]

Bases: BaseModel

Full trap detection output for a single tick.

Parameters:
liberal

Liberal trap status.

ultra_left

Ultra-left trap status.

rightist

Rightist trap status.

active_trap

The dominant trap (highest score), or None.

game_over_trap

If any trap has reached SEVERE, this is set.

liberal: TrapStatus
ultra_left: TrapStatus
rightist: TrapStatus
active_trap: TrapType | None
game_over_trap: TrapType | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

babylon.engine.trap_detection.detect_liberal_trap(action_history, org_budget, org_cadre, org_cohesion, consciousness_avg)[source]

Detect liberal deviation.

Indicators: - High ratio of “negotiate” and “campaign” to total actions - High budget but low cadre (buying influence, not building power) - Stagnant consciousness despite activity

Parameters:
  • action_history (list[dict[str, Any]]) – Recent action dicts with ‘verb’ keys.

  • org_budget (float) – Player org budget.

  • org_cadre (float) – Player org cadre_level.

  • org_cohesion (float) – Player org cohesion.

  • consciousness_avg (float) – Average consciousness across entities.

Return type:

TrapStatus

babylon.engine.trap_detection.detect_ultra_left_trap(action_history, org_heat, sympathizer_labor, territory_count, territory_losses=0)[source]

Detect ultra-left deviation.

Indicators: - High ratio of “attack” to total actions - High heat (state has identified you as a threat) - Low sympathizer labor (no mass base) - Territory losses from repression

Parameters:
  • action_history (list[dict[str, Any]]) – Recent action dicts with ‘verb’ keys.

  • org_heat (float) – Player org heat level.

  • sympathizer_labor (float) – Current SL availability.

  • territory_count (int) – Territories the org operates in.

  • territory_losses (int) – Territories lost to repression recently.

Return type:

TrapStatus

babylon.engine.trap_detection.detect_rightist_trap(action_history, org_cadre, tick, fascist_entities=0, total_entities=1)[source]

Detect rightist deviation.

Indicators: - Only “aid” and “educate” actions (no mobilization or confrontation) - No growth in cadre over time - Rising fascism unchecked

Parameters:
  • action_history (list[dict[str, Any]]) – Recent action dicts with ‘verb’ keys.

  • org_cadre (float) – Player org cadre_level.

  • tick (int) – Current simulation tick.

  • fascist_entities (int) – Entities with dominant national_identity.

  • total_entities (int) – Total entity count.

Return type:

TrapStatus

babylon.engine.trap_detection.detect_traps(action_history, org_budget, org_cadre, org_cohesion, org_heat, sympathizer_labor, territory_count, consciousness_avg, tick, fascist_entities=0, total_entities=1, territory_losses=0, previous_result=None)[source]

Run all three trap detectors and produce a combined result.

Parameters:
  • action_history (list[dict[str, Any]]) – List of recent action dicts (last ~10 ticks).

  • org_budget (float) – Player org budget.

  • org_cadre (float) – Player org cadre_level.

  • org_cohesion (float) – Player org cohesion.

  • org_heat (float) – Player org heat.

  • sympathizer_labor (float) – Current SL.

  • territory_count (int) – Territories the org operates in.

  • consciousness_avg (float) – Average consciousness across entities.

  • tick (int) – Current simulation tick.

  • fascist_entities (int) – Entities with dominant national identity.

  • total_entities (int) – Total entity count.

  • territory_losses (int) – Territories lost to repression recently.

  • previous_result (TrapDetectionResult | None) – Previous tick’s detection result (for persistence).

Return type:

TrapDetectionResult

Returns:

TrapDetectionResult with all three trap statuses.