diff options
author | Frans Bongers <fransbongers@macbookpro.home> | 2025-03-19 21:55:43 +0100 |
---|---|---|
committer | Frans Bongers <fransbongers@macbookpro.home> | 2025-03-19 21:56:01 +0100 |
commit | 0fae284f79b1c934e58214cf5f88cad4cab6b03b (patch) | |
tree | 779e447a18042132e40036f40fc5d0af6622954a | |
parent | 19d48663a25cf6f9a93e8710f6896a2b43971fcd (diff) | |
download | land-and-freedom-0fae284f79b1c934e58214cf5f88cad4cab6b03b.tar.gz |
refactor: FrontId to number
-rw-r--r-- | data.js | 20 | ||||
-rw-r--r-- | data.ts | 20 | ||||
-rw-r--r-- | rules.js | 16 | ||||
-rw-r--r-- | rules.ts | 27 | ||||
-rw-r--r-- | types.d.ts | 12 |
5 files changed, 47 insertions, 48 deletions
@@ -28,13 +28,13 @@ const INITIATIVE_PLAYER = 'i'; exports.INITIATIVE_PLAYER = INITIATIVE_PLAYER; const ALL_PLAYERS = 'all'; exports.ALL_PLAYERS = ALL_PLAYERS; -const ARAGON = 'a'; +const ARAGON = 0; exports.ARAGON = ARAGON; -const MADRID = 'm'; +const MADRID = 1; exports.MADRID = MADRID; -const NORTHERN = 'n'; +const NORTHERN = 2; exports.NORTHERN = NORTHERN; -const SOUTHERN = 's'; +const SOUTHERN = 3; exports.SOUTHERN = SOUTHERN; const CLOSEST_TO_DEFEAT = 'd'; exports.CLOSEST_TO_DEFEAT = CLOSEST_TO_DEFEAT; @@ -1732,12 +1732,6 @@ const data = { ], fronts: [ { - id: NORTHERN, - name: 'Northern', - left: 89, - top: 96, - }, - { id: ARAGON, name: 'Aragon', left: 340, @@ -1750,6 +1744,12 @@ const data = { top: 262, }, { + id: NORTHERN, + name: 'Northern', + left: 89, + top: 96, + }, + { id: SOUTHERN, name: 'Southern', left: 205, @@ -17,10 +17,10 @@ const PLAYER_WITH_MOST_HERO_POINTS = 0; const INITIATIVE_PLAYER = 'i'; const ALL_PLAYERS = 'all'; -const ARAGON = 'a'; -const MADRID = 'm'; -const NORTHERN = 'n'; -const SOUTHERN = 's'; +const ARAGON = 0; +const MADRID = 1; +const NORTHERN = 2; +const SOUTHERN = 3; const CLOSEST_TO_DEFEAT = 'd'; const CLOSEST_TO_VICTORY = 'v'; const FRONTS: FrontId[] = [ARAGON, MADRID, NORTHERN, SOUTHERN]; @@ -1804,12 +1804,6 @@ const data: StaticData = { ], fronts: [ { - id: NORTHERN, - name: 'Northern', - left: 89, - top: 96, - }, - { id: ARAGON, name: 'Aragon', left: 340, @@ -1822,6 +1816,12 @@ const data: StaticData = { top: 262, }, { + id: NORTHERN, + name: 'Northern', + left: 89, + top: 96, + }, + { id: SOUTHERN, name: 'Southern', left: 205, @@ -410,28 +410,28 @@ function setup(seed, _scenario, options) { }, engine: [], faction_turn: null, - fronts: { - a: { + fronts: [ + { value: -2, contributions: [], status: null, }, - m: { + { value: -2, contributions: [], status: null, }, - n: { + { value: -2, contributions: [], status: null, }, - s: { + { value: -2, contributions: [], status: null, }, - }, + ], glory: [], first_player: null, hands: { @@ -2551,7 +2551,7 @@ function defeat_on_a_front(front_id) { log_br(); log('Defeat on ' + get_front_name(front_id) + '!'); log_br(); - if (front_id === 'm' || get_defeated_front_count() == 2) { + if (front_id === data_1.MADRID || get_defeated_front_count() == 2) { game_over('Fascist', 'All players lose the game!'); return; } @@ -2745,7 +2745,7 @@ function get_fronts_closest_to(target) { return []; } const targetValue = target === 'd' ? Math.min(...values) : Math.max(...values); - return Object.keys(game.fronts).filter((frontId) => game.fronts[frontId].value === targetValue); + return game.fronts.findIndex((front) => front.value === targetValue); } function log_br() { if (game.log.length > 0 && game.log[game.log.length - 1] !== '') @@ -145,7 +145,7 @@ function gen_action_card(card_id: CardId) { gen_action('card', card_id); } -function gen_action_front(front_id: string) { +function gen_action_front(front_id: FrontId) { gen_action('front', front_id); } @@ -593,28 +593,28 @@ export function setup(seed: number, _scenario: string, options: Record<string,bo }, engine: [], faction_turn: null, - fronts: { - a: { + fronts: [ + { value: -2, contributions: [], status: null, }, - m: { + { value: -2, contributions: [], status: null, }, - n: { + { value: -2, contributions: [], status: null, }, - s: { + { value: -2, contributions: [], status: null, }, - }, + ], glory: [], first_player: null, hands: { @@ -2932,7 +2932,10 @@ function resolve_final_bid() { resolve_active_and_proceed(); } -function get_fronts_to_add_to(target: string, not: FrontId[] = []): FrontId[] { +function get_fronts_to_add_to( + target: string | number, + not: FrontId[] = [] +): FrontId[] { if (target === CLOSEST_TO_DEFEAT || target === CLOSEST_TO_VICTORY) { return get_fronts_closest_to(target); } else if (target === ANY) { @@ -3181,7 +3184,7 @@ function defeat_on_a_front(front_id: FrontId) { log_br() // Check game end - if (front_id === 'm' || get_defeated_front_count() == 2) { + if (front_id === MADRID || get_defeated_front_count() == 2) { game_over('Fascist', 'All players lose the game!'); return; } @@ -3439,9 +3442,9 @@ function get_fronts_closest_to(target: 'd' | 'v'): FrontId[] { const targetValue = target === 'd' ? Math.min(...values) : Math.max(...values); - return Object.keys(game.fronts).filter( - (frontId) => game.fronts[frontId].value === targetValue - ) as FrontId[]; + return game.fronts.findIndex( + (front) => front.value === targetValue + ) as unknown as FrontId[]; } // #endregion @@ -8,7 +8,8 @@ export type Brand<T, TBrand extends string> = T & { export type Player = Brand<string, 'Player'>; export type CardId = Brand<number, 'CardId'>; export type FactionId = 'a' | 'c' | 'm'; -export type FrontId = 'a' | 'm' | 'n' | 's'; +export type FrontId = 0 | 1 | 2 | 3; +// export type FrontId = 'a' | 'm' | 'n' | 's'; export interface Front { value: number; @@ -46,12 +47,7 @@ export interface Game { * First player of current game turn */ first_player: FactionId | null; - fronts: { - a: Front; - m: Front; - n: Front; - s: Front; - }; + fronts: Front[]; glory: FactionId[]; hands: Record<FactionId, CardId[]>; hero_points: Record<FactionId | 'pool', number>; @@ -202,7 +198,7 @@ export interface Effect { export interface StaticData { cards: Card[]; fronts: Array<{ - id: string; + id: number; name: string; left: number; top: number; |