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

Offline Somebody

  • *
  • Posts: 7201
  • Rep: 13
  • CP: +2
    • View Profile
    • Awards
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #720 on: July 24, 2010, 05:11:26 PM »
Make sure the bot names are exact.
I built that big robot on that TV show that time


Offline Naryar

  • Posts: 23278
  • Rep: 20
  • hybrids oui oui
    • http://www.youtube.com/us
  • Awards BOTM Winner
    • View Profile
    • Awards
  • Skype: TheMightyNaryar
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #721 on: August 14, 2010, 12:25:32 PM »
I tried to improve Joey's THZ.py, notably by adding popup code and something that retracts the arm to backwards position when no bot is into the smartzone (that Frenzy.py critically misses)

But did it wrong (no surprise here):
Code: [Select]
from __future__ import generators
import plus
import AI
from AI import vector3
import Arenas
import Gooey
import math
import Tactics

class THZPlus(AI.SuperAI):
    "Frenzy strategy + FBS immobility management. Also backs up weapon when not in use and uses NoChassisTime variable like Popup.py"
#Original Frenzy.py improved by JoeBlo, re-improved by Naryar
    name = "THZPlus"

    def __init__(self, **args):
        AI.SuperAI.__init__(self, **args)
               
        self.zone = "whipzone"
               
        self.tactics.append(Tactics.Engage(self))
       
        self.whipTimer = 0
        self.whipDir = 1
        self.whipDirCount = 4
        self.botinzone = 0
        self.compinzone = 0
        self.comptimer = 0
        self.NoChassisTime = 8
self.canFire = 0
        self.ImmobileCounter = 0
        self.ThisAI_bImmobile = 0
        self.BU_ImmobileTimer_A = 0       
        self.BU_ImmobileTimer_B = 0
        self.ReMobilizeRoutineTime = 40
        self.ThisAIBot_XFactorA = 0
        self.ThisAIBot_ZFactorA = 0
        self.ThisAIBot_XFactorB = 0
        self.ThisAIBot_ZFactorB = 0
       
        self.whipFunction = self.WhipBackAndForth
       
        if 'zone' in args: self.zone = args['zone']
       
        if 'whip' in args:
            if args['whip'] !=  "around": self.whipFunction = self.WhipBackAndForth
        if 'NoChassisTime' in args: self.NoChassisTime = args.get('NoChassisTime') * 4
       
    def Activate(self, active):
        if active:
            if AI.SuperAI.debugging:
                self.debug = Gooey.Plain("watch", 0, 75, 100, 75)
                tbox = self.debug.addText("line0", 0, 0, 100, 15)
                tbox.setText("Throttle")
                tbox = self.debug.addText("line1", 0, 15, 100, 15)
                tbox.setText("Turning")
                tbox = self.debug.addText("line2", 0, 30, 100, 15)
                tbox.setText("")
                tbox = self.debug.addText("line3", 0, 45, 100, 15)
                tbox.setText("")
           
            self.RegisterSmartZone(self.zone, 1)
        else:
            # get rid of reference to self
            self.whipFunction = None
           
        return AI.SuperAI.Activate(self, active)

    def Tick(self):
        # fire weapon
        targets = []
       
        if self.weapons:
            targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \
                and not plus.isDefeated(x.robot)]
        if self.compinzone == 1 and self.botinzone == 0:
            self.comptimer += 1
           
        if self.botinzone == 1:
            self.comptimer = 0
           
        if self.weapons and (self.botinzone == 1 or (self.comptimer >= self.NoChassisTime and self.compinzone == 1)):
            canFire = 1
