A House Divided A House DividedDocumentation
↵
Changelog
Game Design/Elections & Campaigns

Elections

Last updated 2026-10-29
Player wikiElections: A Granular Player Guide
Source files

Summary#

Elections run perpetually across five US race types: House, Senate, Governor, State Senate, and President (other countries add their own types, see UK Elections, Germany Elections and Japan Elections). Each election has a primary phase (intra-party competition) followed by a general phase (inter-party competition). One turn = one hour; timers advance each turn.

Player guide: Election Mechanics, with Primaries and General Elections

The vote math itself (appeal, reach, swing flow, drivers) is documented in Election Engine; this page covers the race lifecycle, primaries, entry and withdrawal, and the presidential specifics.

Rules#

Election types#

Type Seats Scope Notes
House 435 total (by state) Per state Multi-seat; proportional allocation
Senate 100 (2 per state) Per state, per class Single-seat; 3 staggered classes
Governor 50 (1 per state) Per state Single-seat
State Senate Varies Per state Multi-seat; proportional allocation
President 1 (national) National (state: "US") Electoral College; 270 to win

The seat counts are the modern map. Era presets use their own apportionment (HOUSE_SEATS_1991, a 48-state 1953 map with 531 electoral votes) through getHouseSeats(preset) and getElectoralVotes(preset) in .

Seat identifiers#

Each political seat has a stable seatId that persists across election cycles, enabling external systems (Discord bots, APIs) to reliably track races.

Format: {countryId}-{electionType}-{localRegionId}[-{senateClass}]

Seat seatId
Pennsylvania Senate Class 1 US-senate-PA-1
Pennsylvania House US-house-PA
California Governor US-governor-CA
U.S. President US-president
London Commons UK-commons-LON
Scotland Commons UK-commons-SCO

Historical race IDs append the cycle number: US-senate-PA-1-c3 (third cycle).

The seats collection stores permanent seat documents with display names. Elections reference seats via the seatId field. Source: , .

Election routes accept either an election ObjectId or a seatId slug such as US-president in the [id] segment. A slug resolves to the active election for that seat, else the upcoming one, else the latest cycle (resolveElectionRouteParam in ).

Election phases#

Primary phase#

General phase#

Phase boundaries are read turn-first with a Date fallback for un-backfilled documents (hasElectionStarted, isPrimaryEnded, isElectionEnded in ).

Duration by race type#

48 turns = 1 year in game time. The general phase is 24 turns for every type in the table (generalDurationHours in DEFAULT_DURATIONS); the primary is the rest of the window.

Type Total Duration Primary Duration General Duration
House 96 hours (2 years) 72 hours 24 hours
Senate 288 hours (6 years) 264 hours 24 hours
Governor 192 hours (4 years) 168 hours 24 hours
State Senate 192 hours (4 years) 168 hours 24 hours
President 192 hours (4 years) 168 hours 24 hours

Commons, regional council, Bundestag, Landtag and snap or by-election types run 48 hours in total with a 24 hour primary and 24 hour general. Shugiin is 192/168/24 and Sangiin 144/120/24.

New elections use the canonical DEFAULT_DURATIONS and the canonical schedule, not the prior cycle's timers, so an admin timer edit does not drag the calendar. Source: (re-exported from src/lib/turn/perpetualElections.ts).

Senate class stagger#

Each state's two seats belong to two of three classes (SENATE_CLASSES_BY_STATE in ). The first-cycle end turn of each class comes from the world's anchor year: under the 2019 default senateClass3 is 2022, senateClass1 2024 and senateClass2 2026; under the 1991 default 1992, 1994 and 1996 (). Anchors are 2 game years apart, so the classes end 96 turns apart. Later cycles add durationHours (288) to the class anchor ().

Primary resolution#

When the primary has ended, resolvePrimariesIfNeeded() in :

  1. Finds elections that are past their primary but not yet ended (turn-first filters)
  2. For each party with multiple candidates, ranks candidates by the path that applies:
    • Presidential (all countries except RU and BR): delegate totals from the stagger waves; if no delegates were awarded yet, the national sum of real per-state votes; if neither exists (admin-forced resolution), the presidential primary score. On a ruleset with conventionEnabled and every wave run, a no-majority nomination resolves through the convention (resolveNominationForParty).
    • Down-ballot with ballots: the cumulative primary ballots (primaryVotes on the tally) accrued turn by turn.
    • Down-ballot with no ballots (no registration figure for the party, or a legacy race mid-flight): the primary score below.
  3. Takes the top N per party, where N comes from getPrimaryWinnersForElection: 1 for presidential races and single-winner executives, 3 for parliamentary legislatures, 7 for one-party states (CN, RU, DD). Others are marked withdrawn.
  4. Writes primaryResults to the tally, sends win and loss notifications to player candidates, and initialises (or creates if missing) the general vote tally.

