2023 WIF AI Progress Report
Posted: Wed Dec 20, 2023 12:33 pm
Hi everyone,
I'm including below Steve's end of year summary of progress on the AI Opponent for World in Flames, which has been his main focus this year. As we've discussed previously, the goal is to have a functional AI Opponent for both sides in Barbarossa and the Japanese side in Guadalcanal. We see this as a great tool for helping players learn to play WIF and with both of those scenarios most of the movement and combat variations will be covered. Based on the progress so far, which has been tough going, we'll decide on anything beyond Guadalcanal once those initial goals are completed.
Year 2023 Progress on the Artificial Intelligence Opponent for World in Flames
Summary
The sequence of play can be broken into 5 parts: (1) beginning a scenario, (2) starting a new turn, (3) making decisions during a turn as the phasing side, (4) making decisions during a turn as the non-phasing side, and (5) the end of turn phases. In my last report I had merged the first two parts, which was incorrect. While beginning a scenario is immediately followed by starting a new turn, the Bringing in Reinforcements phase is skipped for the first turn. It is obviously important in subsequent turns,
Part I - Beginning the Game
The program enables players to select the mode of play where they compete against the AI Opponent (AIO). It automatically sets the scenario (Barbarossa), optional rules (standard set), and that the human is playing the Axis/Germany. Immediately following those actions, the program executes the decisions for the AIO setting up the Russian units and returns decision making to the human player to scrap German units and place the randomly selected German units on the map. As always occurs in Barbarossa, Germany and Italy automatically declare war on the USSR and the USSR calls out its reserves. Likewise the weather, imitative, and who goes first phases occur according to the scenario rules for Barbarossa.
Setting up the Russian units is done by the AIO using LAIO (Language for the AI Opponent) scripts. These are text files which contain branching logic to provide variety as to where the AIO places its units. To increase the challenge to the human player, random numbers are used to select which of 5 setup positions are used for each of the air, infantry, and armor/mechanized/cavalry units. In addition, the infantry unit placements vary independently for the north (Lithuania/Latvia), the center (Poland), and the south (Bessarabia). Combined with the normal random selection of which units are available to the USSR at the start of the game, the Russian forces facing the German/human player (and where they are placed), are virtually never the same.
To accomplish the initial setup for the USSR, code was written to (1) parse the LAIO scripts into instructions which the World in Flames program then (2) executes in real time (in 1 or 2 seconds). Simpler means were used to decide about scrapping units and placing the Russian naval units on the map. Once Germany declares war on the USSR, another LAIO script is used to randomize where the AIO places the USSR reserve units on the map. After the Russian reserve units are on the map, control returns to the human player to decide about aligning minors and then begin the German/Phasing side sequence of play.
The AIO code beginning the game has been completed and tested by the beta testers.
Part II - Starting a New Turn
This phase is skipped during the first turn. In the second and subsequent turns the AIO identifies which USSR units are available as reinforcements. Presently it establishes all the possible hexes/cities where the land and air units can arrive - there are no naval reinforcements for the USSR in Barbarossa. One remaining task is to code the AIO selecting good hexes in which to place its reinforcements. Given the large number of home cities in the USSR and the dozen or so units that arrive each turn, there are numerous possibilities. My goal is to find a Good hex for each unit - not to try and find the Best hex.
The AIO always asks for a reroll when possible. It always chooses to move first, when offered the opportunity. Those decisions are hard coded for Barbarossa, primarily because the scenario is only 5 turns long.
Aside from placing reinforcements on the map, the code for starting a new turn has been completed.
Part III - Non-phasing Side Decisions
When the German/human player makes decisions as the phasing side, there are frequent places in the sequence of play where the AIO must make decisions on behalf of the USSR. For example, during air missions and land combat. The code for making these decisions is ‘hard-coded’ in World in Flames; it does not use LAIO scripts. Most of these decisions are quite obvious (e.g., the USSR always chooses the Assault table when defending in land combats). Since the best (or near best) choice can be chosen easily, there was no need to create an elaborate process to make the hypothetical optimal choice. Indeed, experienced players often argue about many of these decisions as to which answer is best, so Optimal is not clear cut.
Part IV - Phasing Side Decisions
In general, the phases where the phasing side needs to make decisions can be divided into: Naval (naval air, naval movement, and naval combat), Air (strategic bombardment, carpet bombing, ground strikes), and Land (rail movement, land movement, air transport of land units, unloading land units, invasion, paradrop, land combat declaration, and land combat resolution). Additionally, there are a collection of other phases at the end of the impulse (air rebase and reorganization by air/naval/HQ units).
Naval
The AIO is never going to send naval units out to sea. In Barbarossa it is far more important to take Land Actions in order to move all the Russian land units. Overall, the Barbarossa scenario has little for the naval units to do, especially for the USSR. Hence, in all the Naval phases (listed above) the AIO will move no units and initiate no combats.
Air
The optional rules that the AIO will be using do not include carpet bombing, so none of those air missions will be possible. We have decided that the AIO will not be flying any strategic bombing missions either. Because the game is only 5 turns long, producing new units is very limited. As a consequence, production points have little value. Wasting air missions, and possibly air units, on strategic bombing in an attempt to impact the Axis side’s production, would be a bad idea.
That leaves just the ground strike phase in the Air phases (listed above) where the AIO might decide to risk its air force. During the first phase of the first turn, the USSR is unable to fly any air missions, so writing code for ground strikes isn’t necessary until the fourth impulse of the first turn. Guidelines for how those decisions will be made have been prepared, but the code to implement them remains to be written. Currently the AIO flies no ground strike missions.
Land
Deciding on what to do in the Land phases (as listed above) requires formulating an overall operational plan on where land units should attack, defend, and retreat. That work was completed in 2021. In 2023 I wrote code to figure out where precisely the front lines currently are for each land region. That was easy enough in principal but took some time to get right, given that the Baltic Sea frequently breaks the front line into northern and southern pieces. In essence, the existing front line is where an Axis controlled hex is adjacent to an Allied controlled hex (regardless of intervening Alpine and lake hex sides). The tricky bit occurs when Finland and Hungary are neutral. The AIO has to treat hexes in those countries as Axis controlled, since the Axis player can bring those countries into the war whenever he likes.
Determining a new hex front line depends on whether the AIO can and should move land units to reinforce existing front lines or build new ones. Issuing actual movement orders to the land units was a large part of the work I completed in 2023. That code is now completed and has been ‘lightly’ tested by the beta testers.
End of Impulse Phases
Decisions in the air rebase and reorganization phases at the end of the phasing side’s impulse are fairly easy to make. Although they still need to be coded. Air units are to be placed behind the front lines, but close enough to be within range of reaching them. Forest hexes are preferred and the air units should be spread out, so that only one air unit is in each hex.
Reorganization by naval and air units is rarely useful and can be eliminated from consideration. Reorganization by an HQ unit is a different matter. Indeed, the original setup for the AIO HQs and placement of reserve units anticipates that reserve units will be reorganized by the USSR/AIO at the end of the second impulse of the game. Other than that, reorganization by HQs is likely to be uncommon. HQ units are too important for maintaining supply to the land and air.units.
The current assessment is that 90% the code for the AIO to act as the phasing side has been completed.
Part V - End of Turn Decisions
One of the big decisions in the end of turn phases is Production Planning. However, here no new code was needed for the AIO. The program already is excellent at routing resources to factories overland. The AIO just uses those decisions for that phase of the game. Likewise, the AIO does not break down or reform units, and never surrenders. The phases in the end of turn involving naval units require no decisions, since the AIO is never going to send naval or air units out to sea.
The only phase where real decisions by the AIO are needed is Production. But here the choices are quite obvious. The AIO will build land units, and possibly air units if excess build points are available after building as many land units as possible. The Barbarossa scenario is only 5 turns long, so building units that take 4 turns to arrive doesn’t make any sense. And after the second turn, units that tkae 3 turns aren’t very attractive choices either. It didn’t take a lot of code to translate available build points, available units, and turns remaining into a list of units to be built.
The AIO code the end turn decisions was been completed in 2023 but needs testing by the beta testers.
Schedule for 2024
The expectation is that the AIO will be playing the Russian side of the Barbarossa scenario fairly well by March 1st, 2024.
Then the next task will be to get the AIO to play the German side of Barbarossa. That will entail making the AIO devise land attacks supported by ground strikes and ground suppport. Sometime in the middle of the year is my estimate for the AIO making decent decisions the Germans.
The last task for the AIO will be playing the Japanese side of the Guadalcanal scenario. The Japanese side is easier for a couple of reasons: there is only one major power on the Axis side, and the Japanese are primarily concerned with defending their convoy pipelines. The human player will have the more difficult task of coordinating the Commonwealth and US forces and breaking the Japanese convoy pipelines - without losing a lot of carriers.
I'm including below Steve's end of year summary of progress on the AI Opponent for World in Flames, which has been his main focus this year. As we've discussed previously, the goal is to have a functional AI Opponent for both sides in Barbarossa and the Japanese side in Guadalcanal. We see this as a great tool for helping players learn to play WIF and with both of those scenarios most of the movement and combat variations will be covered. Based on the progress so far, which has been tough going, we'll decide on anything beyond Guadalcanal once those initial goals are completed.
Year 2023 Progress on the Artificial Intelligence Opponent for World in Flames
Summary
The sequence of play can be broken into 5 parts: (1) beginning a scenario, (2) starting a new turn, (3) making decisions during a turn as the phasing side, (4) making decisions during a turn as the non-phasing side, and (5) the end of turn phases. In my last report I had merged the first two parts, which was incorrect. While beginning a scenario is immediately followed by starting a new turn, the Bringing in Reinforcements phase is skipped for the first turn. It is obviously important in subsequent turns,
Part I - Beginning the Game
The program enables players to select the mode of play where they compete against the AI Opponent (AIO). It automatically sets the scenario (Barbarossa), optional rules (standard set), and that the human is playing the Axis/Germany. Immediately following those actions, the program executes the decisions for the AIO setting up the Russian units and returns decision making to the human player to scrap German units and place the randomly selected German units on the map. As always occurs in Barbarossa, Germany and Italy automatically declare war on the USSR and the USSR calls out its reserves. Likewise the weather, imitative, and who goes first phases occur according to the scenario rules for Barbarossa.
Setting up the Russian units is done by the AIO using LAIO (Language for the AI Opponent) scripts. These are text files which contain branching logic to provide variety as to where the AIO places its units. To increase the challenge to the human player, random numbers are used to select which of 5 setup positions are used for each of the air, infantry, and armor/mechanized/cavalry units. In addition, the infantry unit placements vary independently for the north (Lithuania/Latvia), the center (Poland), and the south (Bessarabia). Combined with the normal random selection of which units are available to the USSR at the start of the game, the Russian forces facing the German/human player (and where they are placed), are virtually never the same.
To accomplish the initial setup for the USSR, code was written to (1) parse the LAIO scripts into instructions which the World in Flames program then (2) executes in real time (in 1 or 2 seconds). Simpler means were used to decide about scrapping units and placing the Russian naval units on the map. Once Germany declares war on the USSR, another LAIO script is used to randomize where the AIO places the USSR reserve units on the map. After the Russian reserve units are on the map, control returns to the human player to decide about aligning minors and then begin the German/Phasing side sequence of play.
The AIO code beginning the game has been completed and tested by the beta testers.
Part II - Starting a New Turn
This phase is skipped during the first turn. In the second and subsequent turns the AIO identifies which USSR units are available as reinforcements. Presently it establishes all the possible hexes/cities where the land and air units can arrive - there are no naval reinforcements for the USSR in Barbarossa. One remaining task is to code the AIO selecting good hexes in which to place its reinforcements. Given the large number of home cities in the USSR and the dozen or so units that arrive each turn, there are numerous possibilities. My goal is to find a Good hex for each unit - not to try and find the Best hex.
The AIO always asks for a reroll when possible. It always chooses to move first, when offered the opportunity. Those decisions are hard coded for Barbarossa, primarily because the scenario is only 5 turns long.
Aside from placing reinforcements on the map, the code for starting a new turn has been completed.
Part III - Non-phasing Side Decisions
When the German/human player makes decisions as the phasing side, there are frequent places in the sequence of play where the AIO must make decisions on behalf of the USSR. For example, during air missions and land combat. The code for making these decisions is ‘hard-coded’ in World in Flames; it does not use LAIO scripts. Most of these decisions are quite obvious (e.g., the USSR always chooses the Assault table when defending in land combats). Since the best (or near best) choice can be chosen easily, there was no need to create an elaborate process to make the hypothetical optimal choice. Indeed, experienced players often argue about many of these decisions as to which answer is best, so Optimal is not clear cut.
Part IV - Phasing Side Decisions
In general, the phases where the phasing side needs to make decisions can be divided into: Naval (naval air, naval movement, and naval combat), Air (strategic bombardment, carpet bombing, ground strikes), and Land (rail movement, land movement, air transport of land units, unloading land units, invasion, paradrop, land combat declaration, and land combat resolution). Additionally, there are a collection of other phases at the end of the impulse (air rebase and reorganization by air/naval/HQ units).
Naval
The AIO is never going to send naval units out to sea. In Barbarossa it is far more important to take Land Actions in order to move all the Russian land units. Overall, the Barbarossa scenario has little for the naval units to do, especially for the USSR. Hence, in all the Naval phases (listed above) the AIO will move no units and initiate no combats.
Air
The optional rules that the AIO will be using do not include carpet bombing, so none of those air missions will be possible. We have decided that the AIO will not be flying any strategic bombing missions either. Because the game is only 5 turns long, producing new units is very limited. As a consequence, production points have little value. Wasting air missions, and possibly air units, on strategic bombing in an attempt to impact the Axis side’s production, would be a bad idea.
That leaves just the ground strike phase in the Air phases (listed above) where the AIO might decide to risk its air force. During the first phase of the first turn, the USSR is unable to fly any air missions, so writing code for ground strikes isn’t necessary until the fourth impulse of the first turn. Guidelines for how those decisions will be made have been prepared, but the code to implement them remains to be written. Currently the AIO flies no ground strike missions.
Land
Deciding on what to do in the Land phases (as listed above) requires formulating an overall operational plan on where land units should attack, defend, and retreat. That work was completed in 2021. In 2023 I wrote code to figure out where precisely the front lines currently are for each land region. That was easy enough in principal but took some time to get right, given that the Baltic Sea frequently breaks the front line into northern and southern pieces. In essence, the existing front line is where an Axis controlled hex is adjacent to an Allied controlled hex (regardless of intervening Alpine and lake hex sides). The tricky bit occurs when Finland and Hungary are neutral. The AIO has to treat hexes in those countries as Axis controlled, since the Axis player can bring those countries into the war whenever he likes.
Determining a new hex front line depends on whether the AIO can and should move land units to reinforce existing front lines or build new ones. Issuing actual movement orders to the land units was a large part of the work I completed in 2023. That code is now completed and has been ‘lightly’ tested by the beta testers.
End of Impulse Phases
Decisions in the air rebase and reorganization phases at the end of the phasing side’s impulse are fairly easy to make. Although they still need to be coded. Air units are to be placed behind the front lines, but close enough to be within range of reaching them. Forest hexes are preferred and the air units should be spread out, so that only one air unit is in each hex.
Reorganization by naval and air units is rarely useful and can be eliminated from consideration. Reorganization by an HQ unit is a different matter. Indeed, the original setup for the AIO HQs and placement of reserve units anticipates that reserve units will be reorganized by the USSR/AIO at the end of the second impulse of the game. Other than that, reorganization by HQs is likely to be uncommon. HQ units are too important for maintaining supply to the land and air.units.
The current assessment is that 90% the code for the AIO to act as the phasing side has been completed.
Part V - End of Turn Decisions
One of the big decisions in the end of turn phases is Production Planning. However, here no new code was needed for the AIO. The program already is excellent at routing resources to factories overland. The AIO just uses those decisions for that phase of the game. Likewise, the AIO does not break down or reform units, and never surrenders. The phases in the end of turn involving naval units require no decisions, since the AIO is never going to send naval or air units out to sea.
The only phase where real decisions by the AIO are needed is Production. But here the choices are quite obvious. The AIO will build land units, and possibly air units if excess build points are available after building as many land units as possible. The Barbarossa scenario is only 5 turns long, so building units that take 4 turns to arrive doesn’t make any sense. And after the second turn, units that tkae 3 turns aren’t very attractive choices either. It didn’t take a lot of code to translate available build points, available units, and turns remaining into a list of units to be built.
The AIO code the end turn decisions was been completed in 2023 but needs testing by the beta testers.
Schedule for 2024
The expectation is that the AIO will be playing the Russian side of the Barbarossa scenario fairly well by March 1st, 2024.
Then the next task will be to get the AIO to play the German side of Barbarossa. That will entail making the AIO devise land attacks supported by ground strikes and ground suppport. Sometime in the middle of the year is my estimate for the AIO making decent decisions the Germans.
The last task for the AIO will be playing the Japanese side of the Guadalcanal scenario. The Japanese side is easier for a couple of reasons: there is only one major power on the Axis side, and the Japanese are primarily concerned with defending their convoy pipelines. The human player will have the more difficult task of coordinating the Commonwealth and US forces and breaking the Japanese convoy pipelines - without losing a lot of carriers.