Author Topic: Orc's Simple(ish) Guide to AI'ing DSL Bots  (Read 127 times)

Offline TheOrcCorp

  • I push buttons and hope GTM doesn't explode.
  • *
  • Posts: 833
  • Rep: 20
  • A mean, green, small brained machine!
    • View Profile
    • Awards
Orc's Simple(ish) Guide to AI'ing DSL Bots
« on: August 26, 2020, 05:49:11 PM »
Right, time for the AI'ing part of my tutorial series. Don't run away, I promise everything will be explained clearly as possible!
 

AI is the code robots use in Robot Arena 2 to work as opposed to you manually driving your robot to test it or play in Parsec. Supplying your own AI code for your robot(s) to hosts for AI Tournaments makes for an easier time for us and we'll appreciate you a lot more! (If you think about it, if everyone AI'ed their bots then tournaments would happen A LOT quicker...) AI is not hard, just a bit fiddly and requires messing around with...besides it makes for better testing of your robots for things like OW or Deathmatch etc.

EXPORTING/SETTING UP A TEAM
So we've wired our robot(s) up from the last tutorial, time to get them AI'ed up! I'm going to use my bots from the previous tutorials as examples again for consistency! Select your robot, click Export and name your robot Bot0/Bot1/Bot2/Bot3/Bot4/Bot5 - these are the names the game's code recognises when loading in robots and represent the 6 slots in an AI team.
 

When done, we're going to create a new team for our AI creations. Quit your game and go into your AI folder.
 

We have a bunch of Team folders here, you can either replace an existing bot file by dragging your bot files into an existing team folder OR you right click and select New -> Folder. Name this folder to follow the last Team folder you currently have. For example, my current last folder is Team20, so I've named my new folder Team21. Copy your bot files you just exported into this folder.
 

Now go back to the AI folder and open up the Teams file. I use Notepad to do this.
 

