If we want our AI script to win, we must take the fight to our opponent. The best way to do this is by using rushes and attacks. Let's look at some rush script parts:
; >> ZEALOT RUSH SCRIPT PART
:b_zealotrush
wait_build 1 gateway
train 7 zealot
attack_add 7 zealot
attack_prepare
attack_do
attack_clear
goto a_zealotrush
; >> DRAGOON RUSH SCRIPT PART
:b_dragoonrush
wait_build 1 gateway
wait_build 1 cybernetics_core
train 8 zealot
train 4 dragoon
attack_add 8 zealot
attack_add 4 dragoon
attack_prepare
attack_do
attack_clear
goto a_dragoonrush
; >> DARK TEMPLAR RUSH SCRIPT PART
:b_darkrush
wait_build 1 gateway
wait_build 1 templar_archives
train 5 dark_templar
attack_add 5 dark_templar
attack_prepare
attack_do
attack_clear
goto a_darkrush
; >> CARRIER RUSH SCRIPT PART
:b_carrierrush
wait_build 1 stargate
wait_build 1 fleet_beacon
train 3 carrier
attack_add 3 carrier
attack_prepare
attack_do
attack_clear
goto a_carrierrush
; >> ARBITER RUSH SCRIPT PART
:b_arbiterrush
wait_build 1 stargate
wait_build 1 fleet_beacon
wait_build 1 arbiter_tribunal
train 8 carrier
train 2 arbiter
attack_add 8 carrier
attack_add 2 arbiter
attack_prepare
attack_do
attack_clear
goto a_arbiterrush
It's just like our previous zealot attack, but now we have a larger variety
of attack groups. Note that our rush groups are quite small. This means
we can only use rushes early on, as they get less and less effective later on.
For the end phase of the game we use mass attacks. On a map like Fastest Map Ever mass attacks are common. The classic broodwar AI tends to lose on this map, just because it plays too defensive and doesn't use large attacks. Let's not make the same mistake!
; >> MASS ZEALOT SCRIPT PART
:b_masszealot
wait_build 1 gateway
train 30 zealot
goto a_masszealot
; >> MASS DARK TEMPLAR SCRIPT PART
:b_massdark
wait_build 1 gateway
wait_build 1 templar_archives
train 20 dark_templar
goto a_massdark
; >> MASS SCOUT/REAVER SCRIPT PART
:b_massreaver
wait_build 1 stargate
wait_build 1 robotics_support_bay
wait_build 1 robotics_facility
train 12 scout
train 8 reaver
goto a_massreaver
; >> MASS ARBITER SCRIPT PART
:b_massarbiter
wait_build 1 stargate
wait_build 1 fleet_beacon
wait_build 1 arbiter_tribunal
train 6 arbiter
train 12 carrier
goto a_massarbiter
The 1st thing you will notice about the mass attack script parts is
that they lack any attack commands. This is because we are going to
use these mass attacks in combination with a new command: send_suicide 0.
This command sends every attack unit on a strategic suicide mission.
Though this leaves the base vulnerable to counter attacks, it gives
us a really good chance at defeating an enemy. We'll get back at this
command later. Now it's time to put the attacks in a script sequence
we can use at will.
A good way to make use of the rush/attack script parts is by creating a small multirun script part (i.e. a small script part that can be run in parallel with the main code section) using the notowns_jump and the resources_jump command. Let's take a look at an example:
; --- MULTIRUN JUMP EXAMPLE (not part of our script)
:m_rushcheck
notowns_jump gateway nocheck
wait 100
resources_jump 700 0 b_zealotrush
:a_zealotrush
:nocheck
stop
The script above first checks if we do not own a gateway. If the answer is yes (i.e. we don't own a gateway) it proceeds to nocheck and stops the multirun. If the answer is no, it continues to the next line. It waits a short while before checking whether it has enough (700 minerals, 0 gas) resources. If the answer is yes it continues to the start of the zealot rush (and eventually returns to ":a_zealotrush"), else it just proceeds and stops the multirun.
Thus the notowns_jump command checks if the AI is not (yet) the owner of a particular building
and jumps depending on the answer. If the AI does not own a building it will use the jump,
else it will proceed to the next line.
The resources_jump command does exactly what we think it does: it jumps to
a location if we own enough resources, else it just proceeds to the next line.
Now we come to the real multirun script parts. We use the same principle as in our example, once for each rush/attack. We first check if we can do a rush or attack with more advanced units. If we can't, because we lack the necessary resources or buildings, we proceed to check if we can rush or attack with less advanced units. This continues until we finally come to our zealot check.
; --- RUSH CHECK MULTIRUN SCRIPT PART
:m_rushcheck
notowns_jump arbiter_tribunal carriercheck
wait 1200
resources_jump 2000 2000 b_arbiterrush
:a_arbiterrush
:carriercheck
notowns_jump fleet_beacon darkcheck
wait 600
resources_jump 1000 700 b_carrierrush
:a_carrierrush
:darkcheck
notowns_jump templar_archives dragooncheck
wait 400
resources_jump 600 400 b_darkrush
:a_darkrush
:dragooncheck
notowns_jump cybernetics_core zealotcheck
wait 200
resources_jump 1200 200 b_dragoonrush
:a_dragoonrush
:zealotcheck
notowns_jump gateway nocheck
wait 100
resources_jump 700 0 b_zealotrush
:a_zealotrush
:nocheck
stop
Just take your time and study the multirun script part for a while.
You'll notice the wait commands, which give the AI time to gather
the necessary resources. You'll also notice that the resources
required for the jump are slightly lower than the amount it takes
to train the units. Here we presume the AI still gains resources
as it trains the units. We could argue about where the returning
points (e.g. "a_carrierrush") for each rush should be located:
after each check (as it is now) or at the end, before the
stop command. When located at the end, the chance, for example,
of a zealot rush following an arbiter rush is changed to zero.
This would seem better, but personally I prefer keeping the opponent
occupied on all levels (ground/air).
The multirun script part containing the big attacks is very much the same as the previous script part:
; --- BIG ATTACK CHECK MULTIRUN SCRIPT PART
:m_bigattackcheck
notowns_jump arbiter_tribunal massreavercheck
wait 1000
resources_jump 2000 2000 b_massarbiter
:a_massarbiter
:massreavercheck
notowns_jump robotics_support_bay massdarkcheck
notowns_jump stargate massdarkcheck
wait 1000
resources_jump 2000 1000 b_massreaver
:a_massreaver
:massdarkcheck
notowns_jump templar_archives masszealotcheck
wait 1000
resources_jump 2000 1500 b_massdark
:a_massdark
:masszealotcheck
notowns_jump gateway nomasscheck
wait 1000
resources_jump 2000 0 b_masszealot
:a_masszealot
:nomasscheck
stop
For the mass reaver attack we check the availability of both a robotics
support bay and a stargate, because we also want to add scouts to the attack.
Rushing and attacking is fun, but unless we do something about our defense the AI won't know how to act when attacked. Thus we need to tell it what units to build and use when defending the base. This is actually quite easy to do. SCAIEdit provides us with a couple of commands: defensebuild, defenseuse and defenseclear:
Here's an example:
; --- EXAMPLE DEFENSE BLOCK (not part of our script)
:b_startdefenseblock
defenseclear_gg
defensebuild_gg 1 zealot
defenseuse_gg 1 zealot
goto a_startdefenseblock
The code above assigns a zealot as a ground defense unit. Previously assigned
ground defenders are cleared. A defense script part like the one above is generally
used after the first zealots are ready.
Note: send_suicide 0 overrides the defensive orders of a unit. Thus
also units originally build for defense are sent to attack the enemy. It might
be a good idea to build extra static defense (e.g. photon cannons, sunkens)
when using this command.
The following script part describes the start defense block we will use for our Protoss AI. It's quite big, but it's easy to understand.
; --- START DEFENSE BLOCK
:b_startdefenseblock
defenseclear_gg
defensebuild_gg 1 zealot
defenseuse_gg 1 zealot
defensebuild_gg 1 dragoon
defenseuse_gg 1 dragoon
defensebuild_gg 1 reaver
defenseuse_gg 1 reaver
defensebuild_gg 1 dark_templar
defenseuse_gg 1 dark_templar
defensebuild_gg 1 carrier
defenseuse_gg 1 carrier
defensebuild_gg 1 scout
defenseuse_gg 1 scout
defensebuild_gg 1 archon
defenseuse_gg 1 archon
defenseclear_ag
defensebuild_ag 1 scout
defenseuse_ag 1 scout
defensebuild_ag 1 dragoon
defenseuse_ag 1 dragoon
defensebuild_ag 1 archon
defenseuse_ag 1 archon
defensebuild_ag 1 dark_archon
defenseuse_ag 1 dark_archon
defensebuild_ag 1 carrier
defenseuse_ag 1 carrier
defensebuild_aa 1 corsair
defenseuse_aa 1 corsair
defensebuild_aa 1 scout
defenseuse_aa 1 scout
defensebuild_aa 1 carrier
defenseuse_aa 1 carrier
defensebuild_ga 1 carrier
defenseuse_ga 1 carrier
defensebuild_ga 1 scout
defenseuse_ga 1 scout
goto a_startdefenseblock
Note that air units can also be assigned to ground to ground defense. As can be seen scouts and carriers are important for our defense, because of their allround capabilities. We can support these units by adding shield batteries to our base.
Even though this script part will be used early on in the game, the more advanced
units will only be build and used once the required buildings are available.
Normally including a line like train 12 carrier while lacking a fleet_beacon
would seriously slow down our AI. Fortunately in case of defensebuild this is
not the case.
Where zealots are nice early in the game, later on we prefer more advanced units to defend the base:
; --- FINAL DEFENSE BLOCK
:b_finaldefenseblock
defenseclear_gg
defensebuild_gg 1 reaver
defenseuse_gg 1 reaver
defensebuild_gg 1 dark_templar
defenseuse_gg 1 dark_templar
defensebuild_gg 1 carrier
defenseuse_gg 1 carrier
defenseclear_ag
defensebuild_ag 1 scout
defenseuse_ag 1 scout
defensebuild_ag 1 dragoon
defenseuse_ag 1 dragoon
defensebuild_ag 1 archon
defenseuse_ag 1 archon
defensebuild_ag 1 dark_archon
defenseuse_ag 1 dark_archon
defensebuild_ag 1 carrier
defenseuse_ag 1 carrier
defensebuild_aa 1 corsair
defenseuse_aa 1 corsair
defensebuild_aa 1 scout
defenseuse_aa 1 scout
defensebuild_aa 1 carrier
defenseuse_aa 1 carrier
defensebuild_ga 1 carrier
defenseuse_ga 1 carrier
defensebuild_ga 1 scout
defenseuse_ga 1 scout
goto a_finaldefenseblock
Scouts and carriers are still important, but we removed less advanced units like the zealot.
In the first two sections of the 4th tutorial we have designed an attack and
defense 'plan'. Now we still need an upgrade plan.
It is often said that upgrading and researching techs are one of the most important aspects of broodwar. On a map like Fastest Map Ever, where large groups of units are common, upgrades and techs are even more important. In this section we will write the concluding research script parts.
The first upgrade script part below will look familiar. It also holds the first upgrades for the cybernetics core:
; --- RESEARCH MULTIRUN SCRIPTS
:r_groundupgrades
wait_build 2 forge
upgrade 1 p_ground_weapon 70
upgrade 1 p_plasma_shield 70
wait 2700
wait_build 1 cybernetics_core
upgrade 1 p_armor 70
upgrade 2 p_plasma_shield 70
wait 3600
wait_build 1 templar_archives
upgrade 2 p_ground_weapon 70
upgrade 3 p_plasma_shield 70
wait 4500
upgrade 3 p_ground_weapon 70
upgrade 2 p_armor 70
wait 4500
upgrade 3 p_armor 70
stop
:r_cybupgrades
wait_build 2 cybernetics_core
upgrade 1 dragoon_range 70
upgrade 1 p_air_weapon 70
wait 2700
upgrade 1 p_plating 70
stop
Easy!
On to the next research script part:
:r_roboticsupgrades
wait_build 1 robotics_support_bay
upgrade 1 shuttle_speed 70
wait 3600
upgrade 1 reaver_capacity 70
wait 3600
upgrade 1 scarab_damage 70
stop
:r_observerupgrades
wait_build 1 observatory
upgrade 1 observer_speed 70
wait 2700
upgrade 1 observer_sight 70
stop
:r_templarupgrades
wait_build 1 citadel_of_adun
upgrade 1 zealot_speed 70
wait_build 1 templar_archives
tech psionic_storm 70
wait 2700
tech maelstrom 70
wait 2700
upgrade 1 templar_mana 70
wait 2700
upgrade 1 dark_archon_mana 70
wait 3600
tech mind_control 70
stop
:r_airupgrades
wait_build 1 fleet_beacon
upgrade 1 carrier_capacity 70
upgrade 2 p_air_weapon 70
upgrade 2 p_plating 70
wait 3600
tech disruption_web 70
upgrade 3 p_air_weapon 70
upgrade 3 p_plating 70
wait 4500
upgrade 1 scout_speed 70
wait 3600
upgrade 1 corsair_mana 70
wait 3600
upgrade 1 scout_sight 70
wait_build 1 arbiter_tribunal
tech statis_field 70
wait 4500
upgrade 1 arbiter_mana 70
stop
That's a lot of research, but trust me on this. The AI will make very good use of each upgrade and tech. If you plan to create a simple AI, which uses only a few unit types you might decide to leave out some upgrades or techs to save resources. Otherwise your AI will need all of them.


Ok, phew! Now that we have studied all these lines of code it's finally
time to put them to good use and create our first competitive AI script
in the 5th tutorial!
| Previous | Back to Index | Next |