Author Topic: AI-ing (.py files, coding, nose-orienting R+D, and help)  (Read 105936 times)

Offline Madiaba

  • *
  • Posts: 1438
  • Reputation: 8
    • View Profile
AI-ing (.py files, coding, nose-orienting R+D, and help)
« on: October 12, 2008, 01:51:26 PM »
This thread is to help facilitate modders/builders to learn how to AI. It's fairly easy if one will just invest some time, so no 'cold feet' necessary.
 
There's been an 'AI Chart' that I started and then sent to CB, and is now with SC, (but he's been busy, NP). I'll finish up his part and send it to Goose for any other final tweaks before it goes out. It will be a simple chart of all available AI.pys kinds (Spinner, Rammer,...); their function(s); bot wiring's zone/control naming.
ANY noob can learn and do it in a short time.
Bindings line functions and tweaking, questions or input, are welcome here too.
(BTW: No inquiries or input is too easy or dumb....)
--------------------------
 
 
So to start:
Here's a new FBS AI.py that I just finished. FBS's are notorious for getting counted out while spinning. This py is very reliable to 'stop and move' when the immobilization countdown starts. It has other User-adjustable settings that you can read about for yourself in the ReadMe included. Stock and DSL.
 
FBS_1]FBS_1
 
[/color]..[/b][/URL]
 
 
 
 
 
                             Bindings.py
-Bot Nose orientaton:
(Copy+paste this coding to the top of your Bindings.py for a convenient reference)
How to use:
1. Find out where your bot is facing in-game (Exhibition), without any nose bias.
2. Then use this chart to turn it to face forward, NP.
 
 
Code: [Select]
    # nose is "front" of bot-
        #Nose paradigm: All 360 rotational degrees for "math.pi" are represented by the factor '2'.
            #thus:  '2'=360degrees,   '1'=180degrees,   '0.5'=90degrees,   '0.25'=45degrees.
        #The direction of change(CW/CCW)is determined by the "-" or "+" before the statement.
            #thus: '+' causes rotation CCW,  '-' causes rotation CW.
        #Format examples:
            # " 'nose':math.pi*0.25 "  will rotate the bot 45degrees/CCW.
            # " 'nose':-math.pi*0.25 " will rotate the bot 45degrees/CW.
            # " 'nose':math.pi*0.5 "   will rotate the bot 90degrees/CCW.
            # " 'nose':-math.pi*0.5 "  will rotate the bot 90degrees/CW.
            # " 'nose':math.pi*0.75 "  will rotate the bot 135degrees/CCW.
            # " 'nose':-math.pi*0.75 " will rotate the bot 135degrees/CW.
            # (Make sure there is a comma(,)after the the value # (to separate it from the next characteristic and its value).
            #(-----notes-----)
                # Note1:  "math.pi"   AND   'nose':math.pi*1.0 "   AND  " 'nose': -math.pi*1.0 "   will rotate the bot 180 degrees.
                    #   (The first two are the same, and the last two just rotate different directions to get 180 degrees.}
                    #   Thus there is no real reason to have a factor greater than '1',
                    #   since after that you just move into the other half of the circle covered by the other '+' or '-' sign.
                # Note2: "math.pi*0" or "math.pi*2" = the same as no new heading.


 
Again, you might copy this to the top of your Bindings.py for easy reference.
« Last Edit: July 20, 2010, 08:06:21 AM by Madiaba »
Input is appreciated. :)
-Arrogance is a quantity devoid of quality...
-As a client once told me "This is my story, and it's sticking to me!"
-Relationships these days are like the 'Arrival' section of the airport: a lot of baggage is being revealed in one place, and not a lot of it is being correlated to its real owners...

Offline Naryar

  • *
  • Posts: 21983
  • Reputation: 19
  • You are already defeated.
    • http://www.youtube.com/us
    • View Profile
  • Skype: TheMightyNaryar
AI-ing (.py files, coding, R+D, and help)
« Reply #1 on: October 12, 2008, 01:59:16 PM »
Starcore done something like that already... and posted it somewhere, with the strengths/weaknesses of all AI's, and it's great.