You want to copy ALL of the text in this red square and paste it at the very bottom of the document. The following things are what you need to change:
index 0 (change 0 to your new Team folder number, in my case 21)
Red Zone (I'd suggest changing this so you know what you're looking for)
"That's where your bot will be after ten seconds with ours!" (You don't have to change this but...eh.)
AI\red_zone.bmp (Again, don't have to change this but...eh.)
Robots: 0 1 2 3 4 5 (If you have 6 robots then leave this as is, if NOT then remove the numbers to compensate. For example, I only have 4 robots so will remove 4 and 5.)
 

Save your document when you have made your changes...now we move onto AI! Open the Bindings file in your AI folder.

AI:
 

Good lord, that's a lot of text...HEY, DON'T RUN OFF! RA2 AI is compromised of smaller segments that tell a robot how to act. Here are the basic ones you need for your robots (with definitions taken from the AI-Chart)
nose - the front of the robot. Tends to be either math.pi or math.pi*2 but if you build your robot facing the side then it might be math.pi*0.5.
topspeed - speed in meters/second AI will attempt not to exceed (default 4.0).
throttle - maximum analog value AI will attempt not to exceed (default 100)
turnspeed - turning in radians/second AI will attempt not to exceed (default 2.5)
turn - maximum analog value AI will attempt not to exceed (default 60)
radius - bot radius to used to check distances to hazards, walls, and other bots. (default 1.0). With a high value, your bot will avoid hazards, with a null value, it will ignore them (but hazards will not ignore your bot!).  Low value may be useful for high speed bots like pusher or rammer that rely more on their speed than maneuver.
weapons – Id of the weapon. Once all the components with theses Id are broken, the strategy of the bot may change to pusher. You could put a number for each weapon you have. As example: ,'weapons':(1,2,3,4,5,6) You DO NOT need to exact component number.

SPINNERS also use:
range - This determines the distance for when a spinner will start spinning it's weapon.

A bonus but IMPORTANT segment is:
'invertible':True, - This allows a robot to run upside down. You may see some robots with 'invertible':False, but I tend to omit this from when I do AI as I feel it's pointless. Lets take a look at Highschool Ex II's AI line:
    list.append(("Highschool Ex II","Omni",{'nose':math.pi,'radius':0.2,'range':100,'topspeed':200,'throttle':200,'turn':60,'turnspeed':2.5,'weapons':(1,2,)}))
As you can see Highschool Ex uses the 8 basic AI parts with values that Sev has spent time on to adjust. You're gonna have to test your AI a lot to make sure your bot is running how you want it to! You can AI your bots by copying another bot's AI line and adjusting the values accordingly with trial and error! (including changing the name to your own robot otherwise you'll keep crashing your game) DSL 2.4 comes with a DSL Bindings Templates file for your convenience.

You may notice a lot of files called PY files in your AI folder...these are different commands for each robot and why you need to wire/name your buttons correctly. Let's look at some basic py types with our four example bots applied to them!
Omni.py - The jack of all trades, Omni can be used for almost anything, great for weapon combinations. Flippers with a seperate srimech, spinners with a srimech, axes, pistons etc. As you can see here, Necky doesn't have anything too fancy with this AI line, just the basics so it can fire it's weapon and self-right.
    list.append(("Necky III","Omni",{'nose':math.pi,'radius':1.4,'topspeed':100,'throttle':250,'turn':80,'turnspeed':2.5,'weapons':(16,17,18,)}))
Flipper.py - Your typical flipper AI, this is good for flippers that self-right using their flippers. VVC's nose is the opposite direction but he functions the same!
    list.append(("Vivacious C","Flipper",{'nose':math.pi*2,'range':99,'radius':0.1,'topspeed':100,'throttle':130,'turn':60,'turnspeed':2,'weapons':(18,19)}))
Spinner.py - Typical spinner AI, not much to be said really. Deadgnaws here can somewhat drive upside down but relies on invertibility more to help the spinner turn it back over.
    list.append(("Deadgnaws III","Spinner",{'invertible':True,'nose':math.pi*2,'radius':0.1,'range':500,'topspeed':100,'throttle':130,'turn':60,'turnspeed':2,'weapons':(29,30)}))
There are plenty of other binding types but these are the most used in my opinion. Now let's look at Judge.py.

JUDGE.PY
Judge.py is for robots that use Beta/Overkill motors and as such have some added commands. Before we get into these, you'll need Notepad++ (at least that's what I use) https://notepad-plus-plus.org/downloads/ - download this and then carry on reading below.
MotorID - This is the number that represents your Beta/Overkill Motor. Right click your bot file and select "Edit with Notepad++"
 

Good lord, looks like a mess right? Don't worry, scroll down till you find these parts.
 

You will have to count each component (tedious, I know) until you find your Beta/Overkill motor. As we can see here, Miles the Marauder's first component is the betaburst so his MotorID is 'MotorID':1, - adjust accordingly to whatever number your component is!
StartAngle - This is where your weapon starts, most of the time it's either math.pi*0.6 or -math.pi*0.6
Reload - This is a unit for how long your weapon takes between firing.
    list.append(("G-funk F","Judge",{'nose':math.pi,'MotorID':38,'StartAngle':-math.pi*0.6,'reload':10,'radius':0.1,'topspeed':1000,'throttle':100,'turn':50,'turnspeed':2,'weapons':(32,)}))
As we can see here, G-Funk's motor was component number 38 so it's MotorID is 38, aside from the two added segments needed for a judge.py bot, the rest is similar to other robots.

FINAL WORDS:
All you need to do to make an AI line work is:
- Make sure it's on a fresh line
- Make sure everything is spelt case sensitive and correctly
- If the game crashes, you've spelt something wrong or removed an important part such as a comma,apostrophe or bracket.
 

I set it up like this simply for consistency...yes I keep the old AI too for reference. So I did some AI testing...
 

Necky didn't self-right with it's head so I'm gonna wire up it's head to the Srimech button (sometimes you have to go back to the Bot Lab to make changes but that's just bot building!) and I'm going to increase it's speed too!
 

Miles is facing the wrong way so I'm going to change his nose to 'nose':math.pi*2, ...
 

He's facing the right way and he fires his weapon pretty quickly thanks to messing with his Reload. I'm gonna alter the AI lines a bit more but this is basically it! Anyone can AI, it's not hard, just fiddly and takes time. Bear in mind that more tournaments might enforce your own AI in the future...I'm looking at it for OW5. With these tutorials you should have no excuse now!

If you have any questions, please ask away and if you think anything needs changing/adding then let me know! Hope this helps!
« Last Edit: August 26, 2020, 06:53:39 PM by TheOrcCorp »
GTM 2017 Awards - Most Unique Bots (shared with DSC) and Most Enthusiastic Member!
GTM 2018 Awards - Friendliest and Kindest/Most Unique Bots/Best Tournament 2018/Best Tournament by Editing/Best Tournament by Matches!
GTM 2019 Awards - Friendliest and Kindest(how)/Favourite Staff Member/Hall of Fame Inductee