else:
    canFire = 0


        bReturn = AI.SuperAI.Tick(self)
    # call this now so it takes place after other driving commands
        if self.whipFunction and self.ThisAI_bImmobile == 0: self.whipFunction(len(targets) > 0)

        if self.ThisAI_bImmobile == 1: # If Immobility is on:  -------------------------------------
            self.ImmobileCounter += 1  # Then start counting....
           
            if self.ImmobileCounter >= self.ReMobilizeRoutineTime*0.2:   # go backward for a designated time.   
                self.Throttle(100)
                self.Input("LeftRight", 0, 0)
                self.Input("Forward", 0, -100)
           
            if self.ImmobileCounter >= self.ReMobilizeRoutineTime*0.6:  # go forward for a designated time.   
                self.Input("LeftRight", 0, 0)
                self.Throttle(100)
                self.Input("Forward", 0, 100)

            if self.ImmobileCounter >= self.ReMobilizeRoutineTime:  # Reset everything:   
                self.ThisAI_bImmobile = 0 # default Reset (if timer goes too long).
                self.ImmobileCounter = 1
        else:
            self.ThisAI_bImmobile = 0
            self.ImmobileCounter = 0     



        # BackUp Immobile routine (continually running).... calculate difference of position between 2 calls
        self.BU_ImmobileTimer_A +=1       
        if self.BU_ImmobileTimer_A >= 1:       
            self.ThisAIBot_XFactorA =  plus.getLocation(self.GetID())[0] #
            self.ThisAIBot_ZFactorA =  plus.getLocation(self.GetID())[2]
        if self.BU_ImmobileTimer_A == 16:       
            self.ThisAIBot_XFactorB =  plus.getLocation(self.GetID())[0]
            self.ThisAIBot_ZFactorB =  plus.getLocation(self.GetID())[2]
            self.BU_ImmobileTimer_A = 0 # Reset.       

        if   self.ThisAIBot_XFactorA > self.ThisAIBot_XFactorB - .07 and   self.ThisAIBot_XFactorA < self.ThisAIBot_XFactorB + .07 and    self.ThisAIBot_ZFactorA > self.ThisAIBot_ZFactorB - .07 and   self.ThisAIBot_ZFactorA < self.ThisAIBot_ZFactorB + .07:
            self.BU_ImmobileTimer_B +=1       
            if self.BU_ImmobileTimer_B ==50:       
                self.ThisAI_bImmobile = 1
                self.BU_ImmobileTimer_B = 0
        else:
            self.BU_ImmobileTimer_B = 0 # Reset
       
        return bReturn
       
    def InvertHandler(self):
        # fire weapon once per second (until we're upright!)
        while 1:
            if self.whipDir > 0:
                self.Input("Hammer", 0, -1000)
            else:
                self.Input("Hammer", 0, 1000)

            self.whipDirCount -= 1
            if self.whipDirCount < 0:
                self.whipDirCount = 4
                self.whipDir = -self.whipDir
           
            self.whipTimer -= 1
           
            for i in range(0, 8):
                yield 0

    def WhipBackAndForth(self, bTarget):
        if bTarget and canFire = 1: self.whipTimer = 8
       
        if self.whipTimer > 0:
            # Whip back and forth!
            if self.whipDir > 0:
                self.Input("Hammer", 0, -100)
            else:
                self.Input("Hammer", 0, 100)
            self.Throttle(0)
           
            self.whipDirCount -= 1
            if self.whipDirCount < 0:
                self.whipDirCount = 4
                self.whipDir = -self.whipDir
           
            self.whipTimer -= 1

if self.whipTimer = 0:
            self.Input("Hammer", 0, -100)

    def WhipAround(self, bTarget):
        if bTarget: self.whipTimer = 4
        elif self.whipTimer == 0: self.whipDir = -self.whipDir
       
        if self.whipTimer > 0:
            # Whip around!
            if self.whipDir > 0: self.Turn(0)
            else: self.Turn(0)
            self.Throttle(0)
           
            self.whipTimer -= 1
           
    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 not self.weapons:
            tactic = [x for x in self.tactics if x.name == "Engage"]
            if len(tactic) > 0:
                self.tactics.remove(tactic[0])
               
                self.tactics.append(Tactics.Shove(self))
                self.tactics.append(Tactics.Charge(self))
           
        return AI.SuperAI.LostComponent(self, id)
           
    def DebugString(self, id, string):
        if self.debug:
            if id == 0: self.debug.get("line0").setText(string)
            elif id == 1: self.debug.get("line1").setText(string)
            elif id == 2: self.debug.get("line2").setText(string)
            elif id == 3: self.debug.get("line3").setText(string)

    def ImmobilityWarning(self, id, on): # keep track of our own immobility warning
        if on and  id == 0 or id == 1 or id == 2 or id == 3:
            if  id == self.GetID():               
                self.ThisAI_bImmobile = 1

        if self.ImmobileCounter == 0:  # ID protector(Keeps other bots from changing "self.ThisAI_bImmobile = 1", until it runs its course of 'freeing' this AI.
            if not id == self.GetID():
                self.ThisAI_bImmobile = 0