Anyways this would be welcomed Mad. My ELBITE tabletop bot is decently AIed, but i'm still a beginner (i don't suck at it anymore at least)

Offline Madiaba

  • *
  • Posts: 1438
  • Reputation: 8
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #2 on: October 12, 2008, 02:09:41 PM »
I've not seen and he's not told me of a chart like this; unless he put up the incomplete version?.. which I doubt. This is not a step 1,2,3... on "How to AI" instructions, like on GTM. It's a chart on the necessary AI.py information for choosing the best/appropriate AI.py based upon functioning(s), and then the some information/specs needed to AI it.
I'll put up a snipet later ....
But if you run into it, please let me know...
Input is appreciated. :)
-Arrogance is a quantity devoid of quality...
-As a client once told me "This is my story, and it's sticking to me!"
-Relationships these days are like the 'Arrival' section of the airport: a lot of baggage is being revealed in one place, and not a lot of it is being correlated to its real owners...

Offline infiniteinertia

  • *
  • Posts: 1846
  • Reputation: 5
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #3 on: October 12, 2008, 02:21:29 PM »
This is great for me, because I would like to try and make my own "Relentless.py" and well, at least try...
infiniteinertia

Offline Gigafrost

  • *
  • Posts: 809
  • Reputation: 0
  • You'll never know what I'll think of next.
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #4 on: October 12, 2008, 10:23:01 PM »
Woah, that FBS .py is simular to my RA2GE version for the bot Filmore. Anyway, nice tut.

Offline philetbabe

  • *
  • Posts: 510
  • Reputation: 2
  • Drop D
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #5 on: November 13, 2008, 06:00:08 AM »
i wonder how to AI those servo motor and servo piston.

About servo piston,  it is possible to define 2 custom zone and to move (extend/retact) the piston depending of the position of the ennemy (see schema).
sample code :

  def __init__(self, **args):
        AI.SuperAI.__init__(self, **args)
               
        self.zone = "weapon"
        self.triggers = ["Fire"]
        #self.trigger2 = ["Srimech"]
        self.reloadTime = 0
        self.reloadDelay = 3    
        self.spin_range = 3.0
        # declare  zone and associated triggers
        self.zone2 = "zone1"
        self.triggers2 = ["Action1"]
        self.zone3 = "zone2"
        self.triggers3 = ["Action2"]
        self.zone4 = "zone3"
        self.triggers4 = ["Action3"]
        self.zone5 = "zone4"
        self.triggers5 = ["Action4"]
       
...
  def SmartZoneEvent(self, direction, id, robot, chassis):
        if id == 1:
            if direction == 1:
                AI.SuperAI.SmartZoneEvent(self, direction, id, robot, chassis)
        elif id == 2:
            if robot > 0:
                if direction == 1:
                    for trigger in self.triggers2: self.Input(trigger, 0, 2)
        elif id == 3:
            if robot > 0:
                if direction == 1:
                    for trigger in self.triggers3: self.Input(trigger, 0, 3)
        elif id == 4:
            if robot > 0:
                if direction == 1:
...



But i can't figure how to do it with a servo motor :
 - i can not attach custom zone to extender : If i could, it should be faisable to tell the servo motor to turn until the ennemy is in its attached custom zone( for the custom zone will be turned by the motor).
- an other way should be to know the current position of the servo motor (angle of turn) and to make it turning,  depending of the position of the ennemy. Here again i don't know how to do that.

=========
looking at beetlebros cheatcode, it appears that one can iterate on the components. But how do i identify on (by its name ?), what are the property associated with the components ?

def turbo(id=0):
...
    for comp in range(100):
        damage(id, comp, -500, getLocation(id))
========

Does anyone have any successful experience in this domain ?
« Last Edit: November 25, 2008, 03:11:08 AM by philetbabe »