Resolution is idempotent: it is keyed on tally.primaryResults, so a past-primary race is resolved exactly once.

Primary score#

Used every turn for the standings display, as the split for each turn's ballots, and as the fallback ranking. The raw score is multiplied by an infamy penalty, 1 − 0.05 × (infamy/100), for player characters (NPPs have no infamy), and by NPP_PRIMARY_SCORE_MULTIPLIER = 0.5 for an NPP that shares a primary with a player.

State-level races (House, Senate, Governor, State Senate):

Presidential (national, no state-position component):

Weights and clamps live in (calcPrimaryScore, calcPresidentPrimaryScore, scorePrimaryCandidate) and (INFAMY_PENALTY_MAX = 0.05). The score is rounded to one decimal. Displayed share is a softmax of the scores, exp((score - max) / 8) normalised (PRIMARY_SHARE_SOFTMAX_TEMPERATURE = 8, one decimal). The softmax never reorders candidates, so it affects the number shown and the ballot split, not the ranking.

Primary ballots (down-ballot races)#

Ballots accrue only over the closing stretch of the primary (primaryBallotWindow, ): the window starts at primaryEndTurn - min(primaryLength, generalLength), so a standard race (24-turn general) counts primary ballots for the last 24 turns. Each party's electorate is the region's turnout pool times that party's registration share (partyPrimaryPools, min(100, registration) / 100); a party with no registration figure gets no pool. Each turn releases a slice of that pool using the same turnVoteWeight curve as the general, split among the party's candidates by that turn's softmax shares, with increments rounded to whole ballots (accruePrimaryBallotTurn). The cumulative count picks the nominee, so a sustained lead beats a late surge. Independents and the unregistered are outside every party pool.

Presidential primary waves#

During the stagger window, states vote in six waves (Iowa, New Hampshire, Nevada plus South Carolina, a 14-state Super Tuesday, mid-March states, all remaining) modelled on the 2020 calendar (PRIMARY_WAVES, , delegate tables from ). The compressed schedule fits all six into the final STAGGER_WINDOW_TURNS = 6 turns; the stretched schedule spaces them over STAGGER_WINDOW_TURNS_STRETCHED = 41 turns. Which schedule a race runs is stamped by its ruleset (primaryCalendar, below). Delegate majority comes from getDelegateMajority(family, preset).

Vote accumulation (general phase)#

Handled by the src/lib/electionEngine/ module (accumulateVoteTurn() in tallyManagement.ts). The full pipeline, pool bands, caps and swing-flow drivers are in Election Engine; this section keeps the lifecycle-level rules.

Model#

FPTP and RCV vote splitting#

The voting system used by each state determines whether the vote-splitting (spoiler) effect is applied after the group-level allocation.

First Past the Post (FPTP), default. In FPTP states, third-party candidates create an explicit spoiler effect:

  1. After group-level votes are distributed, for each third-party candidate in the race, FPTP_SPOILER_RATE (4%) × the third party's own group-level allocation is drawn from the ideologically nearest major-party candidate (per getMajorPartiesForRegion(countryId, parentRegionId), e.g. Democrat/Republican in the US, Labour/Conservative in England, SNP/Labour in Scotland) and transferred to the third party.
  2. "Nearest" is measured by Manhattan distance on the economic / social policy grid.
  3. This models the real-world vote-splitting dynamic: a Green Party candidate on the left bleeds coalition voters from the Democratic candidate, potentially handing the race to the Republican.

Political implications (design intent):

Example (FPTP, Texas):

Candidate Party Group-level votes After FPTP spoiler
Adams Democrat 400,000 392,000 (−8,000)
Brooks Republican 450,000 450,000 (unaffected)
Chen Green 200,000 208,000 (+8,000)

Green is ideologically near Democrat. 4% × 200,000 = 8,000 spoiled, drawn from Dem. Rep is unaffected.

The key outcome: Democrat loses 8,000 votes; Green gains 8,000, but Green still finishes second. Republican wins with the plurality. In a tighter race the 8,000-vote swing is enough to flip the seat.

Ranked Choice Voting (RCV), optional (legislated per state). In RCV states, no vote-splitting adjustment is applied. Third parties compete on equal footing with major parties:

Implementation: FPTP_SPOILER_RATE is defined in src/lib/electionEngine/constants.ts. Major parties for the spoiler step come from getMajorPartiesForRegion() in , the same helper used in src/lib/electionEngine/voteDistribution.ts and in-race poll math in src/lib/actions/pollCalculations.ts (invoked from ). The voting system is stored per state in states.votingSystem ("fptp" | "rcv", defaults to "fptp"). One-party states also skip the step.

