summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrans Bongers <fransbongers@macbookpro.home>2025-03-19 21:55:43 +0100
committerFrans Bongers <fransbongers@macbookpro.home>2025-03-19 21:56:01 +0100
commit0fae284f79b1c934e58214cf5f88cad4cab6b03b (patch)
tree779e447a18042132e40036f40fc5d0af6622954a
parent19d48663a25cf6f9a93e8710f6896a2b43971fcd (diff)
downloadland-and-freedom-0fae284f79b1c934e58214cf5f88cad4cab6b03b.tar.gz
refactor: FrontId to number
-rw-r--r--data.js20
-rw-r--r--data.ts20
-rw-r--r--rules.js16
-rw-r--r--rules.ts27
-rw-r--r--types.d.ts12
5 files changed, 47 insertions, 48 deletions
diff --git a/data.js b/data.js
index b90990f..58bb00c 100644
--- a/data.js
+++ b/data.js
@@ -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,
diff --git a/data.ts b/data.ts
index f36f9c3..424fcc7 100644
--- a/data.ts
+++ b/data.ts
@@ -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,
diff --git a/rules.js b/rules.js
index 9dedb5b..40cde75 100644
--- a/rules.js
+++ b/rules.js
@@ -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] !== '')
diff --git a/rules.ts b/rules.ts
index 8299d1b..1e2ff94 100644
--- a/rules.ts
+++ b/rules.ts
@@ -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
diff --git a/types.d.ts b/types.d.ts
index 2387420..16cae59 100644
--- a/types.d.ts
+++ b/types.d.ts
@@ -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;