Offline Madiaba

  • *
  • Posts: 1438
  • Reputation: 8
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #6 on: November 13, 2008, 09:35:33 AM »
Attaching Smart Zones to (moving) components. I like your ideas, Phil. As far as controlling motors/weapons through attaching SZs, some of us worked through this before. Here's a few pics of initial ideas about this I posted (that someone saved before the old forum went down):
 

 
Then a better idea came:

 
Here is the whole dialogue's txt, if you wantto look through it (don't think the hyperlinks in it work any more):
AttachingSZsToComponents]AttachingSZsToComponents[/URL]

 
PM me, Phil, and I'll share with you how to connect SZs to moving components.
 
---------------------
Controlling piston:
Controlling pistons is not consistent, but it can be done. Here's the basic coding for such:
#---------THESE SERVO CONTROLS "WORK" (with 2 BUTTON trigger switches, 1 for each pos/neg input).
# SERVO CONTROL-1 - "Timer" (WORKS with 2 Buttons controling retract/extend. Reads this py's trigger NUMBER [i.e. "self.triggers1"])

self.TriggerTimer1 += 1
if self.TriggerTimer1 == 1:
for trigger in self.triggers1: self.Input(trigger, 0, 1) # Extend
if self.TriggerTimer1 == 5:
for trigger in self.triggers1: self.Input(trigger, 0, 0) # Off
if self.TriggerTimer1 == 6:
for trigger in self.triggers2: self.Input(trigger, 0, -1) # Retract
if self.TriggerTimer1 == 10:
for trigger in self.triggers2: self.Input(trigger, 0, 0) # Off
if self.TriggerTimer1 == 15: # For repeating above
self.TriggerTimer1 = 0
 
# SERVO CONTROL-2 -"Timer" (WORKS with 2 Buttons controling retract/extend. Reads in this py's = trigger NAME (which in-game is a controller Button 'Name').

self.TriggerTimer1 += 1
if self.TriggerTimer1 == 10:
self.Input("Fire1", 0, 1)
if self.TriggerTimer1 == 15:
self.Input("Fire1", 0, 0)
if self.TriggerTimer1 == 20:
self.Input("Fire2", 0, 2)
if self.TriggerTimer1 == 25:
self.Input("Fire2", 0, 0)
if self.TriggerTimer1 == 30:
self.TriggerTimer1 = 0
 
 
 
Finding Piston location:
#--- Get Piston Position -------- (parameters are around '0', unto between '-.2' and '-.6' [depending on length of shaft]).
self.GetPistonPosition(13) # '13' is piston component number.
# Example:
def Tick(self):
self.PistonShaftLocation = self.GetPistonPosition(13)
if self.PistonShaftLocation < -.35:
plus.playSound(self.EMFsound) # or whatever command...
 
---------------------
 
 
Finding Servo Motor Angles(Apanx work):
# component Motor-number set from Bindings. Must add (1) in AI.py under __init__: if 'motor' in args: self.Motor = args['motor'] ; and (2) in Bindings.py: 'motor':19, . Or you can just enter the component number yourself: servoangle = self.GetMotorAngle(19).
 
def __init__(self):
self.Motor = 1
if 'motor' in args: self.Motor = args['motor']
 
def Tick(self):
servoangle = self.GetMotorAngle(self.Motor)

 
Controlling Servo Motors:
 
def __init__(self):
self.Motor = 1
if 'motor' in args: self.Motor = args['motor']
 
def Tick(self):
servoangle = self.GetMotorAngle(self.Motor)
 
# Basic servo control
if servoangle < 1: self.Input("BAF", 0, -100)
elif servoangle > 2: self.Input("BAF", 0, 100)
 
# Open, then cycle within parameters (<1 and >2)
self.weptimerB += 1
if self.weptimerB == 1:
if servoangle == 0: self.Input("BAF", 0, -100)
if servoangle < 1: self.Input("BAF", 0, -100)
elif servoangle > 2: self.Input("BAF", 0, 100)
 
