On Turn 4 of the auto-test, we see:

- CSVN_AAR_AI_AI_RungSat148.jpg (1.09 MiB) Viewed 930 times
The lead platoon of the _1ST_58TH_INF_COY_55_B_303 has reached the first way point. The other platoons trail behind.
On Turn 6, a surprise:

- CSVN_AAR_AI_AI_RungSat149.jpg (1.09 MiB) Viewed 930 times
OBJECTIVES[4] is captured! So easily. Apparently there were no BX Army defenders to contest the capture.
_1ST_58TH_INF_COY_55_B_303 proceeds to way point move on to the next objective. At Turn 8:

- CSVN_AAR_AI_AI_RungSat150.jpg (1.09 MiB) Viewed 930 times
At Turn 10:

- CSVN_AAR_AI_AI_RungSat151.jpg (1.16 MiB) Viewed 930 times
_MMG_48_307, the company's weakest unit, is indeed left behind to garrison (defend normal) OBJECTIVES[4]. The garrison() uber function etc. are all WAD!
The lead platoon has reached the way point hex 49,39. The _1ST_58TH_INF_COY_55_B_303 infantry have two paths (green arrows) leading to OBJECTIVES[12]. Which one to take?
We revise the code:
Code: Select all
attack_way_point(units, {"45,36", "47,36", "49,39", random_pick({"51,40", "51,40", "51,37"}), OBJECTIVES[12]}, NODIR, 0, 100, ATTACK_STRONG)
Um, what is that random_pick() function call doing in the list of attack_way_point() inputs (parameters)? That's odd!
But perfectly acceptable. 'random_pick({"51,40", "51,40", "51,37"})' evaluates to "51,40" or "51,37", depending (on the die roll). Whether the fourth hex in the list of way points is a hard-coded "51,40" or 'random_pick({"51,40", ...})' effectively makes no difference.
You can nest function calls in your function input lists.
With that code change, we retry the auto-test, and ... the joke's on me. That random_pick() call embedded in the attack_way_point(). It refreshes each turn, there is a new random pick each go around, so the way point move goes one way, then backtracks and goes the other way, etc., etc. Oops!
Back to the drawing board:
Code: Select all
_1ST_58TH_INF_COY_55_B_303_WAYPOINT4 = _1ST_58TH_INF_COY_55_B_303_WAYPOINT4 or random_pick({"51,40", "51,40", "51,37"})
attack_way_point(units, {"45,36", "47,36", "49,39", _1ST_58TH_INF_COY_55_B_303_WAYPOINT4, OBJECTIVES[12]}, NODIR, 0, 100, ATTACK_STRONG)
We set a new
global variable _1ST_58TH_INF_COY_55_B_303_WAYPOINT4 once and only once to the random_pick() result. With every attack_way_point() call, the fourth way point never varies. Problem solved!
Note: The issue was not embedding functions calls in function parameter lists. It is okay to do that. The issue here was that this one particular embedded function call, random_pick(), is repeatedly called turn after turn, and with each new turn, potentially gives a different result, making the way point list variable from turn to turn leading to chaotic, random movement.
Note that in the 'random_pick({"51,40", "51,40", "51,37"})' we have "51,40" twice and "51,37". This implies a 2 out of 3 chance that "51,40" will be randomly picked, "51,37" only a 1 out of 3 chance. It is more likely the 1st/58th infantry will continue taking the right fork Path (PT) to OBJECTIVES[12]. But we allow for the possibility it will go off Path and take the left fork (left green arrow in the preceding screenshot).
We could have done this:
Code: Select all
if chance(66) then
attack_way_point(units, {"45,36", "47,36", "49,39", "51,40", OBJECTIVES[12]}, NODIR, 0, 100, ATTACK_STRONG)
else
attack_way_point(units, {"45,36", "47,36", "49,39", "51,37", OBJECTIVES[12]}, NODIR, 0, 100, ATTACK_STRONG)
end
Is one way or the other briefer, more concise? Arguable. Take your pick.
We let the auto-test run another turn, then:

- CSVN_AAR_AI_AI_RungSat152.jpg (1.16 MiB) Viewed 930 times
Okay, the 1st/58th infantry are taking the right fork, on-path route to OBJECTIVES[12].
Two turns later:

- CSVN_AAR_AI_AI_RungSat153.jpg (1.1 MiB) Viewed 930 times
Side B BX Army defenders opfire at the approaching VNA infantry, but undeterred, the _2ND_PLT_305 immediately assaults OBJECTIVES[12] and captures it. That too was easy!
We are only 13 turns into the scenario and by now _1ST_58TH_INF_COY_55_B_303 has succeeded in its two assigned missions. What to do next? After garrisoning OBJECTIVES[12], the other two platoons could wander about generally southward looking for trouble, looking for BX Army supply dumps and jungle factories to destroy. Or we could let them rest on their laurels, no more orders.
Before going in, how would the VNA know that OBJECTIVES[4] and OBJECTIVES[12] were so lightly defended? Consider the other fights around the map coded and described in earlier posts. Most of them were challenges, some of them very tough fights. Like the other cases, in this case, we might suppose that _1ST_58TH_INF_COY_55_B_303 would also face some tough, drawn out fights, requiring most of the scenario to (a) do the way point moves (what if intercepted along the way by enemy units?) and (b) assault and capture the two Objectives (what if they were stoutly defended?).
No, it is reasonable that we code the _1ST_58TH_INF_COY_55_B_303 battle plan orders no further. Why write speculative code based on unlikely situations? For the 1st/58th, we will let the matter rest.
Hmm. Since we know there is a possibility that the OBJECTIVES[12] Military Post will fall as early as Turn 13, should we consider delaying the _NAVAL_ASSAULT_GROUPS_377 in their movement down the Song Long Tau to the Nga Ba Dong Tranh and beyond? Where in passing by the (OBJECTIVES[12]) Military Post they are opfired at and, as we have seen, suffering SP loss in the passage? Should we code _NAVAL_ASSAULT_GROUPS_377 maybe to delay, awaiting the _1ST_58TH_INF_COY_55_B_303 first taking out the Military Post defenders? Something to think about.