summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrans Bongers <fransbongers@macbookpro.home>2025-03-19 22:09:20 +0100
committerFrans Bongers <fransbongers@macbookpro.home>2025-03-19 22:09:20 +0100
commit1738326b21f02a1a4cd246b85026bc3f846511df (patch)
treebf3803f5c1c7cc815a5f8614772d32c445c051af
parent0fae284f79b1c934e58214cf5f88cad4cab6b03b (diff)
downloadland-and-freedom-1738326b21f02a1a4cd246b85026bc3f846511df.tar.gz
refactor: FactionId to number
-rw-r--r--data.js12
-rw-r--r--data.ts14
-rw-r--r--rules.js112
-rw-r--r--rules.ts119
-rw-r--r--types.d.ts28
5 files changed, 145 insertions, 140 deletions
diff --git a/data.js b/data.js
index 58bb00c..7072ad8 100644
--- a/data.js
+++ b/data.js
@@ -36,9 +36,9 @@ const NORTHERN = 2;
exports.NORTHERN = NORTHERN;
const SOUTHERN = 3;
exports.SOUTHERN = SOUTHERN;
-const CLOSEST_TO_DEFEAT = 'd';
+const CLOSEST_TO_DEFEAT = 4;
exports.CLOSEST_TO_DEFEAT = CLOSEST_TO_DEFEAT;
-const CLOSEST_TO_VICTORY = 'v';
+const CLOSEST_TO_VICTORY = 5;
exports.CLOSEST_TO_VICTORY = CLOSEST_TO_VICTORY;
const FRONTS = [ARAGON, MADRID, NORTHERN, SOUTHERN];
exports.FRONTS = FRONTS;
@@ -54,13 +54,13 @@ const OTHER_PLAYERS = 'other';
exports.OTHER_PLAYERS = OTHER_PLAYERS;
const TRASH = 'trash';
exports.TRASH = TRASH;
-const ANARCHISTS_ID = 'a';
+const ANARCHISTS_ID = 0;
exports.ANARCHISTS_ID = ANARCHISTS_ID;
-const COMMUNISTS_ID = 'c';
+const COMMUNISTS_ID = 1;
exports.COMMUNISTS_ID = COMMUNISTS_ID;
-const FASCIST_ID = 'f';
+const FASCIST_ID = 3;
exports.FASCIST_ID = FASCIST_ID;
-const MODERATES_ID = 'm';
+const MODERATES_ID = 2;
exports.MODERATES_ID = MODERATES_ID;
const ANARCHIST = 'Anarchist';
exports.ANARCHIST = ANARCHIST;
diff --git a/data.ts b/data.ts
index 424fcc7..98ee2be 100644
--- a/data.ts
+++ b/data.ts
@@ -1,4 +1,4 @@
-import { Card, Effect, FactionId, FrontId, Player, StaticData } from './types';
+import { Card, Effect, FactionId, FascistId, FrontId, Player, StaticData } from './types';
const LIBERTY = 0;
const COLLECTIVIZATION = 1;
@@ -21,8 +21,8 @@ const ARAGON = 0;
const MADRID = 1;
const NORTHERN = 2;
const SOUTHERN = 3;
-const CLOSEST_TO_DEFEAT = 'd';
-const CLOSEST_TO_VICTORY = 'v';
+const CLOSEST_TO_DEFEAT = 4;
+const CLOSEST_TO_VICTORY = 5;
const FRONTS: FrontId[] = [ARAGON, MADRID, NORTHERN, SOUTHERN];
const TOWARDS_CENTER = 10;
@@ -33,10 +33,10 @@ const SELF = 'self';
const OTHER_PLAYERS = 'other';
const TRASH = 'trash';
-const ANARCHISTS_ID: FactionId = 'a';
-const COMMUNISTS_ID: FactionId = 'c';
-const FASCIST_ID = 'f';
-const MODERATES_ID: FactionId = 'm';
+const ANARCHISTS_ID: FactionId = 0;
+const COMMUNISTS_ID: FactionId = 1;
+const FASCIST_ID: FascistId = 3;
+const MODERATES_ID: FactionId = 2;
const ANARCHIST = 'Anarchist' as Player;
const COMMUNIST = 'Communist' as Player;
diff --git a/rules.js b/rules.js
index 40cde75..9cbda76 100644
--- a/rules.js
+++ b/rules.js
@@ -10,24 +10,24 @@ const states = {};
let game = {};
var view = {};
const role_ids = [data_1.ANARCHISTS_ID, data_1.COMMUNISTS_ID, data_1.MODERATES_ID];
-const faction_player_map = {
- a: data_1.ANARCHIST,
- c: data_1.COMMUNIST,
- m: data_1.MODERATE,
-};
+const faction_player_map = [
+ data_1.ANARCHIST,
+ data_1.COMMUNIST,
+ data_1.MODERATE,
+];
const player_faction_map = {
[data_1.ANARCHIST]: data_1.ANARCHISTS_ID,
[data_1.COMMUNIST]: data_1.COMMUNISTS_ID,
[data_1.MODERATE]: data_1.MODERATES_ID,
};
-const front_names = {
- a: 'Aragon Front',
- m: 'Madrid Front',
- n: 'Northern Front',
- s: 'Southern Front',
- d: 'the Front closest to Defeat',
- v: 'the Front closest to Victory',
-};
+const front_names = [
+ 'Aragon Front',
+ 'Madrid Front',
+ 'Northern Front',
+ 'Southern Front',
+ 'the Front closest to Defeat',
+ 'the Front closest to Victory',
+];
const bonus_names = ['Morale Bonus', 'Teamwork Bonus'];
const { cards, medallions, tracks, } = data_1.default;
const bonuses = [data_1.MORALE_BONUS, data_1.TEAMWORK_BONUS];
@@ -402,12 +402,12 @@ function setup(seed, _scenario, options) {
bag_of_glory: [data_1.ANARCHISTS_ID, data_1.COMMUNISTS_ID, data_1.MODERATES_ID],
bonuses: [data_1.ON, data_1.ON],
current_events: [],
- discard: {
- a: [],
- c: [],
- m: [],
- f: [],
- },
+ discard: [
+ [],
+ [],
+ [],
+ [],
+ ],
engine: [],
faction_turn: null,
fronts: [
@@ -434,42 +434,38 @@ function setup(seed, _scenario, options) {
],
glory: [],
first_player: null,
- hands: {
- a: [],
- c: [],
- m: [],
- },
+ hands: [
+ [],
+ [],
+ [],
+ ],
hero_points: {
- a: 2,
- c: 2,
- m: 0,
- pool: 14,
+ factions: [2, 2, 0],
+ pool: 14
},
initiative: data_1.MODERATES_ID,
medallions: {
- a: [],
- c: [],
- m: [],
+ factions: [[], [], []],
pool: [],
},
played_card: null,
player_order: [data_1.MODERATE],
- selected_cards: {
- a: [],
- c: [],
- m: [],
- },
- tableaus: {
- a: [],
- c: [],
- m: [],
- },
+ selected_cards: [
+ [],
+ [],
+ [],
+ ],
+ tableaus: [
+ [],
+ [],
+ [],
+ ],
tracks: [5, 5, 6, 3, 3],
- trash: {
- a: [],
- c: [],
- m: [],
- },
+ trash: [
+ [],
+ [],
+ [],
+ ],
triggered_track_effects: [],
log: [],
undo: [],
@@ -1178,11 +1174,11 @@ states.draw_glory = {
const index = random(game.bag_of_glory.length);
const faction = game.bag_of_glory[index];
game.glory.push(faction);
- game.glory_current_year = game.glory_current_year = {
- a: false,
- c: false,
- m: false,
- };
+ game.glory_current_year = game.glory_current_year = [
+ false,
+ false,
+ false,
+ ];
game.glory_current_year[faction] = true;
array_remove(game.bag_of_glory, index);
logi(`Pulled T${faction} from the Bag`);
@@ -1495,7 +1491,7 @@ states.peek_fascist_cards = {
game.top_of_events_deck = c;
for (const ec of game.fascist_cards) {
if (ec !== c) {
- game.discard.f.push(ec);
+ game.discard[data_1.FASCIST_ID].push(ec);
}
}
delete game.fascist_cards;
@@ -2204,11 +2200,11 @@ function end_of_year() {
}
}
const glory_to_draw = [0, 1, 2, 5];
- game.glory_current_year = {
- a: false,
- c: false,
- m: false,
- };
+ game.glory_current_year = [
+ false,
+ false,
+ false,
+ ];
const player_order = get_player_order();
const engine = [];
for (let i = 0; i < glory_to_draw[game.year]; ++i) {
@@ -2744,7 +2740,7 @@ function get_fronts_closest_to(target) {
if (values.length === 0) {
return [];
}
- const targetValue = target === 'd' ? Math.min(...values) : Math.max(...values);
+ const targetValue = target === data_1.CLOSEST_TO_DEFEAT ? Math.min(...values) : Math.max(...values);
return game.fronts.findIndex((front) => front.value === targetValue);
}
function log_br() {
diff --git a/rules.ts b/rules.ts
index 1e2ff94..2b858c7 100644
--- a/rules.ts
+++ b/rules.ts
@@ -20,6 +20,9 @@ import {
SeqNode,
States,
View,
+ FascistId,
+ ClosestToDefeat,
+ ClosestToVictory,
} from './types';
import data, {
@@ -76,11 +79,11 @@ var view = {} as View; // = null
const role_ids: FactionId[] = [ANARCHISTS_ID, COMMUNISTS_ID, MODERATES_ID];
-const faction_player_map: Record<FactionId, Player> = {
- a: ANARCHIST,
- c: COMMUNIST,
- m: MODERATE,
-};
+const faction_player_map: Record<FactionId, Player> = [
+ ANARCHIST,
+ COMMUNIST,
+ MODERATE,
+];
const player_faction_map: Record<Player, FactionId> = {
[ANARCHIST]: ANARCHISTS_ID,
@@ -88,14 +91,14 @@ const player_faction_map: Record<Player, FactionId> = {
[MODERATE]: MODERATES_ID,
};
-const front_names: Record<string, string> = {
- a: 'Aragon Front',
- m: 'Madrid Front',
- n: 'Northern Front',
- s: 'Southern Front',
- d: 'the Front closest to Defeat',
- v: 'the Front closest to Victory',
-};
+const front_names = [
+ 'Aragon Front',
+ 'Madrid Front',
+ 'Northern Front',
+ 'Southern Front',
+ 'the Front closest to Defeat',
+ 'the Front closest to Victory',
+];
const bonus_names: string[] = ['Morale Bonus', 'Teamwork Bonus'];
@@ -585,12 +588,12 @@ export function setup(seed: number, _scenario: string, options: Record<string,bo
bag_of_glory: [ANARCHISTS_ID, COMMUNISTS_ID, MODERATES_ID],
bonuses: [ON, ON],
current_events: [],
- discard: {
- a: [],
- c: [],
- m: [],
- f: [],
- },
+ discard: [
+ [],
+ [],
+ [],
+ [],
+ ],
engine: [],
faction_turn: null,
fronts: [
@@ -617,42 +620,38 @@ export function setup(seed: number, _scenario: string, options: Record<string,bo
],
glory: [],
first_player: null,
- hands: {
- a: [],
- c: [],
- m: [],
- },
+ hands: [
+ [],
+ [],
+ [],
+ ],
hero_points: {
- a: 2,
- c: 2,
- m: 0,
- pool: 14,
+ factions: [2, 2, 0],
+ pool: 14
},
initiative: MODERATES_ID,
medallions: {
- a: [],
- c: [],
- m: [],
+ factions: [[],[],[]],
pool: [],
},
played_card: null,
player_order: [MODERATE],
- selected_cards: {
- a: [],
- c: [],
- m: [],
- },
- tableaus: {
- a: [],
- c: [],
- m: [],
- },
+ selected_cards: [
+ [],
+ [],
+ [],
+ ],
+ tableaus: [
+ [],
+ [],
+ [],
+ ],
tracks: [5, 5, 6, 3, 3],
- trash: {
- a: [],
- c: [],
- m: [],
- },
+ trash: [
+ [],
+ [],
+ [],
+ ],
triggered_track_effects: [],
log: [],
undo: [],
@@ -1470,11 +1469,11 @@ states.draw_glory = {
game.glory.push(faction);
- game.glory_current_year = game.glory_current_year = {
- a: false,
- c: false,
- m: false,
- };
+ game.glory_current_year = game.glory_current_year = [
+ false,
+ false,
+ false,
+ ];
game.glory_current_year[faction] = true;
@@ -1824,7 +1823,7 @@ states.peek_fascist_cards = {
game.top_of_events_deck = c;
for (const ec of game.fascist_cards) {
if (ec !== c) {
- game.discard.f.push(ec);
+ game.discard[FASCIST_ID].push(ec);
}
}
delete game.fascist_cards;
@@ -2708,11 +2707,11 @@ function end_of_year() {
const glory_to_draw = [0, 1, 2, 5];
- game.glory_current_year = {
- a: false,
- c: false,
- m: false,
- };
+ game.glory_current_year = [
+ false,
+ false,
+ false,
+ ];
const player_order = get_player_order();
@@ -3423,7 +3422,7 @@ function lose_hero_points(faction: FactionId, value: number) {
// #region FRONTS
-function get_fronts_closest_to(target: 'd' | 'v'): FrontId[] {
+function get_fronts_closest_to(target: ClosestToDefeat | ClosestToVictory): FrontId[] {
const values = Object.values(game.fronts).reduce(
(accrued: number[], current: Front) => {
if (current.status === null) {
@@ -3441,7 +3440,7 @@ function get_fronts_closest_to(target: 'd' | 'v'): FrontId[] {
}
const targetValue =
- target === 'd' ? Math.min(...values) : Math.max(...values);
+ target === CLOSEST_TO_DEFEAT ? Math.min(...values) : Math.max(...values);
return game.fronts.findIndex(
(front) => front.value === targetValue
) as unknown as FrontId[];
@@ -3674,7 +3673,7 @@ function make_list(first: number, last: number): number[] {
return list;
}
-function list_deck(id: FactionId | 'f') {
+function list_deck(id: FactionId | FascistId) {
const deck = [];
const card_list: CardId[] =
id === FASCIST_ID ? fascist_decks[game.year] : faction_cards[id];
diff --git a/types.d.ts b/types.d.ts
index 16cae59..cb772a6 100644
--- a/types.d.ts
+++ b/types.d.ts
@@ -7,8 +7,12 @@ 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 FactionId = 'a' | 'c' | 'm';
+export type FactionId = 0 | 1 | 2;
+export type FascistId = 3;
export type FrontId = 0 | 1 | 2 | 3;
+export type ClosestToDefeat = 4;
+export type ClosestToVictory = 5;
// export type FrontId = 'a' | 'm' | 'n' | 's';
export interface Front {
@@ -35,7 +39,7 @@ export interface Game {
bag_of_glory: FactionId[];
bonuses: number[];
current_events: CardId[];
- discard: Record<FactionId | 'f', number[]>;
+ discard: number[][];
engine: EngineNode[];
/**
* Set to faction whos turn it is or null if not player turn
@@ -49,25 +53,31 @@ export interface Game {
first_player: FactionId | null;
fronts: Front[];
glory: FactionId[];
- hands: Record<FactionId, CardId[]>;
- hero_points: Record<FactionId | 'pool', number>;
+ hands: CardId[][];
+ hero_points: {
+ factions: number[];
+ pool: number;
+ };
initiative: FactionId;
- medallions: Record<FactionId, number[]> & { pool: Array<number | null> };
+ medallions: {
+ factions: number[][]
+ pool: Array<number | null>
+ };
played_card: CardId | null;
player_order: Player[];
- selected_cards: Record<FactionId, CardId[]>;
+ selected_cards: CardId[][];
fascist_cards?: CardId[]; // used for specific events
- tableaus: Record<FactionId, CardId[]>;
+ tableaus: CardId[][];
/**
* Used for event effect that allows Anarchist to put an event
* card on top of the deck
*/
top_of_events_deck: CardId | null;
tracks: number[];
- trash: Record<FactionId, CardId[]>;
+ trash: CardId[][];
triggered_track_effects: number[];
used_medallions: number[];
- glory_current_year?: Record<FactionId, boolean> | null;
+ glory_current_year?: boolean[] | null;
fascist: 0 | 1 | 2;
card_played: 0 | 1;
hidden_bag?: 0 | 1;