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:
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.
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.
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 deviation. |
|
Detect rightist deviation. |
|
Run all three trap detectors and produce a combined result. |
|
Detect ultra-left deviation. |
Classes
|
Full trap detection output for a single tick. |
|
How deep into a trap the player has fallen. |
|
Current trap detection state for a player organization. |
|
The three strategic deviation traps. |
- class babylon.engine.trap_detection.TrapType(*values)[source]
Bases:
StrEnumThe three strategic deviation traps.
- LIBERAL = 'liberal'
- ULTRA_LEFT = 'ultra_left'
- RIGHTIST = 'rightist'
- class babylon.engine.trap_detection.TrapSeverity(*values)[source]
Bases:
StrEnumHow 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:
BaseModelCurrent trap detection state for a player organization.
- Parameters:
trap_type (TrapType)
severity (TrapSeverity)
score (Annotated[float, Ge(ge=0.0), Le(le=1.0), AfterValidator(func=~babylon.utils.math.quantize)])
- 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:
BaseModelFull trap detection output for a single tick.
- Parameters:
liberal (TrapStatus)
ultra_left (TrapStatus)
rightist (TrapStatus)
active_trap (TrapType | None)
game_over_trap (TrapType | None)
- 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:
- Return type:
- 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:
- Return type:
- 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:
- Return type:
- 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:
- Returns:
TrapDetectionResult with all three trap statuses.