Date post: | 17-Dec-2015 |
Category: |
Documents |
Upload: | phebe-bell |
View: | 217 times |
Download: | 2 times |
Project 3Project 3
CSE 397/497 CSE 397/497
AI and Computer GamesAI and Computer Games
What is Wargus?What is Wargus?
An open source clone of Warcraft 2An open source clone of Warcraft 2
Supports the LUA scripting languageSupports the LUA scripting language
Project 3 ObjectivesProject 3 Objectives
Write a LUA script (or modify Write a LUA script (or modify custom_script) to control an army in custom_script) to control an army in WargusWargusAll three rounds will take place on the “default” mapThere will be three rounds:There will be three rounds: Defeat an early rush opponent (soldiers_rush)Defeat an early rush opponent (soldiers_rush) Defeat a delayed rush opponent Defeat a delayed rush opponent
(knights_rush)(knights_rush) Defeat a well-balanced attack (land_attack)Defeat a well-balanced attack (land_attack)
Getting StartedGetting Started
Once you’ve downloaded Wargus, Once you’ve downloaded Wargus, navigate to data.wargus\scripts\ainavigate to data.wargus\scripts\ai
When you’re ready to write your own bot, When you’re ready to write your own bot, custom_script.lua offers a good starting custom_script.lua offers a good starting pointpoint
For now, we’re going to look at For now, we’re going to look at soldiers_rush.lua…soldiers_rush.lua…
Getting StartedGetting Started
AI in Stratagus is script based. Each AI player AI in Stratagus is script based. Each AI player keeps executing scripts. There are two kinds of keeps executing scripts. There are two kinds of scripts : scripts : The main script. It starts buildings, upgrades, ... The main script. It starts buildings, upgrades, ... The action/reaction scripts. They are started by the AI The action/reaction scripts. They are started by the AI
engine, under certain condition.engine, under certain condition.
Scripts can arrange and control units using Scripts can arrange and control units using forces : forces : A script can ask for some type of unit in a force A script can ask for some type of unit in a force (using (using AiForceAiForce), and then wait for them to be ), and then wait for them to be ready (using ready (using AiWaitForceAiWaitForce). ).
More on ForcesMore on Forces
The force 0 is a special case : it holds all the The force 0 is a special case : it holds all the unassigned units, and is used to fill other forces. unassigned units, and is used to fill other forces. ( when needed, units are transfered from force 0 ( when needed, units are transfered from force 0 to others ). to others ).
Attacker units in force 0 won't be used for Attacker units in force 0 won't be used for attacksattacks
Forces from 1 to 3 are also special : They are Forces from 1 to 3 are also special : They are used as the attack reserve. Attack forces will used as the attack reserve. Attack forces will only be created using units available in those only be created using units available in those forces. forces.
soldiers_rush.luasoldiers_rush.lualocal soldiers_funcs = {local soldiers_funcs = { function() return AiSleep(AiGetSleepCycles()) end,function() return AiSleep(AiGetSleepCycles()) end, function() return AiNeed(AiCityCenter()) end,function() return AiNeed(AiCityCenter()) end, function() return AiSet(AiWorker(), 1) end,function() return AiSet(AiWorker(), 1) end, function() return AiWait(AiCityCenter()) end,function() return AiWait(AiCityCenter()) end, function() return AiWait(AiWorker()) end, -- start hangs if nothing availablefunction() return AiWait(AiWorker()) end, -- start hangs if nothing available function() return AiSet(AiWorker(), 10) end,function() return AiSet(AiWorker(), 10) end, function() return AiNeed(AiBarracks()) end,function() return AiNeed(AiBarracks()) end, function() return AiForce(0, {AiSoldier(), 2}) end,function() return AiForce(0, {AiSoldier(), 2}) end, function() return AiForce(1, {AiSoldier(), 10}) end,function() return AiForce(1, {AiSoldier(), 10}) end, function() return AiWaitForce(1) end,function() return AiWaitForce(1) end, function() return AiAttackWithForce(1) end,function() return AiAttackWithForce(1) end, function() return AiSet(AiWorker(), 15) end,function() return AiSet(AiWorker(), 15) end, function() return AiNeed(AiBlacksmith()) end,function() return AiNeed(AiBlacksmith()) end, function() return AiWait(AiBlacksmith()) end,function() return AiWait(AiBlacksmith()) end, function() return AiNeed(AiBarracks()) end,function() return AiNeed(AiBarracks()) end, function() return AiResearch(AiUpgradeWeapon1()) end,function() return AiResearch(AiUpgradeWeapon1()) end, function() return AiResearch(AiUpgradeArmor1()) end,function() return AiResearch(AiUpgradeArmor1()) end, function() return AiResearch(AiUpgradeWeapon2()) end,function() return AiResearch(AiUpgradeWeapon2()) end, function() return AiResearch(AiUpgradeArmor2()) end,function() return AiResearch(AiUpgradeArmor2()) end, function() return AiSleep(500) end,function() return AiSleep(500) end, function() return AiForce(0, {AiSoldier(), 4}) end,function() return AiForce(0, {AiSoldier(), 4}) end, function() return AiForce(1, {AiSoldier(), 10}) end,function() return AiForce(1, {AiSoldier(), 10}) end, function() return AiWaitForce(1) end,function() return AiWaitForce(1) end, function() return AiAttackWithForce(1) end,function() return AiAttackWithForce(1) end, function() return AiSoldiersRushEndloop() end,function() return AiSoldiersRushEndloop() end,}}
soldiers_rush in depthsoldiers_rush in depth
function() return AiNeed(AiCityCenter()) end, function() return AiNeed(AiCityCenter()) end, --we need a city center--we need a city center
function() return AiSet(AiWorker(), 1) end, function() return AiSet(AiWorker(), 1) end, --we need 1 worker for this--we need 1 worker for this
function() return AiWait(AiCityCenter()) end, function() return AiWait(AiCityCenter()) end, --wait until we have a center before continuing--wait until we have a center before continuing
function() return AiWait(AiWorker()) end, function() return AiWait(AiWorker()) end, -- hangs if nothing available-- hangs if nothing available
function() return AiSet(AiWorker(), 10) end, function() return AiSet(AiWorker(), 10) end, --now we need 10 workers--now we need 10 workers
function() return AiNeed(AiBarracks()) end, function() return AiNeed(AiBarracks()) end, --need a barracks, too--need a barracks, too
• AiNeed() always refers to one unitAiNeed() always refers to one unit• AiSet() can specify the number neededAiSet() can specify the number needed• Remember, AiSset(AiWorker(), 10) will not necessarily Remember, AiSset(AiWorker(), 10) will not necessarily
build 10 Workers, it will build as many as it needs until we build 10 Workers, it will build as many as it needs until we have 10have 10
soldiers_rush in depthsoldiers_rush in depth
function() return AiForce(0, {AiSoldier(), 2}) end, function() return AiForce(0, {AiSoldier(), 2}) end, --we need 2 soldiers for force 0--we need 2 soldiers for force 0
function() return AiForce(1, {AiSoldier(), 10}) end, function() return AiForce(1, {AiSoldier(), 10}) end, --we need 10 soldiers for force 1--we need 10 soldiers for force 1
function() return AiWaitForce(1) end, function() return AiWaitForce(1) end, --wait until force 1 is ready, then…--wait until force 1 is ready, then…
function() return AiAttackWithForce(1) end, function() return AiAttackWithForce(1) end, --attack!--attack!
• The AI automatically knows where to attackThe AI automatically knows where to attack• Units in defense forces (0 is a defense force, by default) Units in defense forces (0 is a defense force, by default)
will automatically respond to buildings being attackedwill automatically respond to buildings being attacked
soldiers_rush in depthsoldiers_rush in depthfunction() return AiSet(AiWorker(), 15) end, function() return AiSet(AiWorker(), 15) end, --make sure we have 15 workers now--make sure we have 15 workers nowfunction() return AiNeed(AiBlacksmith()) end, function() return AiNeed(AiBlacksmith()) end, --do we have a blacksmith?--do we have a blacksmith?function() return AiWait(AiBlacksmith()) end, function() return AiWait(AiBlacksmith()) end, --wait until we have one--wait until we have onefunction() return AiNeed(AiBarracks()) end, function() return AiNeed(AiBarracks()) end, --make sure we still have a barracks--make sure we still have a barracksfunction() return AiResearch(AiUpgradeWeapon1()) end, function() return AiResearch(AiUpgradeWeapon1()) end, --upgrade our weapons--upgrade our weaponsfunction() return AiResearch(AiUpgradeArmor1()) end, function() return AiResearch(AiUpgradeArmor1()) end, --and armor--and armorfunction() return AiResearch(AiUpgradeWeapon2()) end,function() return AiResearch(AiUpgradeWeapon2()) end,function() return AiResearch(AiUpgradeArmor2()) end,function() return AiResearch(AiUpgradeArmor2()) end,function() return AiSleep(500) end, function() return AiSleep(500) end, --wait, since this is going to take a while--wait, since this is going to take a while
• Workers will automatically harvest resources and build Workers will automatically harvest resources and build farms, however you can build extra farms, if you wantfarms, however you can build extra farms, if you want
soldiers_rush in depthsoldiers_rush in depth
function() return AiForce(0, {AiSoldier(), 4}) end, function() return AiForce(0, {AiSoldier(), 4}) end, --build up some more defenses--build up some more defenses
function() return AiForce(1, {AiSoldier(), 10}) end, function() return AiForce(1, {AiSoldier(), 10}) end, --and another force to attack with--and another force to attack with
function() return AiWaitForce(1) end, function() return AiWaitForce(1) end, --wait for new attack force--wait for new attack force
function() return AiAttackWithForce(1) end, function() return AiAttackWithForce(1) end, --then attack--then attack
function() return AiSoldiersRushEndloop() end, function() return AiSoldiersRushEndloop() end, --call end loop--call end loop
Some Final NotesSome Final Notes
The scripting documentation is not The scripting documentation is not included with Wargus, because it is slightly included with Wargus, because it is slightly out of dateout of date
It will be available on the website, but not It will be available on the website, but not all commands will work as writtenall commands will work as written
Some Final NotesSome Final Notes
Project 3 is due Friday, October 15Project 3 is due Friday, October 15
Script must be emailed to me, jemj, by Script must be emailed to me, jemj, by midnight the night beforemidnight the night before
Email presentations to Professor Munoz, Email presentations to Professor Munoz, hem4hem4
Helpful linksHelpful links
Wargus Home PageWargus Home Page http://http://wargus.sourceforge.netwargus.sourceforge.net//
Warcraft 2 Gameplay and Strategy FAQ’sWarcraft 2 Gameplay and Strategy FAQ’s http://www.gamefaqs.com/computer/doswin/http://www.gamefaqs.com/computer/doswin/
game/199259.htmlgame/199259.html
General Purpose LUA tutorialGeneral Purpose LUA tutorial http://lua-users.org/wiki/TutorialDirectoryhttp://lua-users.org/wiki/TutorialDirectory
#stratagus on irc.freenode.net#stratagus on irc.freenode.net