Author Topic: Need some help with new rammer AI.  (Read 1016 times)

Offline Clickbeetle

  • *
  • Posts: 3374
  • Rep: 21
  • In Soviet Russia, bugs stomp YOU!
  • Awards BOTM Winner
    • View Profile
    • Beetle Bros site
    • Awards
Need some help with new rammer AI.
« on: January 08, 2010, 03:46:36 PM »
Well not quite with the AI itself, but with some extra features I want to put in.


The AI is done and working properly.  What it does: if the bot is within 6 meters of the opponent and is moving slower than a certain threshold speed (default 3), the AI attempts to drive away for another ram.  If the bot is facing the opponent, it backs up; if it is facing away from the opponent, it drives forward; and if the opponent is on its flank, it turns to face the opponent and then backs up.  If it can't get away (there is an obstacle in its path) it will face the opponent and push back.  While the AI is driving away, it is constantly checking for clear paths in front of and behind it.  It will continue to drive away from the opponent until it either detects an obstacle in its path or it is a certain distance away from the opponent.  At that point it will charge the opponent again.


How it's different from the previous rammer AI:
-Better hazard avoidance.  The obstacle c all but ensure the AI won't run into walls or hazards while backing up.
-The AI will usually run away first and then turn to face the opponent for a ram.  The only case in which it tries to turn first is if the enemy is exactly to the side.
-The point at which the AI will stop backing up and charge the opponent is based on distance/presence of obstacles rather than a timer.  The result is usually greater distances over which a ram is performed.  Most bots will back up the length of the Combat Arena, stop just before hitting the wall, and then do a boxlong charge.
-Because bots tend to back up a longer distance, the new AI doesn't work as well for bots that don't drive straight in reverse.  For that reason I am keeping the old Rammer AI as another option.  However, it works excellently for bots that do drive straight in reverse.


So here's what I need help with.  I want to make the threshold speed for "run away" activation customizable in Bindings.py.  I also want to make the AI's sight range for obstacle detection customizable in Bindings, because a fast bot will need a longer sight range than a slow bot.


However, I can't figure out a way to call variables from Tactics.py in Rammer.py to make them customizable.  I also tried putting the customization code in Tactics (if self.blah in args:...) but that just made the game crash.  My question is, is there any way to make variables in Tactics.py customizable in Bindings.py?


If there isn't, I can always move the new code into Rammer.py, but it would be more convenient to leave it in Tactics so it can be called by other py's like OmniRam and whatnot.

To lack feeling is to be dead, but to act on every feeling is to be a child.
-Brandon Sanderson, The Way of Kings

Offline Jack Daniels

  • *
  • Posts: 2719
  • Rep: 9
  • Losing Tournaments with Style
    • matt.morrill.12
  • Awards BOTM Winner
    • View Profile
    • My abandoned online RPG project.
    • Awards
Re: Need some help with new rammer AI.
« Reply #1 on: January 08, 2010, 04:01:36 PM »
*opens door*

*rolls out red carpet for Trovaner or Madiaba's grand entrace*

Hopefully our celebrities will be here soon.

Offline Trovaner

  • *
  • Posts: 1222
  • Rep: 32
    • View Profile
    • Awards
Re: Need some help with new rammer AI.
« Reply #2 on: January 08, 2010, 08:44:00 PM »
Assuming that you want to name them runspeed and lookahead...
Code: [Select]
    def __init__(self, ai):
        list = [x for x in AI.ai_bindings if x[0] == self.ai.botName]
        self.runspeed = list[0][2]['runspeed']
        self.lookahead = list[0][2]['lookahead']

Offline Clickbeetle

  • *
  • Posts: 3374
  • Rep: 21
  • In Soviet Russia, bugs stomp YOU!
  • Awards BOTM Winner
    • View Profile
    • Beetle Bros site
    • Awards
Re: Need some help with new rammer AI.
« Reply #3 on: January 08, 2010, 08:57:38 PM »
And this goes in Tactics I'm guessing?

Thanks!  I'll go try it out...

To lack feeling is to be dead, but to act on every feeling is to be a child.
-Brandon Sanderson, The Way of Kings

Offline Trovaner

  • *
  • Posts: 1222
  • Rep: 32
    • View Profile
    • Awards
Re: Need some help with new rammer AI.
« Reply #4 on: January 08, 2010, 09:16:36 PM »
After looking at the coding again, I think you may also want to add something so that it will use default values when 'runspeed' and/or 'lookahead' are not in the bindings.


Edit: Something like this...
Code: [Select]

    def __init__(self, ai):
        list = [x for x in AI.ai_bindings if x[0] == self.ai.botName]
        self.runspeed = list[0][2].get('runspeed')
        if self.runspeed == None: self.runspeed = 15
        self.lookahead = list[0][2].get('lookahead')
        if self.lookahead == None: self.lookahead = 10