AI.register(THZPlus)

Any help ?

Offline Trovaner

  • *
  • Posts: 1222
  • Rep: 32
    • View Profile
    • Awards
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #722 on: August 14, 2010, 07:56:58 PM »
I'm away from my main computer so I can't test but it looks like you have a problem at line 29. It needs 8 spaces instead 4 before 'self.canFire'.

Offline JoeBlo

Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #723 on: August 14, 2010, 10:48:01 PM »
the retraction thing is to do with the whip back and forth section


infact IIRC a robot is start point 2 will retract the hammer backwards


I have been meaning to do stuff like that ^^^ (I have a few new versions of an unreleased THZ.py) but I got distracted making an effective strafe AI

Offline G.K.

  • *
  • Posts: 12156
  • Rep: 10
  • Striving for a good personal text since 1994.
    • View Profile
    • Awards
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #724 on: September 30, 2010, 11:41:21 AM »
Which direction is Clockwise on FBSPlus?
My above post explains everything about everything.

Host of: Wheely Tag, Back To The Beginnings, BTTB 2, BTTB 3, BTTB 4, & BTTB V.

Heavy Metal: Champion (Mockery of the Whole Concept)
Robotic International Wars Series 1: Champion (Minifridge 6)
RA2 Team Championships 1 & 2: Champion (High Speed Train & Upthrust - as part of Naryar's Not Quite Evil Council of Doom)

Runner Up in: The Amazing Rage (Team Fedex), R0B0NOVA (Zaphod Stock), Steel Warzone (Inception of Instability), Box of Nightmares (Gicquel), Wheely Tag (Minifridge the Second)

Clash Cubes IV: 5th place (Fretless)
BBEANS 6: Rumble Winner & 6th Place (Minifridge 4)

Offline Naryar

  • Posts: 23278
  • Rep: 20
  • hybrids oui oui
    • http://www.youtube.com/us
  • Awards BOTM Winner
    • View Profile
    • Awards
  • Skype: TheMightyNaryar
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #725 on: September 30, 2010, 11:42:48 AM »
Which direction is Clockwise on FBSPlus?

1

FYI you can check this in the python.

Offline G.K.

  • *
  • Posts: 12156
  • Rep: 10
  • Striving for a good personal text since 1994.
    • View Profile
    • Awards
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #726 on: September 30, 2010, 11:49:30 AM »
Cheers.
My above post explains everything about everything.

Host of: Wheely Tag, Back To The Beginnings, BTTB 2, BTTB 3, BTTB 4, & BTTB V.

Heavy Metal: Champion (Mockery of the Whole Concept)
Robotic International Wars Series 1: Champion (Minifridge 6)
RA2 Team Championships 1 & 2: Champion (High Speed Train & Upthrust - as part of Naryar's Not Quite Evil Council of Doom)

Runner Up in: The Amazing Rage (Team Fedex), R0B0NOVA (Zaphod Stock), Steel Warzone (Inception of Instability), Box of Nightmares (Gicquel), Wheely Tag (Minifridge the Second)

Clash Cubes IV: 5th place (Fretless)
BBEANS 6: Rumble Winner & 6th Place (Minifridge 4)

Offline Badnik96

  • tired of your shit
  • *
  • Posts: 17536
  • Rep: 3
  • Awards BOTM Winner
    • View Profile
    • Awards
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #727 on: October 02, 2010, 12:13:31 PM »

What nose.math should I use for this heading?

Offline JoeBlo

Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #728 on: October 02, 2010, 12:22:35 PM »
umm off the top of my head

-math.pi/2


Offline Gazea2

  • Ultra Heavyweight
  • Posts: 3670
  • Rep: 9
  • the one and only
    • View Profile
    • Awards
  • Skype: gazea2
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #729 on: October 31, 2010, 08:51:40 AM »
In my bot's bindings, ,'nose':math.pi makes it face backwards so, what would I need to change it to to make it face forwards?

EDIT: I got it to work. I have one last question. How do you add a srimech? My brain is failing me.


Offline Naryar

  • Posts: 23278
  • Rep: 20
  • hybrids oui oui
    • http://www.youtube.com/us
  • Awards BOTM Winner
    • View Profile
    • Awards
  • Skype: TheMightyNaryar
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #730 on: October 31, 2010, 09:04:52 AM »
Remove the nose value, or put 'nose':0, or 'nose': math.pi*2. Or any multiple of 2 really.

Offline Gazea2

  • Ultra Heavyweight
  • Posts: 3670
  • Rep: 9
  • the one and only
    • View Profile
    • Awards
  • Skype: gazea2
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #731 on: October 31, 2010, 09:05:59 AM »
I managed to do it just before you posted. :P

I have one last question. How do you add a srimech? My brain is failing me.

Could you help me with this? My bot is a popup if it helps.


Offline Naryar

  • Posts: 23278
  • Rep: 20
  • hybrids oui oui
    • http://www.youtube.com/us
  • Awards BOTM Winner
    • View Profile
    • Awards
  • Skype: TheMightyNaryar
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #732 on: October 31, 2010, 09:06:37 AM »
Add a button named "srimech" to the bots you want

Offline Gazea2

  • Ultra Heavyweight
  • Posts: 3670
  • Rep: 9
  • the one and only
    • View Profile
    • Awards
  • Skype: gazea2
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #733 on: October 31, 2010, 09:08:24 AM »
And then I need to add "invertible: false" to the bindings?


Offline Naryar

  • Posts: 23278
  • Rep: 20
  • hybrids oui oui
    • http://www.youtube.com/us
  • Awards BOTM Winner
    • View Profile
    • Awards
  • Skype: TheMightyNaryar
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #734 on: October 31, 2010, 09:19:05 AM »
You don't need it, but what you need in simple AIs is the bot NOT being considered as invertible by the game. If it has no "invertible : True" in the bindings it's fine.

Offline JoeBlo

Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #735 on: October 31, 2010, 09:34:14 AM »
IIRC it will ignore the srimech control if told "invertible : True"

"invertible : False" is the exact same as having nothing at all, so just delete the "invertible : True" part if its not needed

Offline Gazea2

  • Ultra Heavyweight
  • Posts: 3670
  • Rep: 9
  • the one and only
    • View Profile
    • Awards
  • Skype: gazea2
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #736 on: October 31, 2010, 09:37:29 AM »
Ok, thanks. For some reason I forgot how to do it. >_>


Offline Stagfish

  • Ultra Heavyweight
  • Posts: 2963
  • Rep: 0
    • View Profile
    • Awards
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #737 on: November 07, 2010, 01:36:48 PM »
Can someone give me a download link for OmniMultiZone?

I asked this before but no one listened :(

Offline Badnik96

  • tired of your shit
  • *
  • Posts: 17536
  • Rep: 3
  • Awards BOTM Winner
    • View Profile
    • Awards
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #738 on: November 07, 2010, 01:44:06 PM »
Doesn't it come with DSL?

If it doesn't then it comes with NAR AI.

Offline Stagfish

  • Ultra Heavyweight
  • Posts: 2963
  • Rep: 0
    • View Profile
    • Awards
Re: AI-ing (.py files, coding, nose-orienting R+D, and help)
« Reply #739 on: November 07, 2010, 01:45:59 PM »
I cant download from rapidshare or megaupload so I cant get it from NAR ai and it isnt in DSL