Total appeal pipeline#

Two distribution paths exist. Primaries and commissioned polls use the group-level competitive allocation model described below (each demographic group votes as a bloc, splitting its vote pool among candidates by relative appeal). General-election vote accumulation defaults to the swing-flow model (distributeVotesBySwingFlow() in src/lib/electionEngine/voteDistributionSwingFlow.ts, chosen in tallyManagement.ts whenever the race is in its general phase); group-level allocation remains available as a fallback/legacy path for generals but is not the live default. See Election Engine for the swing-flow driver stack (coattails, median-voter, persuasion, incumbency; term fatigue now lives in the economic referendum channel, src/lib/electionEngine/economicReferendum.ts). The appeal/reach/approval math below is the shared foundation both paths build on.

The full pipeline from candidate and state to votes per turn (shared with poll and NPP dropout via ):

Stat used by race type:

  • State races (House, Senate, Governor, State Senate): use Political Influence (politicalInfluence, capped 0-100)
  • Presidential race: use National Political Influence (nationalInfluence)
  1. Reach, normalizeNPI(influence): fraction of turned-out voters the candidate can reach. Sqrt curve, hard-capped at 1.0 once PI/NPI reaches 100. Both state and presidential general elections use this curve. Presidential primary reach uses the separate diminishing-return function 1 - exp(-NPI/45).
  2. Appeal (per demographic group), Position score 25 × (positionRaw/50)^1.5 + floor, where positionRaw = max(0, 50 − |econDiff|×5 − |socialDiff|×5) and APPEAL_POSITION_EXPONENT = 1.5 (), plus a directional (tribal-voter) bonus of up to DIRECTION_BONUS_PER_AXIS = 5 per axis, plus an optional normalizeNPI(influence) × 12.5 term. No live election path switches that term on (includeInfluenceInAppeal is false everywhere), so influence acts through reach only. Appeal is capped at MAX_APPEAL = 50 and does NOT include favorability, that scales at the end. (γ=2, the legacy squared curve, is still supported as a special case but is not the live default.)
  3. Group-level competitive allocation, Each demographic group contributes to the turn pool proportionally to its size. Within each group, candidates split that contribution by relative (appeal × reach × approval × partyOrg × infamyMult). Groups vote as blocs; higher appeal with a group yields a larger share of that group's votes.
  4. Approval scalar, (favorability / 100)^0.8: voters will not support candidates they do not approve of, while the exponent softens the middle of the curve. 0% approval = 0 votes.
  5. Party org scalar, General elections: normalizedOrgShare ^ ORG_WEIGHT_EXPONENT (ORG_WEIGHT_EXPONENT = 0.2), the party's normalized share of statewide Org among all parties, with diminishing returns; no Org data anywhere falls back to a neutral 1×. Primaries use a uniform neutral 1× (intra-party Org cancels). This retired the older flat 0.5 + (org/100)×0.5 scalar (2026-06-18).
  6. Infamy scalar, 1 − 0.05 × (infamy/100): player characters lose up to 5% of their per-group weight at infamy=100. NPPs leave infamy unset and are unaffected.
  7. Party strength modifier, (1 + (approvalDecimal − 0.5) × 0.2) × officeStrength for state races (× 0.5 in place of × 0.2 for president, so presidential races feel state approval 2.5x more strongly):
    • State government approval: 0-100% from state metrics vs. national averages (see Government Approval). When metrics are missing, 50% is used. At 50% approval the modifier is 1.0x baseline regardless of office; state races swing ±10% (0% approval → 0.9x, 100% → 1.1x) before the office-strength factor, president swings ±25% (0.75x-1.25x).
    • Office strength: Governor 1.0, House 0.9, Senate 0.8, State Senate 0.85, President 1.0.
  8. Effective turn pool, Base turn pool × party strength modifier. Same modifier for all candidates in that election; relative shares are unchanged.
  9. Distribution, For each group, its share of the effective turn pool is split among candidates by relative (appeal × reach × approval × partyOrg × infamyMult). Votes per candidate are summed across all groups.

Factors affecting votes#

Factor Effect
Policy alignment Power curve, exponent 1.5: 25 × (positionRaw/50)^1.5 + floor, positionRaw = 50 − econDiff×5 − socialDiff×5; closer = higher appeal
Political influence (PI) State races only, reach (not appeal). Capped 0-100; max reach = 1.0
National Political Influence (NPI) Presidential race only, sqrt scaling via normalizeNPI, hard-capped at 1.0 once NPI reaches 100. Above 100 it saturates (no celebrity bonus).
Favorability (approval) Final scalar: (favorability/100)^0.8 (APPROVAL_SCALAR_EXPONENT); 0% approval = 0 votes
Party org Final scalar in general elections: normalizedOrgShare ^ 0.2 (ORG_WEIGHT_EXPONENT), a party's normalized share of statewide Org with diminishing returns. Primaries use a uniform neutral 1×.
Government approval Scales the turn pool by 1 + (approval - 0.5) × 0.2 (× 0.5 for president), then by office strength; see the pipeline above
Office strength Governor 1.0, House 0.9, Senate 0.8, State Senate 0.85, governor races most affected by approval
Voting system (FPTP/RCV) FPTP: third-party candidates gain FPTP_SPOILER_RATE × their own allocation drawn from nearest major party (spoiler effect). RCV: no adjustment.