# Timed + Limited open, then cycle within parameters (between <1 and >2)
self.weptimerB += 1
if self.weptimerB == 1:
if servoangle < 0.5: self.Input("BAF", 0, -100)
if self.weptimerB > 1:
if servoangle > 2: self.Input("BAF", 0, 0)
if self.weptimerB >= 20:
if servoangle < 1: self.Input("BAF", 0, -100)
elif servoangle > 2: self.Input("BAF", 0, 100)
 

--------------------
If you want to look through all my Python notes(partially organized):
PYTHON SCRIPTS]PYTHON SCRIPTS[/URL][/B]....[/COLOR]
 
...
« Last Edit: November 13, 2008, 06:38:48 PM by Madiaba »
Input is appreciated. :)
-Arrogance is a quantity devoid of quality...
-As a client once told me "This is my story, and it's sticking to me!"
-Relationships these days are like the 'Arrival' section of the airport: a lot of baggage is being revealed in one place, and not a lot of it is being correlated to its real owners...

Offline philetbabe

  • *
  • Posts: 510
  • Reputation: 2
  • Drop D
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #7 on: November 13, 2008, 09:44:02 AM »
Quote from: Madiaba;21440
Attaching Smart Zones ...

quick and smart !

 i read all of this, try some solution, and give you feed back ... or another question.

And there it goes :

What i do not understand is
"
self.Motor = 1
...
servoangle = self.GetMotorAngle(self.Motor)..."

In the first line i declare the Identifier of a motor as '1'
in the second line i ask for the motor angle of the motor  which identifier is '1'.

but, how the system can link the number '1' with my servo motor if my bot have other motors (servo or not) ?

PS : i have not tested this code yet. this is just a 'code reading' question.
« Last Edit: November 13, 2008, 11:04:36 AM by philetbabe »

Offline Madiaba

  • *
  • Posts: 1438
  • Reputation: 8
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #8 on: November 13, 2008, 06:31:51 PM »
Phil, the first
def __init__(self):
....self.Motor = 1
is just a variable with an integer given to it as a default value.
 
The second line is just to retreive an arg(specific parameter) from the Bindings.py, if one is present. Thus it is coded conditionally:
....if 'motor' in args: self.Motor = args['motor']
meaning that if there is some info in the Bindings.py line called 'motor', then assign this number to self.Motor instead of '1' (the default). That's why the conditional statement is placed after the default setting.
 
def __init__(self):
....self.Motor = 1
....if 'motor' in args: self.Motor=args['motor']
 
def Tick(self):
....servoangle = self.GetMotorAngle(self.Motor)
 
 
------------------
The syntax in the Bindings line will be:
 
......., 'throttle':80, 'range':4, 'motor':2, 'weapons':........
 
where '2' is the component sequential assembly number. Use Apanx's Exporter to find the motor's number, and add it here.
 
 
....
Input is appreciated. :)
-Arrogance is a quantity devoid of quality...
-As a client once told me "This is my story, and it's sticking to me!"
-Relationships these days are like the 'Arrival' section of the airport: a lot of baggage is being revealed in one place, and not a lot of it is being correlated to its real owners...

Offline philetbabe

  • *
  • Posts: 510
  • Reputation: 2
  • Drop D
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #9 on: November 14, 2008, 01:10:55 AM »
Quote from: Madiaba;21539

where '2' is the component sequential assembly number. Use Apanx's Exporter to find the motor's number, and add it here.

My question was mis-formulated : it should have been : how do i know the value of 'motor';

you gave me the answer, thank's.

==== still working on====
your source code is very useful :
i think, to know the component sequential assembly number, i will try to iterate on the components.
that will simplify the task for the futur users of the AI.
 They wouldn't have to 'hack'  the gmf.

here is a 'principe' code to put on the 'activate' function:

  for i in range(0, self.GetNumComponents()):
                test if self.GetComponentType(i) == 'ServoMotor"
                if ok -> memorize i, than break.

now i have to try it.
« Last Edit: November 14, 2008, 09:18:50 AM by philetbabe »

