diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-04-14 11:42:12 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-05-03 18:48:16 +0200 |
commit | 21d853ac27ed3751087750051dd97e68a0502c3b (patch) | |
tree | b23d7e00163fcfb342c37a4c6f7ef885d79756ca | |
parent | 662c74265ea9c3bdeb04fea06abcc659c01085e8 (diff) | |
download | andean-abyss-21d853ac27ed3751087750051dd97e68a0502c3b.tar.gz |
Simplify 5.1.3 affected events with new instruction pair.
if_space <condition1>
or_space <condition2>
Gets compiled to:
if can_vm_place(1, s => <condition1>)
space 1 <condition1>
else
space 1 <condition2>
endif
Interleaving if/else and space/endspace is safe.
-rw-r--r-- | events.txt | 88 | ||||
-rw-r--r-- | rules.js | 114 | ||||
-rw-r--r-- | tools/gencode.js | 11 |
3 files changed, 66 insertions, 147 deletions
@@ -156,15 +156,8 @@ EVENT 14 # 5.1.3 - place base if possible! # 5.1.3 - TODO Ecuador max 2 prompt "Place 1 Base and 3 Troops into any Department." - space 1 is_dept(s) && can_place_piece(s, GOVT, BASE) - auto_place GOVT BASE - auto_place GOVT TROOPS - auto_place GOVT TROOPS - auto_place GOVT TROOPS - return - endspace - prompt "Place 1 Base and 3 Troops into any Department." - space 1 is_dept(s) && can_stack_any(s, GOVT) + if_space is_dept(s) && can_place_piece(s, GOVT, BASE) + or_space is_dept(s) && can_stack_any(s, GOVT) auto_place GOVT BASE auto_place GOVT TROOPS auto_place GOVT TROOPS @@ -174,19 +167,8 @@ EVENT 14 SHADED 14 # 5.1.3 - remove both base and cube if possible prompt "Remove 1 Government Base and 1 cube from a Department." - space 1 is_dept(s) && ( has_govt_base(s) && has_cube(s) ) - prompt "Remove 1 Government Base." - piece 1 is_piece_in_event_space(p) && is_govt_base(p) - remove - endpiece - prompt "Remove 1 cube." - piece 1 is_piece_in_event_space(p) && is_cube(p) - remove - endpiece - return - endspace - prompt "Remove 1 Government Base and 1 cube from a Department." - space 1 is_dept(s) && ( has_govt_base(s) || has_cube(s) ) + if_space is_dept(s) && ( has_govt_base(s) && has_cube(s) ) + or_space is_dept(s) && ( has_govt_base(s) || has_cube(s) ) prompt "Remove 1 Government Base." piece 1 is_piece_in_event_space(p) && is_govt_base(p) remove @@ -320,21 +302,8 @@ EVENT 24 SHADED 24 # 5.1.3 - 2 troops priority prompt "Remove 2 Troops from a space with FARC pieces." - space 1 has_farc_piece(s) && count_pieces(s, GOVT, TROOPS) >= 2 - prompt "Remove 2 Troops." - piece 2 is_piece_in_event_space(p) && is_troops(p) - remove - endpiece - save_space - prompt "Shift a City with Support to Neutral." - space 1 is_city(s) && is_support(s) - set_neutral - endspace - restore_space - return - endspace - prompt "Remove 2 Troops from a space with FARC pieces." - space 1 has_farc_piece(s) && has_troops(s) + if_space has_farc_piece(s) && count_pieces(s, GOVT, TROOPS) >= 2 + or_space has_farc_piece(s) && has_troops(s) prompt "Remove 2 Troops." piece 2 is_piece_in_event_space(p) && is_troops(p) remove @@ -435,17 +404,13 @@ SHADED 29 EVENT 30 # 5.1.3 - remove both farc zone and farc base if possible prompt "Remove 1 FARC Zone and 1 FARC Base there." - space 1 is_farc_zone(s) && has_piece(s, FARC, BASE) + if_space is_farc_zone(s) && has_piece(s, FARC, BASE) + or_space is_farc_zone(s) remove_farc_zone prompt "Remove 1 FARC Base." piece 1 is_piece_in_event_space(p) && is_farc_base(p) remove endpiece - return - endspace - prompt "Remove 1 FARC Zone and 1 FARC Base there." - space 1 is_farc_zone(s) - remove_farc_zone endspace @@ -510,14 +475,8 @@ SHADED 34 # 5.1.3 - place base if possible # 5.1.3 - TODO Ecuador max 2 prompt "Place 2 Guerrillas and 1 Base into a 0 Population Department." - space 1 is_zero_pop_dept(s) && can_place_piece(s, game.current, BASE) - auto_place (game.current) BASE - auto_place (game.current) GUERRILLA - auto_place (game.current) GUERRILLA - return - endspace - prompt "Place 2 Guerrillas and 1 Base into a 0 Population Department." - space 1 is_zero_pop_dept(s) && can_stack_any(s, game.current) + if_space is_zero_pop_dept(s) && can_place_piece(s, game.current, BASE) + or_space is_zero_pop_dept(s) && can_stack_any(s, game.current) auto_place (game.current) BASE auto_place (game.current) GUERRILLA auto_place (game.current) GUERRILLA @@ -663,19 +622,14 @@ EVENT 43 # 5.1.3 - farc bases if possible # 5.1.3 - TODO Ecuador max 2 prompt "Place 2 Terror and remove all FARC Bases from a Department with Troops." - space 1 is_dept(s) && has_troops(s) && has_piece(s, FARC, BASE) + if_space is_dept(s) && has_troops(s) && has_piece(s, FARC, BASE) + or_space is_dept(s) && has_troops(s) terror terror prompt "Remove all FARC Bases." piece all is_piece_in_event_space(p) && is_farc_base(p) remove endpiece - return - endspace - prompt "Place 2 Terror and remove all FARC Bases from a Department with Troops." - space 1 is_dept(s) && has_troops(s) - terror - terror endspace SHADED 43 @@ -791,13 +745,8 @@ SHADED 49 # 5.1.3 - place base if possible # 5.1.3 - TODO Ecuador max 2 prompt "Place an AUC Guerrilla and Base in any Department." - space 1 is_dept(s) && can_place_piece(s, AUC, BASE) - auto_place AUC BASE - auto_place AUC GUERRILLA - return - endspace - prompt "Place an AUC Guerrilla and Base in any Department." - space 1 is_dept(s) && can_stack_any(s, AUC) + if_space is_dept(s) && can_place_piece(s, AUC, BASE) + or_space is_dept(s) && can_stack_any(s, AUC) auto_place AUC BASE auto_place AUC GUERRILLA endspace @@ -1109,13 +1058,8 @@ SHADED 64 EVENT 65 # 5.1.3 - do both shipment and base if possible prompt "Place or remove 1 Shipment and Insurgent Base in any Mountain Department." - space 1 is_mountain(s) && ( can_place_or_remove_shipment(s) && can_place_or_remove_insurgent_base(s) ) - place_or_remove_shipment - place_or_remove_insurgent_base - return - endspace - prompt "Place or remove 1 Shipment and Insurgent Base in any Mountain Department." - space 1 is_mountain(s) && ( can_place_or_remove_shipment(s) || can_place_or_remove_insurgent_base(s) ) + if_space is_mountain(s) && ( can_place_or_remove_shipment(s) && can_place_or_remove_insurgent_base(s) ) + or_space is_mountain(s) && ( can_place_or_remove_shipment(s) || can_place_or_remove_insurgent_base(s) ) place_or_remove_shipment place_or_remove_insurgent_base endspace @@ -15,6 +15,8 @@ // TODO: auto-skip civic action // TODO: auto-skip agitation +// TODO: don't auto-end free Rally with elite backing + // TODO: auto-end Extort ? const AUTOMATIC = true @@ -6421,7 +6423,9 @@ function vm_restore_space() { } function vm_space() { - if (can_vm_space()) { + let n = CODE[game.vm.pc][3] + let f = CODE[game.vm.pc][4] + if (can_vm_space(n, f)) { game.state = "vm_space" } else { pop_vm_prompt() @@ -6435,9 +6439,8 @@ function vm_endspace() { vm_goto(vm_space, vm_endspace, -1, 0) } -function can_vm_space() { - let f = CODE[game.vm.pc][4] - if (game.vm.ss.length < CODE[game.vm.pc][3]) +function can_vm_space(n, f) { + if (game.vm.ss.length < n) for (let s = first_space; s <= last_space; ++s) if (!set_has(game.vm.ss, s) && f(s)) return true @@ -7002,19 +7005,10 @@ function goto_game_end(result) { game.active = "None" game.result = result log_br() - log(game.result = " won!") + log(game.result + " won!") return true } -states.game_end = { - get inactive() { - return game.result + " won!" - }, - prompt() { - view.prompt = game.result + " won!" - }, -} - // === UNCOMMON TEMPLATE === function log_br() { @@ -7121,7 +7115,9 @@ exports.view = function (state, role) { if (game.prop) view.propaganda = game.prop.step - if (!is_current_role(role)) { + if (game.result) { + view.prompt = game.result + " won!" + } else if (!is_current_role(role)) { let inactive = states[game.state].inactive if (!inactive) { if (game.vm) @@ -7546,15 +7542,11 @@ const CODE = [ // EVENT 14 [ vm_current, GOVT ], [ vm_prompt, "Place 1 Base and 3 Troops into any Department." ], + [ vm_if, ()=>can_vm_space(1,(s)=>is_dept(s) && can_place_piece(s, GOVT, BASE)) ], [ vm_space, true, 1, 1, (s)=>is_dept(s) && can_place_piece(s, GOVT, BASE) ], - [ vm_auto_place, false, 0, GOVT, BASE ], - [ vm_auto_place, false, 0, GOVT, TROOPS ], - [ vm_auto_place, false, 0, GOVT, TROOPS ], - [ vm_auto_place, false, 0, GOVT, TROOPS ], - [ vm_return ], - [ vm_endspace ], - [ vm_prompt, "Place 1 Base and 3 Troops into any Department." ], + [ vm_else ], [ vm_space, true, 1, 1, (s)=>is_dept(s) && can_stack_any(s, GOVT) ], + [ vm_endif ], [ vm_auto_place, false, 0, GOVT, BASE ], [ vm_auto_place, false, 0, GOVT, TROOPS ], [ vm_auto_place, false, 0, GOVT, TROOPS ], @@ -7563,19 +7555,11 @@ const CODE = [ [ vm_return ], // SHADED 14 [ vm_prompt, "Remove 1 Government Base and 1 cube from a Department." ], + [ vm_if, ()=>can_vm_space(1,(s)=>is_dept(s) && ( has_govt_base(s) && has_cube(s) )) ], [ vm_space, true, 1, 1, (s)=>is_dept(s) && ( has_govt_base(s) && has_cube(s) ) ], - [ vm_prompt, "Remove 1 Government Base." ], - [ vm_piece, false, 1, 1, (p,s)=>is_piece_in_event_space(p) && is_govt_base(p) ], - [ vm_remove ], - [ vm_endpiece ], - [ vm_prompt, "Remove 1 cube." ], - [ vm_piece, false, 1, 1, (p,s)=>is_piece_in_event_space(p) && is_cube(p) ], - [ vm_remove ], - [ vm_endpiece ], - [ vm_return ], - [ vm_endspace ], - [ vm_prompt, "Remove 1 Government Base and 1 cube from a Department." ], + [ vm_else ], [ vm_space, true, 1, 1, (s)=>is_dept(s) && ( has_govt_base(s) || has_cube(s) ) ], + [ vm_endif ], [ vm_prompt, "Remove 1 Government Base." ], [ vm_piece, false, 1, 1, (p,s)=>is_piece_in_event_space(p) && is_govt_base(p) ], [ vm_remove ], @@ -7708,21 +7692,11 @@ const CODE = [ [ vm_return ], // SHADED 24 [ vm_prompt, "Remove 2 Troops from a space with FARC pieces." ], + [ vm_if, ()=>can_vm_space(1,(s)=>has_farc_piece(s) && count_pieces(s, GOVT, TROOPS) >= 2) ], [ vm_space, true, 1, 1, (s)=>has_farc_piece(s) && count_pieces(s, GOVT, TROOPS) >= 2 ], - [ vm_prompt, "Remove 2 Troops." ], - [ vm_piece, false, 2, 2, (p,s)=>is_piece_in_event_space(p) && is_troops(p) ], - [ vm_remove ], - [ vm_endpiece ], - [ vm_save_space ], - [ vm_prompt, "Shift a City with Support to Neutral." ], - [ vm_space, true, 1, 1, (s)=>is_city(s) && is_support(s) ], - [ vm_set_neutral ], - [ vm_endspace ], - [ vm_restore_space ], - [ vm_return ], - [ vm_endspace ], - [ vm_prompt, "Remove 2 Troops from a space with FARC pieces." ], + [ vm_else ], [ vm_space, true, 1, 1, (s)=>has_farc_piece(s) && has_troops(s) ], + [ vm_endif ], [ vm_prompt, "Remove 2 Troops." ], [ vm_piece, false, 2, 2, (p,s)=>is_piece_in_event_space(p) && is_troops(p) ], [ vm_remove ], @@ -7817,17 +7791,16 @@ const CODE = [ [ vm_return ], // EVENT 30 [ vm_prompt, "Remove 1 FARC Zone and 1 FARC Base there." ], + [ vm_if, ()=>can_vm_space(1,(s)=>is_farc_zone(s) && has_piece(s, FARC, BASE)) ], [ vm_space, true, 1, 1, (s)=>is_farc_zone(s) && has_piece(s, FARC, BASE) ], + [ vm_else ], + [ vm_space, true, 1, 1, (s)=>is_farc_zone(s) ], + [ vm_endif ], [ vm_remove_farc_zone ], [ vm_prompt, "Remove 1 FARC Base." ], [ vm_piece, false, 1, 1, (p,s)=>is_piece_in_event_space(p) && is_farc_base(p) ], [ vm_remove ], [ vm_endpiece ], - [ vm_return ], - [ vm_endspace ], - [ vm_prompt, "Remove 1 FARC Zone and 1 FARC Base there." ], - [ vm_space, true, 1, 1, (s)=>is_farc_zone(s) ], - [ vm_remove_farc_zone ], [ vm_endspace ], [ vm_return ], // SHADED 30 @@ -7887,14 +7860,11 @@ const CODE = [ // SHADED 34 [ vm_current, FARC_AUC_CARTELS ], [ vm_prompt, "Place 2 Guerrillas and 1 Base into a 0 Population Department." ], + [ vm_if, ()=>can_vm_space(1,(s)=>is_zero_pop_dept(s) && can_place_piece(s, game.current, BASE)) ], [ vm_space, true, 1, 1, (s)=>is_zero_pop_dept(s) && can_place_piece(s, game.current, BASE) ], - [ vm_auto_place, false, 0, ()=>(game.current), BASE ], - [ vm_auto_place, false, 0, ()=>(game.current), GUERRILLA ], - [ vm_auto_place, false, 0, ()=>(game.current), GUERRILLA ], - [ vm_return ], - [ vm_endspace ], - [ vm_prompt, "Place 2 Guerrillas and 1 Base into a 0 Population Department." ], + [ vm_else ], [ vm_space, true, 1, 1, (s)=>is_zero_pop_dept(s) && can_stack_any(s, game.current) ], + [ vm_endif ], [ vm_auto_place, false, 0, ()=>(game.current), BASE ], [ vm_auto_place, false, 0, ()=>(game.current), GUERRILLA ], [ vm_auto_place, false, 0, ()=>(game.current), GUERRILLA ], @@ -8038,19 +8008,17 @@ const CODE = [ [ vm_return ], // EVENT 43 [ vm_prompt, "Place 2 Terror and remove all FARC Bases from a Department with Troops." ], + [ vm_if, ()=>can_vm_space(1,(s)=>is_dept(s) && has_troops(s) && has_piece(s, FARC, BASE)) ], [ vm_space, true, 1, 1, (s)=>is_dept(s) && has_troops(s) && has_piece(s, FARC, BASE) ], + [ vm_else ], + [ vm_space, true, 1, 1, (s)=>is_dept(s) && has_troops(s) ], + [ vm_endif ], [ vm_terror ], [ vm_terror ], [ vm_prompt, "Remove all FARC Bases." ], [ vm_piece, false, 999, 999, (p,s)=>is_piece_in_event_space(p) && is_farc_base(p) ], [ vm_remove ], [ vm_endpiece ], - [ vm_return ], - [ vm_endspace ], - [ vm_prompt, "Place 2 Terror and remove all FARC Bases from a Department with Troops." ], - [ vm_space, true, 1, 1, (s)=>is_dept(s) && has_troops(s) ], - [ vm_terror ], - [ vm_terror ], [ vm_endspace ], [ vm_return ], // SHADED 43 @@ -8162,13 +8130,11 @@ const CODE = [ [ vm_return ], // SHADED 49 [ vm_prompt, "Place an AUC Guerrilla and Base in any Department." ], + [ vm_if, ()=>can_vm_space(1,(s)=>is_dept(s) && can_place_piece(s, AUC, BASE)) ], [ vm_space, true, 1, 1, (s)=>is_dept(s) && can_place_piece(s, AUC, BASE) ], - [ vm_auto_place, false, 0, AUC, BASE ], - [ vm_auto_place, false, 0, AUC, GUERRILLA ], - [ vm_return ], - [ vm_endspace ], - [ vm_prompt, "Place an AUC Guerrilla and Base in any Department." ], + [ vm_else ], [ vm_space, true, 1, 1, (s)=>is_dept(s) && can_stack_any(s, AUC) ], + [ vm_endif ], [ vm_auto_place, false, 0, AUC, BASE ], [ vm_auto_place, false, 0, AUC, GUERRILLA ], [ vm_endspace ], @@ -8474,13 +8440,11 @@ const CODE = [ [ vm_return ], // EVENT 65 [ vm_prompt, "Place or remove 1 Shipment and Insurgent Base in any Mountain Department." ], + [ vm_if, ()=>can_vm_space(1,(s)=>is_mountain(s) && ( can_place_or_remove_shipment(s) && can_place_or_remove_insurgent_base(s) )) ], [ vm_space, true, 1, 1, (s)=>is_mountain(s) && ( can_place_or_remove_shipment(s) && can_place_or_remove_insurgent_base(s) ) ], - [ vm_place_or_remove_shipment ], - [ vm_place_or_remove_insurgent_base ], - [ vm_return ], - [ vm_endspace ], - [ vm_prompt, "Place or remove 1 Shipment and Insurgent Base in any Mountain Department." ], + [ vm_else ], [ vm_space, true, 1, 1, (s)=>is_mountain(s) && ( can_place_or_remove_shipment(s) || can_place_or_remove_insurgent_base(s) ) ], + [ vm_endif ], [ vm_place_or_remove_shipment ], [ vm_place_or_remove_insurgent_base ], [ vm_endspace ], @@ -8618,5 +8582,5 @@ const CODE = [ [ vm_endif ], [ vm_return ], ] -const UCODE = [0,1,7,13,19,29,47,62,68,75,81,87,93,99,105,146,154,161,167,174,186,202,214,222,242,274,289,300,308,325,346,363,377,384,404,421,437,447,463,479,493,518,532,542,565,577,593,610,635,649,666,698,712,730,758,780,795,806,823,838,861,880,894,904,919,938,950,960,965,987,1014,1030,1050] -const SCODE = [0,4,10,16,24,41,52,65,73,78,84,90,96,102,122,149,159,164,170,0,195,208,219,234,248,282,295,305,316,335,360,372,382,391,406,431,0,453,471,484,501,527,538,558,571,582,0,619,644,654,676,707,717,0,0,790,797,814,829,848,870,889,899,0,929,0,955,962,982,0,1019,1037,1059] +const UCODE = [0,1,7,13,19,29,47,62,68,75,81,87,93,99,105,134,142,149,155,162,174,190,202,210,230,252,267,278,286,303,324,340,354,361,381,395,411,421,437,453,467,492,506,516,537,549,565,582,607,621,636,668,682,700,728,750,765,776,793,808,831,850,864,874,889,908,918,928,933,955,982,998,1018] +const SCODE = [0,4,10,16,24,41,52,65,73,78,84,90,96,102,118,137,147,152,158,0,183,196,207,222,236,260,273,283,294,313,337,349,359,368,383,405,0,427,445,458,475,501,512,530,543,554,0,591,616,626,646,677,687,0,0,760,767,784,799,818,840,859,869,0,899,0,923,930,950,0,987,1005,1027] diff --git a/tools/gencode.js b/tools/gencode.js index 30f12c9..df8f0f1 100644 --- a/tools/gencode.js +++ b/tools/gencode.js @@ -43,6 +43,17 @@ for (let line of fs.readFileSync("events.txt", "utf-8").split("\n")) { console.log("// SHADED " + line[1]) break + case "if_space": + emit([ "if", "()=>can_vm_space(1,(s)=>" + line.slice(1).join(" ") + ")" ]) + emit([ "space", true, 1, 1, "(s)=>" + line.slice(1).join(" ") ]) + emit([ "else" ]) + break + + case "or_space": + emit([ "space", true, 1, 1, "(s)=>" + line.slice(1).join(" ") ]) + emit([ "endif" ]) + break + case "space_no_undo": emit([ "space", false, line[1], line[1], "(s)=>" + line.slice(2).join(" ") ]) break |