Campaign actions raise favorability and influence; ads raise recognition and favorability.

Polls versus simulated votes#

State and general elections (House, Senate, Governor, State Senate, Commons, etc.): Commissioned polls use the group-level competitive allocation and FPTP spoiler rules, including region-aware major parties and per-archetype effective favorability for opponents when that data exists (src/lib/actions/pollCalculations.ts, ). Turn-by-turn general-election vote accumulation itself defaults to the swing-flow model instead (see above); polls are an appeal-based projection and do not replay the swing-flow driver stack.

Presidential: Simulated votes are accumulated per electoral unit in src/lib/presidentialElectionEngine.ts (averaged party vs character positions, national influence for reach, influence kept out of appeal, state/district lean, independent penalty, swing-state ground game). The FPTP spoiler step is applied at half rate (PRESIDENTIAL_SPOILER_RATE = 2%) on the presidential distribution path to prevent fragmented fields from producing EC landslides via winner-take-all. Player polls remain home-state projections and do not replicate the national presidential model, treat poll topline and in-race breakdowns as indicative for the character's state, not as an Electoral College forecast.

Multi-seat races (House, State Senate)#

Senate elections#

Governor elections#

Candidacy rules#

Election entry API#

Endpoint: POST /api/elections/[id]/enter ()

Validation (the route also carries country-specific filing branches for Hungary, Bulgaria and Russia that are documented on the country pages):

Check Response
Election is upcoming or active 400 "This election is not open for entry"
Primary not ended 400 "The primary entry period has ended. You cannot join the race."
Country matches the character's 403 "This election is for {X} characters only..."
Home state matches (President is national) 403 "You can only run for office in your home state"
One-party state: ruling party only for executive offices, no banned or independent candidates 403
Executive term limit not reached (nationwide executive races) 400 "This character has already served the maximum number of {office} terms."
Not already entered under the same party 400 "You are already entered in this race"
Not previously withdrawn from this election (Hungarian and Bulgarian district filings exempt) 403 "You withdrew from this race and cannot re-enter it."
No other blocking active candidacy (findBlockingActiveCandidacy) 400 "You are already running in the {race}. Withdraw first before entering a new race."