Offline philetbabe

  • *
  • Posts: 510
  • Reputation: 2
  • Drop D
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #10 on: November 14, 2008, 03:49:56 PM »
double post :-(

Well, i'm near my goal : make a simple AI that may use servo motor to direct the weapon in the 'good direction'. given that the 'good direction' is defined with 2 custom zones.

what i have still to do :
1/ finalize the AI (little problems to stop the servo when itovercomes their 'min angle' if this one is 0)
2/ make a guide to use it
3/ make 3 tutorial bot HS, VS, Poker/rammer to show the potential use of this AI.
4/ give all of this in this thread.

By the way, i effectively search the motor number  by iterating on the components, so the futur user of this AI will not have to use a gmf decompiler.

« Last Edit: November 25, 2008, 03:09:01 AM by philetbabe »

Offline philetbabe

  • *
  • Posts: 510
  • Reputation: 2
  • Drop D
    • View Profile
SpinServo AI
« Reply #11 on: November 18, 2008, 06:32:09 AM »
Triple post :-( :-(

HERE is the SpinServo AI
https://gametechmods.com/uploads/files/ServoSpin.rar

This is an AI which control 1 servo motor.

the archive contains a file.rtf which explains how to use it.

hope your enjoy.
Also hope you may contribuate to improve it.

EDITED : I forgot to tell it in the help file : the sample bots are DSL2.1 bot !

===============
futur AI to work on ;
-propose a 'standard' AI that works with up to 4 multi zone (really easy -> topknot does it, it is just a matter of 'standardisation')
-propose a 'radar like' AI : more complex. so be patient.

Offline Sage

  • *
  • Posts: 6031
  • Reputation: 10
  • RA2 Wizard & GTM's Favorite Stock Builder 2015
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #12 on: November 18, 2008, 06:45:34 AM »
looks cool, and effective. Nice work.
You got my vote for RA2 Wizard. Always and forever.

Offline Madiaba

  • *
  • Posts: 1438
  • Reputation: 8
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #13 on: November 18, 2008, 08:36:59 AM »
Nice work, Phil.  Allot of this has been done already,... but I like the 'goon' to find the servo.  So to save you from dupping work, look at this AI.py that I wrote specifically for ACAMS Machine-gun mounted atop a self-aiming servo motor, and also has automatic repeating fire.
https://gametechmods.com/uploads/files/D_SMFE_Turret_Machinegun_Spin.rar

I'll PM you about the bot details...

Please give feedback, and any ideas for improvement.
Input is appreciated. :)
-Arrogance is a quantity devoid of quality...
-As a client once told me "This is my story, and it's sticking to me!"
-Relationships these days are like the 'Arrival' section of the airport: a lot of baggage is being revealed in one place, and not a lot of it is being correlated to its real owners...

Offline philetbabe

  • *
  • Posts: 510
  • Reputation: 2
  • Drop D
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #14 on: November 18, 2008, 09:06:06 AM »
Quote from: Madiaba;22175
Nice work, Phil.

thanks.
Quote from: Madiaba;22175
 So to save you from dupping work, look at this AI.py that I wrote specifically for ACAMS Machine-gun mounted atop a self-aiming servo motor, and also has automatic repeating fire


after a quick look, it seems this code will be very useful for a generic radar-system-like AI. All it there yet with the Tick, AimTowards and Aim function.

by the way, i feel you have a big amount of AI code on your drawers, please, share them.
« Last Edit: November 18, 2008, 09:28:42 AM by philetbabe »

Offline 70 CUDA

  • *
  • Posts: 757
  • Reputation: 2
  • Epic skulls= Epic win
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #15 on: November 18, 2008, 02:39:14 PM »
be carefull what you ask for you WILL Get it lol. nice job man i got one to like that before i left but it was not as good.
Holy crap they do exist!!!! :Rob2

Offline philetbabe

  • *
  • Posts: 510
  • Reputation: 2
  • Drop D
    • View Profile
Laser Guided AI
« Reply #16 on: November 24, 2008, 03:22:03 PM »
Big name for little AI !
https://gametechmods.com/uploads/files/tazbot.rar

this is a variant of 'SpinServo AI'. it is  based on Madiaba work.

Here the servo must spin horizontaly only, but you may attach it a spin motor or a fired weapon (piston). In both case, no need of custom zone.

Sample shows  TazBot from DSL 2.1

Fixed : the AI seems to crash the game when the bot is inverted !
« Last Edit: February 12, 2009, 06:56:06 AM by philetbabe »

Offline System32

  • *
  • Posts: 4427
  • Reputation: 4
  • Reality
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #17 on: November 24, 2008, 03:33:38 PM »
Hey, that would make for a cool bot!
Put this onto your signature if you were part of this crappy fad in '03.

Offline philetbabe

  • *
  • Posts: 510
  • Reputation: 2
  • Drop D
    • View Profile
information on binding.py and the Weapon list
« Reply #18 on: December 04, 2008, 06:28:12 AM »
So, what are these numbers in the weapons list contained in binding.py  ?
Code: [Select]
...,'weapons':(1,2,3,4,5,6,7,8,9)}))
This numbers are assumed to be the Identifier of your weapons.
Each time you lost one, it is removed from this list.
By default, when this list is empty the strategy is changed.

