From 0e10c9aff6416482ecea10cd39194d49c63a6a5b Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 19 Apr 2023 00:39:24 +0200 Subject: Automate tedious events. --- events.txt | 114 ++++++++++++++++++++++++++++++++++++++----------------- play.html | 1 + rules.js | 67 +++++++++++++++++++++++++++++--- tools/gencode.js | 7 ++++ 4 files changed, 149 insertions(+), 40 deletions(-) diff --git a/events.txt b/events.txt index 3355e66..3cb693c 100644 --- a/events.txt +++ b/events.txt @@ -324,7 +324,7 @@ EVENT 25 SHADED 25 prompt "Place 3 FARC pieces into Antioquia or an adjacent Department." - # todo Ecuador max 2 + # TODO Ecuador max 2 space 1 (s === ANTIOQUIA || (is_dept(s) && is_adjacent(ANTIOQUIA, s))) && can_stack_any(s, FARC) place FARC BASE_GUERRILLA place FARC BASE_GUERRILLA @@ -463,7 +463,6 @@ SHADED 33 endspace endif - EVENT 34 # -1 = all insurgent factions resources -1 -5 @@ -600,10 +599,16 @@ EVENT 41 endspace SHADED 41 - prompt "AUC Resources +3 for each space with AUC and Cartels pieces." - space all has_auc_piece(s) && has_cartels_piece(s) - auto_resources AUC 3 - endspace + if AUTOMATIC + count_spaces has_auc_piece(s) && has_cartels_piece(s) + log `${game.vm.count} spaces with AUC and Cartels pieces.` + resources AUC (3*game.vm.count) + else + prompt "AUC Resources +3 for each space with AUC and Cartels pieces." + space all has_auc_piece(s) && has_cartels_piece(s) + auto_resources AUC 3 + endspace + endif EVENT 42 prompt "Shift 2 Neutral spaces to Passive Support." @@ -671,7 +676,9 @@ EVENT 45 SHADED 45 if AUTOMATIC - aid (-count_matching_spaces(s=>has_faction_piece(s,AUC))) + count_spaces has_faction_piece(s, AUC) + log `${game.vm.count} spaces with AUC pieces.` + aid (-game.vm.count) else prompt "Aid -1 for each space with AUC pieces." space all has_auc_piece(s) @@ -700,10 +707,17 @@ EVENT 46 endspace EVENT 47 - prompt "All AUC Guerrillas to Active." - piece all is_auc_guerrilla(p) && is_underground(p) - activate - endpiece + # Note: see event 59 + if AUTOMATIC + log "All AUC Guerrillas to Active." + asm for_each_piece(AUC, GUERRILLA, p => { if (piece_space(p) !== AVAILABLE) set_active(p) }) + else + prompt "All AUC Guerrillas to Active." + piece all is_auc_guerrilla(p) && is_underground(p) + activate + endpiece + endif + current GOVT prompt "All Police free Assault AUC as if Troops." space all has_police(s) && has_auc_piece(s) # TODO: test this @@ -907,10 +921,16 @@ EVENT 56 transfer CARTELS GOVT 15 SHADED 56 - prompt "Add twice Cartels pieces in Cities to Cartels Resources." - piece all is_cartels_piece(p) && is_city(s) - auto_resources CARTELS 2 - endpiece + if AUTOMATIC + count_pieces is_cartels_piece(p) && is_city(s) + log `${game.vm.count} Cartels pieces in Cities.` + resources CARTELS (2*game.vm.count) + else + prompt "Add twice Cartels pieces in Cities to Cartels Resources." + piece all is_cartels_piece(p) && is_city(s) + auto_resources CARTELS 2 + endpiece + endif prompt "Place a Cartels Base in each of 2 Cities." space 2 is_city(s) && can_stack_base(s, CARTELS) auto_place CARTELS BASE @@ -954,22 +974,33 @@ SHADED 58 endpiece EVENT 59 + # Note: see event 47 + if AUTOMATIC + log "All Cartels Guerrillas to Active." + asm for_each_piece(CARTELS, GUERRILLA, p => { if (piece_space(p) !== AVAILABLE) set_active(p) }) + else + prompt "All Cartels Guerrillas to Active." + piece all is_cartels_guerrilla(p) && is_underground(p) + activate + endpiece + endif current GOVT - prompt "All Cartels Guerrillas to Active." - piece all is_cartels_guerrilla(p) && is_underground(p) - activate - endpiece prompt "Free Assault against Cartels in each space." space all can_assault_in_space_faction(s, CARTELS) free_assault_cartels endspace SHADED 59 + if AUTOMATIC + log "All Cartels Guerrillas to Underground." + asm for_each_piece(CARTELS, GUERRILLA, set_underground) + else + prompt "Flip all Cartels Guerrillas Underground." + piece all is_cartels_guerrilla(p) && is_active(p) + underground + endpiece + endif current CARTELS - prompt "Flip all Cartels Guerrillas Underground." - piece all is_cartels_guerrilla(p) && is_active(p) - underground - endpiece prompt "Relocate up to 3 Cartels Guerrillas anywhere." piece_undo_opt 3 is_cartels_guerrilla(p) prompt "Relocate Cartels Guerrilla anywhere." @@ -1056,9 +1087,12 @@ EVENT 64 SHADED 64 if AUTOMATIC - asm game.vm.n = count_matching_pieces((p,s) => is_cartels_base(p) && is_city(s)) * 2 - asm game.vm.n += count_matching_pieces((p,s) => is_cartels_base(p) && is_dept(s)) - resources CARTELS (game.vm.n) + count_pieces is_cartels_base(p) && is_city(s) + log `${game.vm.count} Cartels Bases in Cities.` + resources CARTELS (2*game.vm.count) + count_pieces is_cartels_base(p) && is_dept(s) + log `${game.vm.count} Cartels Bases in Departments.` + resources CARTELS (game.vm.count) else prompt "Cartels Resources +2 for each Cartels Base in a City." piece all is_cartels_base(p) && is_city(s) @@ -1117,10 +1151,16 @@ EVENT 68 endif SHADED 68 - prompt "Cartels Resources +2 per Cartels piece in coastal spaces." - piece all is_cartels_piece(p) && is_coastal_space(s) - auto_resources CARTELS 2 - endpiece + if AUTOMATIC + count_pieces is_cartels_piece(p) && is_coastal_space(s) + log `${game.vm.count} Cartels pieces in coastal spaces.` + resources CARTELS (2*game.vm.count) + else + prompt "Cartels Resources +2 per Cartels piece in coastal spaces." + piece all is_cartels_piece(p) && is_coastal_space(s) + auto_resources CARTELS 2 + endpiece + endif EVENT 69 prompt "Select source space." @@ -1151,10 +1191,16 @@ EVENT 69 endspace EVENT 70 - prompt "Government Resources +6 for each Forest without Guerrillas." - space_no_undo all is_forest(s) && !has_any_guerrilla(s) - auto_resources GOVT 6 - endspace + if AUTOMATIC + count_spaces is_forest(s) && !has_any_guerrilla(s) + log `${game.vm.count} Forests without Guerrillas.` + resources GOVT (2*game.vm.count) + else + prompt "Government Resources +6 for each Forest without Guerrillas." + space_no_undo all is_forest(s) && !has_any_guerrilla(s) + auto_resources GOVT 6 + endspace + endif SHADED 70 current FARC_AUC_CARTELS diff --git a/play.html b/play.html index 599092b..aeaa53d 100644 --- a/play.html +++ b/play.html @@ -35,6 +35,7 @@ + diff --git a/rules.js b/rules.js index da142ba..dd98cc2 100644 --- a/rules.js +++ b/rules.js @@ -6621,6 +6621,16 @@ function vm_mark_space() { vm_next() } +function vm_count_spaces() { + game.vm.count = count_matching_spaces(vm_inst(1)) + vm_next() +} + +function vm_count_pieces() { + game.vm.count = count_matching_pieces(vm_inst(1)) + vm_next() +} + // VM: AUTOMATED ACTIONS function vm_eligible() { @@ -8739,10 +8749,16 @@ CODE[41 * 2 + 0] = [ // SHADED 41 CODE[41 * 2 + 1] = [ + [ vm_if, ()=>AUTOMATIC ], + [ vm_count_spaces, (s)=>has_auc_piece(s) && has_cartels_piece(s) ], + [ vm_log, ()=>`${game.vm.count} spaces with AUC and Cartels pieces.` ], + [ vm_resources, AUC, ()=>(3*game.vm.count) ], + [ vm_else ], [ vm_prompt, "AUC Resources +3 for each space with AUC and Cartels pieces." ], [ vm_space, true, 999, 999, (s)=>has_auc_piece(s) && has_cartels_piece(s) ], [ vm_auto_resources, AUC, 3 ], [ vm_endspace ], + [ vm_endif ], [ vm_return ], ] @@ -8835,7 +8851,9 @@ CODE[45 * 2 + 0] = [ // SHADED 45 CODE[45 * 2 + 1] = [ [ vm_if, ()=>AUTOMATIC ], - [ vm_aid, ()=>(-count_matching_spaces(s=>has_faction_piece(s,AUC))) ], + [ vm_count_spaces, (s)=>has_faction_piece(s, AUC) ], + [ vm_log, ()=>`${game.vm.count} spaces with AUC pieces.` ], + [ vm_aid, ()=>(-game.vm.count) ], [ vm_else ], [ vm_prompt, "Aid -1 for each space with AUC pieces." ], [ vm_space, true, 999, 999, (s)=>has_auc_piece(s) ], @@ -8870,10 +8888,16 @@ CODE[46 * 2 + 0] = [ // EVENT 47 CODE[47 * 2 + 0] = [ + [ vm_if, ()=>AUTOMATIC ], + [ vm_log, "All AUC Guerrillas to Active." ], + [ vm_asm, ()=>for_each_piece(AUC, GUERRILLA, p => { if (piece_space(p) !== AVAILABLE) set_active(p) }) ], + [ vm_else ], [ vm_prompt, "All AUC Guerrillas to Active." ], [ vm_piece, false, 999, 999, (p,s)=>is_auc_guerrilla(p) && is_underground(p) ], [ vm_activate ], [ vm_endpiece ], + [ vm_endif ], + [ vm_current, GOVT ], [ vm_prompt, "All Police free Assault AUC as if Troops." ], [ vm_space, true, 999, 999, (s)=>has_police(s) && has_auc_piece(s) ], [ vm_free_assault_auc ], @@ -9123,10 +9147,16 @@ CODE[56 * 2 + 0] = [ // SHADED 56 CODE[56 * 2 + 1] = [ + [ vm_if, ()=>AUTOMATIC ], + [ vm_count_pieces, (p,s)=>is_cartels_piece(p) && is_city(s) ], + [ vm_log, ()=>`${game.vm.count} Cartels pieces in Cities.` ], + [ vm_resources, CARTELS, ()=>(2*game.vm.count) ], + [ vm_else ], [ vm_prompt, "Add twice Cartels pieces in Cities to Cartels Resources." ], [ vm_piece, false, 999, 999, (p,s)=>is_cartels_piece(p) && is_city(s) ], [ vm_auto_resources, CARTELS, 2 ], [ vm_endpiece ], + [ vm_endif ], [ vm_prompt, "Place a Cartels Base in each of 2 Cities." ], [ vm_space, true, 2, 2, (s)=>is_city(s) && can_stack_base(s, CARTELS) ], [ vm_auto_place, false, 0, CARTELS, BASE ], @@ -9184,11 +9214,16 @@ CODE[58 * 2 + 1] = [ // EVENT 59 CODE[59 * 2 + 0] = [ - [ vm_current, GOVT ], + [ vm_if, ()=>AUTOMATIC ], + [ vm_log, "All Cartels Guerrillas to Active." ], + [ vm_asm, ()=>for_each_piece(CARTELS, GUERRILLA, p => { if (piece_space(p) !== AVAILABLE) set_active(p) }) ], + [ vm_else ], [ vm_prompt, "All Cartels Guerrillas to Active." ], [ vm_piece, false, 999, 999, (p,s)=>is_cartels_guerrilla(p) && is_underground(p) ], [ vm_activate ], [ vm_endpiece ], + [ vm_endif ], + [ vm_current, GOVT ], [ vm_prompt, "Free Assault against Cartels in each space." ], [ vm_space, true, 999, 999, (s)=>can_assault_in_space_faction(s, CARTELS) ], [ vm_free_assault_cartels ], @@ -9198,11 +9233,16 @@ CODE[59 * 2 + 0] = [ // SHADED 59 CODE[59 * 2 + 1] = [ - [ vm_current, CARTELS ], + [ vm_if, ()=>AUTOMATIC ], + [ vm_log, "All Cartels Guerrillas to Underground." ], + [ vm_asm, ()=>for_each_piece(CARTELS, GUERRILLA, set_underground) ], + [ vm_else ], [ vm_prompt, "Flip all Cartels Guerrillas Underground." ], [ vm_piece, false, 999, 999, (p,s)=>is_cartels_guerrilla(p) && is_active(p) ], [ vm_underground ], [ vm_endpiece ], + [ vm_endif ], + [ vm_current, CARTELS ], [ vm_prompt, "Relocate up to 3 Cartels Guerrillas anywhere." ], [ vm_piece, true, 0, 3, (p,s)=>is_cartels_guerrilla(p) ], [ vm_prompt, "Relocate Cartels Guerrilla anywhere." ], @@ -9316,9 +9356,12 @@ CODE[64 * 2 + 0] = [ // SHADED 64 CODE[64 * 2 + 1] = [ [ vm_if, ()=>AUTOMATIC ], - [ vm_asm, ()=>game.vm.n = count_matching_pieces((p,s) => is_cartels_base(p) && is_city(s)) * 2 ], - [ vm_asm, ()=>game.vm.n += count_matching_pieces((p,s) => is_cartels_base(p) && is_dept(s)) ], - [ vm_resources, CARTELS, ()=>(game.vm.n) ], + [ vm_count_pieces, (p,s)=>is_cartels_base(p) && is_city(s) ], + [ vm_log, ()=>`${game.vm.count} Cartels Bases in Cities.` ], + [ vm_resources, CARTELS, ()=>(2*game.vm.count) ], + [ vm_count_pieces, (p,s)=>is_cartels_base(p) && is_dept(s) ], + [ vm_log, ()=>`${game.vm.count} Cartels Bases in Departments.` ], + [ vm_resources, CARTELS, ()=>(game.vm.count) ], [ vm_else ], [ vm_prompt, "Cartels Resources +2 for each Cartels Base in a City." ], [ vm_piece, false, 999, 999, (p,s)=>is_cartels_base(p) && is_city(s) ], @@ -9400,10 +9443,16 @@ CODE[68 * 2 + 0] = [ // SHADED 68 CODE[68 * 2 + 1] = [ + [ vm_if, ()=>AUTOMATIC ], + [ vm_count_pieces, (p,s)=>is_cartels_piece(p) && is_coastal_space(s) ], + [ vm_log, ()=>`${game.vm.count} Cartels pieces in coastal spaces.` ], + [ vm_resources, CARTELS, ()=>(2*game.vm.count) ], + [ vm_else ], [ vm_prompt, "Cartels Resources +2 per Cartels piece in coastal spaces." ], [ vm_piece, false, 999, 999, (p,s)=>is_cartels_piece(p) && is_coastal_space(s) ], [ vm_auto_resources, CARTELS, 2 ], [ vm_endpiece ], + [ vm_endif ], [ vm_return ], ] @@ -9440,10 +9489,16 @@ CODE[69 * 2 + 0] = [ // EVENT 70 CODE[70 * 2 + 0] = [ + [ vm_if, ()=>AUTOMATIC ], + [ vm_count_spaces, (s)=>is_forest(s) && !has_any_guerrilla(s) ], + [ vm_log, ()=>`${game.vm.count} Forests without Guerrillas.` ], + [ vm_resources, GOVT, ()=>(2*game.vm.count) ], + [ vm_else ], [ vm_prompt, "Government Resources +6 for each Forest without Guerrillas." ], [ vm_space, false, 999, 999, (s)=>is_forest(s) && !has_any_guerrilla(s) ], [ vm_auto_resources, GOVT, 6 ], [ vm_endspace ], + [ vm_endif ], [ vm_return ], ] diff --git a/tools/gencode.js b/tools/gencode.js index ece66df..c0e1cc9 100644 --- a/tools/gencode.js +++ b/tools/gencode.js @@ -110,6 +110,13 @@ for (let line of fs.readFileSync("events.txt", "utf-8").split("\n")) { emit([ line[0], line.slice(1).join(" ") ]) break + case "count_spaces": + emit([ line[0], "(s)=>" + line.slice(1).join(" ") ]) + break + case "count_pieces": + emit([ line[0], "(p,s)=>" + line.slice(1).join(" ") ]) + break + case "asm": case "if": case "while": -- cgit v1.2.3