Party switching: If already entered under a different party, the old candidacy is auto-withdrawn before creating the new one and the campaign is carried across with its funds and levels (ticket #1313).

Re-entry carry-over: a withdraw and re-enter in the same live primary carries forward the one-rally-per-turn throttle and the one-per-cycle home-state surge gate, so re-entering cannot reset them.

Achievement trigger: Election entry triggers achievement checks via checkElectionEntryAchievements().

Withdrawal mechanics#

Endpoint: POST /api/elections/[id]/withdraw ()

Effects:

  1. Mark the candidate withdrawn with withdrawnAt and withdrawnBy: "candidate"
  2. Remove votes from the tally (removeWithdrawnCandidateFromTally)
  3. Archive the campaign document (status: "archived", archivedReason: "withdrawn"). Hard deletion happens only when the election resolves.
  4. Write an election.withdraw audit record

Restrictions:

Election continuity#

All race types run perpetually:

Presidential election#

API: POST /api/elections/[id]/running-mate ()

Validation, in the route's own order: the election is a presidential race and active; the caller is a candidate in it; the id is valid; the current President is refused; the character exists and passes the eligibility checks; not the caller themselves; same country; a term-limited character is refused where blocksRunningMateSelection is true; the character is not already a candidate in this election. The route accepts a character ObjectId or "" to clear, and writes runningMateId and updatedAt on the candidate row.

Presidential rulesets#

A presidential race is stamped with a ruleset version at spawn (election.rulesetVersion, ). Unstamped races resolve to v1 and an unknown future stamp falls back to the newest known ruleset. Current version: CURRENT_PRESIDENTIAL_RULESET_VERSION = 3.

Field v1 and v2 v3
campaignStrengthMaxBonus 1 (multiplier approaches 2x) 0.25 (approaches 1.25x)
applyExplicitLeanMultiplier true false
tacticalMovementRate 0 0.05 (share of nonviable candidates' new ballots that move in the closing turns)
incumbentApprovalStateWeight 0 0.5
primaryCalendar "compressed" "stretched"
conventionEnabled false true
suspendTransferMode "flat" "affinity"
primaryMomentumCapPoints, endorsementOrgFraction, endorsementCoalitionCredibility 0 0 (identity until calibrated)
vpSurrogateActionCap, vpTravelPresenceWeight 2, 1 2, 1

NPP election participation#

See NPP System for full documentation. NPPs autonomously enter and drop out of elections each turn via processElectionEntry() in .

Entry#

Dropout and elimination#

Spawn (admin)#

Admin → Elections → NPP Management: spawn 1-500 NPPs per party with weighting (lean / members / both).

Presidential travel#

Presidential candidates can travel to specific states to campaign in person.

API: POST /api/elections/[id]/travel (). The action debit and the travel-state write are crash-safe: a keyed idempotent money-flow leg (header Idempotency-Key, issue #1672) means a crash between the writes reconciles instead of charging for a move that never landed. The route validates: the election is a presidential race and active; the caller is an active, non-suspended candidate; the state code is valid; the caller has enough actions; the state differs from the current travel state. It writes travelState and traveledAt on the candidate row.

Travel is a presidential-only mechanic. State-level races use standard campaign/ads actions instead.

Campaign strategy#

Building support#

Attack strategy#

Geographic strategy#

Polling and display#

Elections hub#

/elections is a redirect shell to the player's country page, /country/<code>/elections (), which is the central listing of all elections across race types and states for that country.

County and district maps#

State-level results for presidential, governor and senate elections can be explored at /elections/[id]/state/[stateId].

Constants#

Constant Value Source
Election durations (total / primary / general hours) House 96/72/24, Senate 288/264/24, Governor, State Senate, President 192/168/24 DEFAULT_DURATIONS,
Turns per game year 48 (one turn per real hour)
Senate class stagger 2 game years (96 turns), from the anchor years senateClass1 to senateClass3,
Vote pool bands early 0.5, ramp 0.2 (8 turns), final 0.3 (4 turns) EARLY_POOL_SHARE, RAMP_POOL_SHARE, RAMP_TURNS, FINAL_POOL_SHARE, ELECTION_DAY_TURNS, src/lib/electionEngine/voteCalculations.ts
FPTP spoiler rate 0.04 state, 0.02 presidential FPTP_SPOILER_RATE, PRESIDENTIAL_SPOILER_RATE, src/lib/electionEngine/constants.ts
NPP weights 0.8 general, 0.5 primary score NPP_GENERAL_WEIGHT_MULTIPLIER, NPP_PRIMARY_SCORE_MULTIPLIER, constants.ts
Position exponent / approval exponent 1.5 / 0.8 APPEAL_POSITION_EXPONENT, APPROVAL_SCALAR_EXPONENT,
Org exponent 0.2 ORG_WEIGHT_EXPONENT, src/lib/electionEngine/electionFormulaFactors.ts
Party strength modifier 1 + (approval - 0.5) × 0.2 state, × 0.5 president LEGISLATIVE_APPROVAL_VOTE_SLOPE, PRESIDENTIAL_APPROVAL_VOTE_SLOPE, src/lib/electionEngine/approvalVoteMultiplier.ts
Office strength Governor 1.0, President 1.0, House 0.9, State Senate 0.85, Senate 0.8 partyStrengthWeight,
State primary score weights alignment 25 state + 15 party (40 party-only fallback), favorability 35, influence 25 calcPrimaryScore,
Presidential primary score weights alignment 40, party influence 20, national reach 15, favorability 25 PRESIDENT_PRIMARY_*_WEIGHT,
Primary share softmax temperature 8 PRIMARY_SHARE_SOFTMAX_TEMPERATURE,
Infamy score penalty up to 5% at infamy 100 INFAMY_PENALTY_MAX,
Independent presidential vote penalty 0.3 INDEPENDENT_VOTE_PENALTY, src/lib/presidentialElectionEngine.ts
State lean tiebreaker 0.1 per point (0.3 for ME/NE districts), clamped 0.8 to 1.2 (v1 and v2 rulesets only) STATE_LEAN_STRENGTH, DISTRICT_LEAN_STRENGTH, LEAN_MULT_MIN, LEAN_MULT_MAX, presidentialElectionEngine.ts
Presidential position blend partyPositionWeight 1/3, so 75% candidate and 25% party presidentialElectionEngine.ts
Electoral votes 538 total, 270 to win (modern map) TOTAL_ELECTORAL_VOTES, ELECTORAL_MAJORITY,
Travel action cost EV 5 or less: 3, 10 or less: 5, 20 or less: 7, above 20: 10 getTravelActionCost,
Multi-seat minimum share US House clamp(1/(seats+1), 10%, 20%), 20% non-US House and unlisted types, 10% listed chambers getMultiSeatMinShare, src/lib/turn/election/rules/seatEligibility.ts
Net favorability swing per target per turn 12 MAX_NET_FAVORABILITY_SWING_PER_TURN,
Attack cost 2 infamy, -1 target favorability
Campaign / advertise base fund cost 20,000 / 100,000 (before tier and GDP scaling) CAMPAIGN_BASE_FUND_COST, ADVERTISE_BASE_FUND_COST,
Fundraise action cost 3 action points FUNDRAISE_ACTION_COST,
Stagger window 6 turns compressed, 41 stretched STAGGER_WINDOW_TURNS, STAGGER_WINDOW_TURNS_STRETCHED,

Data#

Collection Purpose Key fields
elections Active, upcoming, completed elections countryId, electionType, state, seatId, senateClass, chamberClass, cycle, status (upcoming, active, completed, resolved, cancelled), startTurn, primaryEndTurn, endTurn (and Date twins startTime, primaryEndTime, endTime), durationHours, totalSeats, electionYear, rulesetVersion, allocationMethod, campaignRulesVersion, resolving
electionCandidates Candidates per election electionId, characterId, characterName, party, status (active or withdrawn), isNPP, seatsRequested, enteredAt, withdrawnAt, withdrawnBy, runningMateId, travelState, traveledAt, support
electionVoteTallies General-phase totals, snapshots, seats estimate, primary ballots totalVotes, candidateNames, candidateParties, turnSnapshots, seatsEstimate, primaryVotes, primaryResults, presidential: totalVotesByUnit, unitTurnSnapshots, primaryDelegates, primaryStateVotes, primaryWaveHistory, electoralVotesByCandidate, resolutionMode; finalized
primarySnapshots Hourly primary standings for trend display electionId, turn, slicePart, byParty[] of primaryScore and sharePct per candidate
seats Permanent seat documents seatId, display name
electedOfficials Current office holders, updated at resolution office, holder, party
campaigns Per-candidate campaign state electionId, candidateId, status (archived on withdrawal), funds and levels
characters Candidate stats read by scoring and entry favorability, politicalInfluence, nationalInfluence, partyInfluence, infamy, homeState, countryId, careerHistory, executiveTermsServed

Player-visible: election lists, candidate rosters, tallies and shares, primary standings, seat estimates, electoral maps and candidate travel badges. Not player-visible: resolving, allocationMethod, ruleset internals, withdrawnBy.

Election engine module structure#

The election vote calculation pipeline is implemented across two modules.

src/lib/electionEngine/, core vote calculation engine#

File Purpose
voteDistribution.ts Group-level competitive allocation: distributes votes by demographic blocs using appeal × reach × approval × partyOrg; applies FPTP spoiler effect. Used for primaries and polls; fallback/legacy path for generals
voteDistributionSwingFlow.ts Two-phase pairwise swing-flow allocation; default vote model for general elections. Layers coattails, median-voter, persuasion, and incumbency drivers on top of the base appeal calculation
tallyManagement.ts Accumulates vote turns, initializes tallies, computes seat estimates for multi-seat races
voteCalculations.ts Turn vote weight formula (three-tier closing surge: 50% early / 20% ramp / 30% final 4 turns), state turnout calculation
resolvedTurnout.ts Combines static StateDemographics.turnout with dynamic StateDemographicTurnout.modifiers from GOTV and canvassing
candidateEnrichment.ts Fetches character/NPP data and merges with candidate records for vote calculations
types.ts EnrichedCandidate, DistributeVotesOptions, AccumulateVoteTurnPreload
constants.ts FPTP_SPOILER_RATE (0.04), PARTY_STRENGTH_BY_OFFICE (deprecated, now in CountryConfig)

src/lib/elections/, API helpers and election lifecycle#

File Purpose
electoralVoteService.ts Presidential Electoral College computation, per-unit EV allocation, map data, EV-by-turn tracking
buildPollingData.ts Poll computation using same group-level allocation as vote accumulation
enrichElection.ts Full election enrichment with candidates, tally, polling data
resolveElection.ts General election resolution: winner determination, seat allocation, NPP influence updates
candidateEnrichment.ts Alternative enrichment for API responses (includes party logos, campaign IDs)
electionParamResolution.ts Resolves an election route segment (ObjectId or seatId slug) to an election
voteTallyService.ts Simple tally fetcher for API responses
phases.ts Turn-first phase helpers (hasElectionStarted, isPrimaryEnded, isElectionEnded, computeElectionPhase)
activeCandidacy.ts Checks if a character has an active candidacy (for validation)
electionResponseTypes.ts TypeScript types for API response shapes

Configuration#

Setting Default Where set
Race durations see Duration table DEFAULT_DURATIONS in
Calendar anchors (Senate classes, president, other cycles) per preset ,
gameState.preset per world (1953-default, 1991-default, 2019-default) Chooses apportionment, electoral map and anchors
election.rulesetVersion unstamped = v1, new US presidential races stamp 3
election.campaignRulesVersion unset = legacy campaigning for that race Stamped at spawn
election.allocationMethod unset = country default Frozen when the race opens
states.votingSystem "fptp" State document, changed by legislation
Office strength see Constants partyStrengthWeight per office in each country's institutionsFacts.ts
Presidential primary calendar "stretched" on v3, "compressed" on v1 and v2 Ruleset primaryCalendar
gameState.fastMode off Turns every 30 minutes; skips the half-hour results tick

Primary-phase campaign constants (src/lib/electionEngine/constants.ts), used by the presidential primary waves and home-state tools:

Constant Value
PRIMARY_PARTY_FIT_WEIGHT 0.3 (party-fit penalty strength in primaries)
NPP_STAGGER_EXTRA_MULTIPLIER 0.6 (stacks with 0.8, combined 0.48)
PRIMARY_CAMPAIGN_TICK_CAP 5
PRIMARY_HOME_SURGE_PCT / cost 15% / 25,000 funds and 3 actions
MAX_PARTY_INFLUENCE_BONUS_PRIMARY 0.4
MAX_STATE_ORG_BONUS_PRIMARY / HOME_STATE_BONUS_PRIMARY 0.25 / 0.2
PRIMARY_STATE_ATTACK_DURATION_TURNS 8
PRIMARY_LOCAL_ATTACK_FAV_POINTS / cost 6 points / 40,000 funds and 4 actions
PRIMARY_VOTE_SUPPRESSION_PCT / cost 10 / 70,000 funds and 5 actions
PRIMARY_VOTE_SUPPRESSION_FLOOR 0.85 (no candidate loses more than 15% of a state's vote)

The primary constants above are marked "first pass" in code comments and may be retuned.

Timing#

Election steps run once per turn as strictly sequential sub-phases of the electionResolutionAndGovernment phase in :

  1. Withdraw inactive candidates (withdrawInactiveCandidates)
  2. Candidate party sweep (candidatePartySweep), withdraws stale or ineligible candidacies after party switches
  3. Resolve primaries (primaryResolution), eliminates losers when the primary ends; must run before vote accumulation
  4. Accumulate general election votes (voteAccumulation), one turn of votes for all active general-phase elections (and the presidential stagger waves first); must run before timer advancement
  5. Campaign spend reset (campaignSpendReset), clears Campaign.spendThisTurn after the tallies have read it
  6. Advance election timers (electionTimers), marks elections "completed" when endTurn passes
  7. Record primary snapshots (primarySnapshots), for elections still in primary phase (trend data and primary ballot accrual)
  8. Resolve completed general elections (electionResolution), determines winners, updates electedOfficials, spawns next cycle
  9. Clear resolved support, vacate leadership (clearResolvedSupport, leadershipVacate), removes leadership from members who lost/changed office
  10. Parliamentary government formation (parliamentaryGovernmentFormation)

NPP behavior, bill lifecycle and the campaign turn (income, actions, maintenance) run in other phases. A half-hour tick between turns banks the early half of the next vote slice and primary ballots (see Election Engine); deadlines stay on the hour.

Critical ordering (documented in the registry): primaries resolve → votes accumulate → timers advance → elections resolve. Reordering would lose final-turn votes or include eliminated candidates in tallies.

flowchart TD
  U[Upcoming: filing opens at startTurn] --> PR[Primary phase: entry open, standings recorded each turn]
  PR --> BW[Ballot window or delegate waves in the closing stretch]
  BW --> PE[primaryEndTurn: resolvePrimariesIfNeeded]
  PE --> G[General phase: accumulateVoteTurn each turn, 24 turns]
  G --> EN[endTurn: timers mark completed]
  EN --> RS[resolveGeneralElections: winner, electedOfficials, next cycle spawned]
  RS --> GV[Leadership vacated, government formation]

Worked trace#

Primary score and ballots (state race)#

Score. Candidate A: economic lean 1.0, social 0.5, favorability 60, political influence 49, infamy 20. State lean (1.5, 0.0), party position (2.0, 1.0).

Rival B has alignment 30, favorability 70 (24.5), influence 64 (20) and no infamy: raw 74.5, score 74.5. A leads by 0.9 points. Had A carried infamy 100 the multiplier would be 0.95 and A would score 72.3 and trail, so infamy matters mainly in close primaries.

Shares. Softmax at temperature 8: exp(0) = 1 for A and exp((74.5 - 75.4) / 8) = 0.8936 for B. A gets 1 / 1.8936 = 52.8%, B 47.2%.

Ballots. The race is in its ballot window (the last 24 turns of the primary). The region's turnout pool is 500,000 and the party's registration share is 40%, so the party pool is 200,000. A 24-turn window has 12 early turns, 8 ramp turns and 4 final turns:

Band Per turn A at 52.8% B at 47.2%
Early (12 turns) 0.5 × 200,000 / 12 = 8,333 4,400 3,933
Ramp (8 turns) 0.2 × 200,000 / 8 = 5,000 2,640 2,360
Final (4 turns) 0.3 × 200,000 / 4 = 15,000 7,920 7,080

If the standings held all window the cumulative count would be 105,600 for A and 94,400 for B (the 200,000 pool split 52.8 to 47.2), so A is nominated by ballots. A late rival surge in the final band moves at most the 30% share held by that band, which is why a sustained lead beats a late surge. At resolution the count, not the score, picks the nominee; the score ranking applies only if the party had no ballots.

Presidential general under a v1 ruleset (lean multiplier)#

A state with display lean -2 and a candidate on the left (epSign = -1): 1 + (-2)(-1)(0.1) = 1.2, inside [0.8, 1.2], so that candidate's votes are multiplied by 1.2 and a right-leaning rival gets 1 + (-2)(+1)(0.1) = 0.8. That is the 1.5:1 swing (1.2 / 0.8) the cap allows. For ME congressional district 1 (UNIT_LEAN = -0.1): 1 + (-0.1)(-1)(0.3) = 1.03. On a v3 race neither multiplier runs.

Electoral College#

On the modern map electoralMajorityFor(538) = floor(538 / 2) + 1 = 270. Candidate A carrying states worth 270 EV wins outright. At 269 each the tie is broken by a deterministic coin flip derived from the election id and candidate ids, so a rerun of the resolution gives the same answer. If nobody has a majority the race goes to the Contingent Election.

Travel#

A candidate travelling to Wyoming (3 EV) pays 3 actions; to Pennsylvania (19 EV) pays 7; to California (54 EV) pays 10. While travelState is set the candidate gains +1.0 favorability each turn.

The general-phase vote chain (pool, caps, group split, spoiler) is traced with numbers in Election Engine.

Edge cases and limits#

Invariants#

Invariant Enforced by
A character has at most one blocking active candidacy findBlockingActiveCandidacy (activeCandidacy.ts); activeCandidacy.test.ts
A withdrawn candidate cannot re-enter the same election Enter route check; ("refuses re-entry after the character withdrew")
A primary resolves exactly once per election Idempotency keyed on tally.primaryResults; primaryResolution.test.ts (no re-initialise cases)
A stalled turn that is re-run does not bank a primary slice or a vote slice twice Per-turn snapshot guard; primaryResolution.test.ts, tallyManagement.test.ts
Each general window releases exactly the pool and never more than the registered electorate See Election Engine invariants
Sub-phase order: primaries, accumulation, timers, resolution Registry comment only; not enforced by a test
Every seat has a stable seatId that is parseable back to its region
Ruleset stamped at spawn never changes for a live race Not enforced by a test; the stamp is only read, never rewritten, in the code paths reviewed
Voting system flag only switches the spoiler step Not enforced by a dedicated test

Failure and recovery#

Connections#

Driven by:

Affects:

Related documentation: Core Systems (turn structure, term cycles), Technical Architecture (implementation status), Cabinet (cabinet nominations use Senate confirmation, a related process).

Tests#

Test file Covers
Primary resolution, ballot-based nominee, NPP elimination, advancers per party, snapshots, accumulation entry points
Ballot window, party pools, accrual, share conversion
Per-turn primary snapshots
State and presidential primary score
and its country siblings Spawning and continuity, including presidentialRespawn, openImmediately, houseApportionment
, src/lib/turn/electionResolution.test.ts, src/lib/turn/election/generalResolution.test.ts Timer advance and resolution
, electionTiming.test.ts Phase helpers
, entryEligibility.test.ts Candidacy rules
, travel/route.test.ts Enter and travel routes
, presidentialGeneralRules.test.ts, src/lib/presidentialElectionEngine.test.ts Presidential rulesets and engine
Canonical schedule
Seat identifiers
Era-aware electoral and contingent majorities
src/lib/turn/election/rules/seatEligibility.test.ts Multi-seat minimum shares

Engine-level coverage is listed in Election Engine. Known gaps: there is no test for the withdraw route (src/app/api/elections/[id]/withdraw/), none pins the DEFAULT_DURATIONS table, and the sub-phase order has no test.

Known issues and history#

Last checked: 2026-10-29, version 1.18.0

Ask