This mean
* if your  list is empty, whatever your AI is, the strategy used should be the
one define in 'LostComponent' function.
* if you put number that do not correspond to Weapon Identifier (which is mostly the case if your write 1,2,3,...) you will keep your strategy even if you loose all your weapons for this list will never be empty

Usage of this list :
* to be sure that your list contains the good weapons identifier, you may fill it yourself after having a look at yotur bot with a gmf decompiler. You may also add this code to your activate function, it build a correct list of weapons Id :
Code: [Select]
   def Activate(self, active):
        if active:
              ...
            goon = 1
            i = 0
            self.weapons = []
            while goon == 1:
                if i  == self.GetNumComponents(): break # to verifiy if  i == ... or  i > ...
                currentType =  self.GetComponentType(i)
                if currentType == "Weapon": self.weapons.append (i)
                i = i+ 1
return AI.SuperAI.Activate(self, active)

For instance, here is an usage of this list :
Code: [Select]
   def __init__(self, **args):
        AI.SuperAI.__init__(self, **args)
        self.SpinTrigger = "Spin"
        self.ServoTrigger = "Servo"
         ...

    def LostComponent(self, id):
        # if we lose all our weapons, stop using the Engage tactic and switch to Shove
        if id in self.weapons: self.weapons.remove(id)
       
        if len(self.weapons) < 4 :
   # i have 2 motors mounted on a tri-bar extender.
# the last bar contains a hammer.
# my self.weapons list contains the Id of the weapons.
# when  only 3 weapons remains, i swith my controler
# to make my servomotor spin much like a normal motor
                        # so the AI that controls the servo become useless
                        # my bot turn to a 'normal spinner'
            self.SpinTrigger = "Servo"
            self.ServoTrigger = "NOP" # does nothing
            self.SpinSpeed =  100
           
        return AI.SuperAI.LostComponent(self, id)

Fields of investigation : does the lostcomponent function is called for each component lost or only for weapons ? What happens if one put Id of motors or other components in its self.weapons list ?
« Last Edit: December 04, 2008, 06:57:48 AM by philetbabe »

Offline Madiaba

  • *
  • Posts: 1438
  • Reputation: 8
    • View Profile
AI-ing (.py files, coding, R+D, and help)
« Reply #19 on: December 04, 2008, 07:51:03 AM »
Quote
Fields of investigation : does the lostcomponent function is called for each component lost or only for weapons ? What happens if one put Id of motors or other components in its self.weapons list ?
I've used lostcomponent function for SRMs, meaning that if it lost it's vertical pole it would try to fire the weapons to self-right. I also did the same for lost armor, changing instead to an basic/crude 'evasive' strategy I wrote.
I would imagine that motors are the same, but not tried it.
Input is appreciated. :)
-Arrogance is a quantity devoid of quality...
-As a client once told me "This is my story, and it's sticking to me!"
-Relationships these days are like the 'Arrival' section of the airport: a lot of baggage is being revealed in one place, and not a lot of it is being correlated to its real owners...