diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-05-17 13:33:00 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-08-21 00:28:20 +0200 |
commit | 62e2b0858c6b8f6e975161053d1653c59e08905d (patch) | |
tree | 4078215693760046f5744d7c1f438b2155757e66 /rules.js | |
parent | 5424a2756d266a983ded718c4f36412cbbfac07a (diff) | |
download | washingtons-war-62e2b0858c6b8f6e975161053d1653c59e08905d.tar.gz |
pc+cu in one array
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 129 |
1 files changed, 56 insertions, 73 deletions
@@ -37,17 +37,6 @@ const PC_NONE = 0 const PC_BRITISH = 1 const PC_AMERICAN = 2 -// max 5 french CU in game total -// no stacking limit on other units, but max 6 new american CU per turn * 9 turns (=54) + starting forces (2+2+5) -// british cu = 3+8+1+8+1+5+1+1+1 (=29) reinforcements + starting forces (1+2+5) -// 6 bits for british, 6 bits for american, 3 bits for french = 15 bits total -// x2 for moved = 30 bits -// moved_cu=5+5+3 bits -// cu=5+5+3 bits -// pc=2 bits - -// OR: pack space=8, owner=2, count=6, moved=6 - const CU_BRITISH_SHIFT = 2 const CU_AMERICAN_SHIFT = 8 const CU_FRENCH_SHIFT = 14 @@ -133,8 +122,8 @@ function setup_game(seed) { played_british_reinforcements: 0, played_american_reinforcements: [], - pc: new Array(space_count).fill(PC_NONE), - generals: new Array(general_count).fill(NOWHERE), + loc: new Array(general_count).fill(NOWHERE), + spc: new Array(space_count + 2).fill(PC_NONE), moved: [], mcu: [], @@ -157,50 +146,46 @@ function setup_game(seed) { actions: [], } - function spawn_unit(owner, location, pc, cu, general=NOBODY) { - if (pc) - set_space_pc(location, pc) - if (general !== NOBODY) - set_general_location(general, location) - if (cu > 0) - spawn_cu(owner, location, cu) - } + set_space_pc(QUEBEC, PC_BRITISH) + set_space_pc(MONTREAL, PC_BRITISH) + set_space_pc(FORT_DETROIT, PC_BRITISH) + set_space_pc(BOSTON, PC_BRITISH) + set_space_pc(NORFOLK, PC_BRITISH) + set_space_pc(GILBERT_TOWN, PC_BRITISH) + set_space_pc(WILMINGTON_NC, PC_BRITISH) + set_space_pc(NINETY_SIX, PC_BRITISH) - function british(place, pc, cu, ld) { - spawn_unit(BRITISH, place, pc, cu, ld) - } - function american(place, pc, cu, ld) { - spawn_unit(AMERICAN, place, pc, cu, ld) - } - function french(place, pc, cu, ld) { - spawn_unit(FRENCH, place, pc, cu, ld) - } + set_general_location(CARLETON, QUEBEC) + set_general_location(HOWE, BOSTON) + + place_british_cu(QUEBEC, 2) + place_british_cu(BOSTON, 5) + place_british_cu(FORT_DETROIT, 1) + + set_space_pc(LEXINGTON_CONCORD, PC_AMERICAN) + set_space_pc(CHARLESTON, PC_AMERICAN) + set_space_pc(PHILADELPHIA, PC_AMERICAN) + + set_general_location(WASHINGTON, LEXINGTON_CONCORD) + set_general_location(GREENE, NEWPORT) - british(QUEBEC, PC_BRITISH, 2, CARLETON) - british(MONTREAL, PC_BRITISH) - british(FORT_DETROIT, PC_BRITISH, 1) - british(BOSTON, PC_BRITISH, 5, HOWE) - british(NORFOLK, PC_BRITISH) - british(GILBERT_TOWN, PC_BRITISH) - british(WILMINGTON_NC, PC_BRITISH) - british(NINETY_SIX, PC_BRITISH) + place_american_cu(LEXINGTON_CONCORD, 5) + place_american_cu(NEWPORT, 2) + place_american_cu(CHARLESTON, 2) - american(LEXINGTON_CONCORD, PC_AMERICAN, 5, WASHINGTON) - american(NEWPORT, PC_NONE, 2, GREENE) - american(CHARLESTON, PC_AMERICAN, 2) - american(PHILADELPHIA, PC_AMERICAN) + set_general_location(BURGOYNE, BRITISH_REINFORCEMENTS) + set_general_location(CLINTON, BRITISH_REINFORCEMENTS) + set_general_location(CORNWALLIS, BRITISH_REINFORCEMENTS) - british(BRITISH_REINFORCEMENTS, PC_NONE, 0, BURGOYNE) - british(BRITISH_REINFORCEMENTS, PC_NONE, 0, CLINTON) - british(BRITISH_REINFORCEMENTS, PC_NONE, 0, CORNWALLIS) + set_general_location(ARNOLD, AMERICAN_REINFORCEMENTS) + set_general_location(LINCOLN, AMERICAN_REINFORCEMENTS) + set_general_location(GATES, AMERICAN_REINFORCEMENTS) + set_general_location(LEE, AMERICAN_REINFORCEMENTS) + set_general_location(LAFAYETTE, AMERICAN_REINFORCEMENTS) - american(AMERICAN_REINFORCEMENTS, PC_NONE, 0, ARNOLD) - american(AMERICAN_REINFORCEMENTS, PC_NONE, 0, LINCOLN) - american(AMERICAN_REINFORCEMENTS, PC_NONE, 0, GATES) - american(AMERICAN_REINFORCEMENTS, PC_NONE, 0, LEE) - american(AMERICAN_REINFORCEMENTS, PC_NONE, 0, LAFAYETTE) + set_general_location(ROCHAMBEAU, FRENCH_REINFORCEMENTS) - french(FRENCH_REINFORCEMENTS, PC_NONE, 5, ROCHAMBEAU) + place_french_cu(FRENCH_REINFORCEMENTS, 5) goto_committees_of_correspondence() } @@ -378,11 +363,12 @@ function is_american_winter_offensive() { /* PC */ function set_space_pc(space, pc) { - game.pc[space] = pc + game.spc[space] &= ~3 + game.spc[space] |= pc } function get_space_pc(space) { - return game.pc[space] + return game.spc[space] & 3 } function has_no_pc(space) { @@ -481,30 +467,30 @@ function reset_moved_cu() { } function count_british_cu(s) { - return (game.pc[s] & CU_BRITISH_MASK) >>> CU_BRITISH_SHIFT + return (game.spc[s] & CU_BRITISH_MASK) >>> CU_BRITISH_SHIFT } function count_american_cu(s) { - return (game.pc[s] & CU_AMERICAN_MASK) >>> CU_AMERICAN_SHIFT + return (game.spc[s] & CU_AMERICAN_MASK) >>> CU_AMERICAN_SHIFT } function count_french_cu(s) { - return (game.pc[s] & CU_FRENCH_MASK) >>> CU_FRENCH_SHIFT + return (game.spc[s] & CU_FRENCH_MASK) >>> CU_FRENCH_SHIFT } function set_british_cu(s, n) { - game.pc[s] &= ~CU_BRITISH_MASK - game.pc[s] |= n << CU_BRITISH_SHIFT + game.spc[s] &= ~CU_BRITISH_MASK + game.spc[s] |= n << CU_BRITISH_SHIFT } function set_american_cu(s, n) { - game.pc[s] &= ~CU_AMERICAN_MASK - game.pc[s] |= n << CU_AMERICAN_SHIFT + game.spc[s] &= ~CU_AMERICAN_MASK + game.spc[s] |= n << CU_AMERICAN_SHIFT } function set_french_cu(s, n) { - game.pc[s] &= ~CU_FRENCH_MASK - game.pc[s] |= n << CU_FRENCH_SHIFT + game.spc[s] &= ~CU_FRENCH_MASK + game.spc[s] |= n << CU_FRENCH_SHIFT } function has_british_cu(space) { @@ -576,10 +562,6 @@ function count_enemy_cu(where) { return count_british_cu(where) } -function spawn_cu(owner, where, count) { - game.cu.push({ owner: owner, location: where, count: count, moved: 0 }) -} - function remove_british_cu(where, count) { set_british_cu(where, count_british_cu(where) - count) } @@ -622,11 +604,11 @@ function move_french_cu(from, to, count) { /* GENERALS */ function location_of_general(g) { - return game.generals[g] + return game.loc[g] } function set_general_location(g, s) { - game.generals[g] = s + game.loc[g] = s } function is_general_at_location(g, s) { @@ -3579,18 +3561,19 @@ exports.view = function (state, current) { game = state view = { - active: state.active, year: state.year, war_ends: state.war_ends, played_british_reinforcements: state.played_british_reinforcements, played_american_reinforcements: state.played_american_reinforcements, - congress: state.congress, - european_war: state.european_war, french_alliance: state.french_alliance, + european_war: state.european_war, + congress: state.congress, french_navy: state.french_navy, regulars: state.regulars, - generals: state.generals, - pc: state.pc, + + loc: state.loc, + spc: state.spc, + control: state.control, a_cards: state.a_hand.length, b_cards: state.b_hand.length, |