Author Topic: Is combining OmniInverted and Popup .py possible.  (Read 1007 times)

Offline 123savethewhales

  • *
  • Posts: 2923
  • Rep: 30
  • Friendship is Magic
  • Awards BOTM Winner
    • View Profile
    • Awards
Is combining OmniInverted and Popup .py possible.
« on: November 04, 2012, 11:25:12 AM »
I was trying to AI this bot



I want to combine the OmniInverted.py with the Popup.py.  But when I tried doing it it won't fire on smart zone, then it rams the wall and crash the game on quit.  I am not sure what I am doing wrong.  Also, is it possible to alter the starting facing without changing the nose (so it faces forward immediately after the flip)?

Code: [Select]
from __future__ import generators
import plus
import AI
from AI import vector3
import Arenas
import Gooey
import math
import Tactics

class PopupInverted(AI.SuperAI):
    "Popup inverted strategy"
    name = "PopupInverted"
    # bot has to be invertible, not mandatory to mention it in your binding, it is force.
    # much like Popup except that the bot use a button control called 'Inverter' to invert itself if it is not.
    def __init__(self, **args):
        AI.SuperAI.__init__(self, **args)
               
           # force bot to be invertible :
        self.invertible = True
        self.zone1 = "weapon"
        self.triggers1 = ["Fire"]
        self.triggers2 = ["Srimech"]
        self.reloadTime = 0
        self.reloadDelay = 3
        self.InverterTime  = 3

        if 'zone' in args: self.zone = args['zone']
       
        if 'triggers' in args: self.triggers1 = args['triggers']
        if 'triggers' in args: self.triggers2 = args['triggers']

        self.tactics.append(Tactics.Engage(self))
       
    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.zone1, 1)
           
        return AI.SuperAI.Activate(self, active)

    def Tick(self):
        # fire weapon

            # If the bot is not inverted, try to invert it : use the button control called 'Inverter' :
            # here again, slight delay before inverting
            if self.InverterTime > 0: self.InverterTime -= 1

            #if (not self.ai.IsUpsideDown()) and (self.InverterTime <= 0) :
            #if (self.InverterTime <= 0) :
            if (not self.IsUpsideDown()) and (self.InverterTime <= 0) :
                self.Input("Inverter", 0, 1)
                self.InverterTime = self.reloadDelay
                   
        targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \
                and not plus.isDefeated(x.robot)]
       
            # slight delay between firing
            if self.reloadTime > 0: self.reloadTime -= 1
           
            if len(targets) > 0 and self.reloadTime <= 0:
                try:
                    trigger = self.triggerIterator.next()
                except StopIteration:
                    self.triggerIterator = iter(self.triggers)
                    trigger = self.triggerIterator.next()
               
                self.Input(trigger, 0, 1)
                self.reloadTime = self.reloadDelay
                       
        bReturn = AI.SuperAI.Tick(self)
       
        return bReturn

    def InvertHandler(self):
        # fire all weapons once per second (until we're upright!)
        while 1:
            for trigger in self.triggers2:
                self.Input(trigger, 0, 1)
           
            for i in range(0, 8):
                yield 0
               
    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 SmartZoneEvent(self, direction, id, robot, chassis):
        if id == 1 and self.weapons:
            if chassis:
                if direction == 1:
                    for trigger in self.triggers1: self.Input(trigger, 0, 1)
        return True
   
AI.register(PopupInverted)

Offline Naryar

  • Posts: 23283
  • Rep: 21
  • hybrids oui oui
    • http://www.youtube.com/us
  • Awards BOTM Winner
    • View Profile
    • Awards
  • Skype: TheMightyNaryar
Re: Is combining OmniInverted and Popup .py possible.
« Reply #1 on: November 04, 2012, 11:29:25 AM »
I'm pretty damn sure you can.

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: Is combining OmniInverted and Popup .py possible.
« Reply #2 on: November 04, 2012, 11:37:02 AM »
I roll out the red carpet for Trovaner and await his arrival.

Offline Mr. AS

  • TheGloriousCarbideArstotzkanIronsideChaosProtocol
  • *
  • Posts: 7558
  • Rep: 19
    • robotarenagtm
  • Awards BOTM Winner
    • View Profile
    • Awards
Re: Is combining OmniInverted and Popup .py possible.
« Reply #3 on: November 04, 2012, 12:10:11 PM »
isnt it in clicks ai essentials? either in there or in the feirce irish coca download in one of the my little pwnys (mnb's development-heck tournament) threads

IDK if it faces forward after the flip though
How you make Alarm Clock Pizza is:
Step 1: You buy an alarm clock from the store, and then you have to break it and put it in the sauce.
Step 2: Fold the sauce in 5 slices and put it in the dough.
Step 3: Paint the eggs with a pitcher of a clock showing what time you want to wake up and eat pizza for breakfast.
Step 4: Put the eggs in the dough.
Step 5: Make it flat into a round shape and draw the time you want on it.
Step 6: Put some old steel to prevent other peple from stealing it.
Step 7: Make it flat and cut into 60 slices 1 for each minute in 1 our.
Step 8: Put in the oven set the timer to 30048813.2884 seconds and put the temperature on 'Volcano' setting.
Step 9: If you think it is take to long, then get yor alarm clock and set it to now so that it will ring and you can take it out.
Step 10: Take it out uv the uvin wen it is redy and go to bed. In the morning eat pizza and also eat yor hands bi mistake.

Offline Gauche Suede

  • Ultra Heavyweight
  • Posts: 1232
  • Rep: 1
    • View Profile
    • Awards
Re: Is combining OmniInverted and Popup .py possible.
« Reply #4 on: November 05, 2012, 02:06:16 AM »
I was trying to AI this bot

(Image removed from quote.)

I want to combine the OmniInverted.py with the Popup.py.  But when I tried doing it it won't fire on smart zone, then it rams the wall and crash the game on quit.  I am not sure what I am doing wrong.  Also, is it possible to alter the starting facing without changing the nose (so it faces forward immediately after the flip)?

Code: [Select]
from __future__ import generators
import plus
import AI
from AI import vector3
import Arenas
import Gooey
import math
import Tactics

class PopupInverted(AI.SuperAI):
    "Popup inverted strategy"
    name = "PopupInverted"
    # bot has to be invertible, not mandatory to mention it in your binding, it is force.
    # much like Popup except that the bot use a button control called 'Inverter' to invert itself if it is not.
    def __init__(self, **args):
        AI.SuperAI.__init__(self, **args)
               
           # force bot to be invertible :
        self.invertible = True
        self.zone1 = "weapon"
        self.triggers1 = ["Fire"]
        self.triggers2 = ["Srimech"]
        self.reloadTime = 0
        self.reloadDelay = 3
        self.InverterTime  = 3

        if 'zone' in args: self.zone = args['zone']
       
        if 'triggers' in args: self.triggers1 = args['triggers']
        if 'triggers' in args: self.triggers2 = args['triggers']

        self.tactics.append(Tactics.Engage(self))
       
    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.zone1, 1)
           
        return AI.SuperAI.Activate(self, active)

    def Tick(self):
        # fire weapon

            # If the bot is not inverted, try to invert it : use the button control called 'Inverter' :
            # here again, slight delay before inverting
            if self.InverterTime > 0: self.InverterTime -= 1

            #if (not self.ai.IsUpsideDown()) and (self.InverterTime <= 0) :
            #if (self.InverterTime <= 0) :
            if (not self.IsUpsideDown()) and (self.InverterTime <= 0) :
                self.Input("Inverter", 0, 1)
                self.InverterTime = self.reloadDelay
                   
        targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \
                and not plus.isDefeated(x.robot)]
       
            # slight delay between firing
            if self.reloadTime > 0: self.reloadTime -= 1
           
            if len(targets) > 0 and self.reloadTime <= 0:
                try:
                    trigger = self.triggerIterator.next()
                except StopIteration:
                    self.triggerIterator = iter(self.triggers)
                    trigger = self.triggerIterator.next()
               
                self.Input(trigger, 0, 1)
                self.reloadTime = self.reloadDelay
                       
        bReturn = AI.SuperAI.Tick(self)
       
        return bReturn

    def InvertHandler(self):
        # fire all weapons once per second (until we're upright!)
        while 1:
            for trigger in self.triggers2:
                self.Input(trigger, 0, 1)
           
            for i in range(0, 8):
                yield 0
               
    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 SmartZoneEvent(self, direction, id, robot, chassis):
        if id == 1 and self.weapons:
            if chassis:
                if direction == 1:
                    for trigger in self.triggers1: self.Input(trigger, 0, 1)
        return True
   
AI.register(PopupInverted)
In the new Popup.py Click made, you can add an invert handler, here's what he told me about the py when i PMed him what py can i use to make a SHW Ultimate Sacrifice clone on DSL:
Quote
It's the latest version of Popup.py which you can conveniently get in the thread I just posted on the Modifications board.
 
Just set 'RunUpsideDown' to 1 and it should work.

Offline 123savethewhales

  • *
  • Posts: 2923
  • Rep: 30
  • Friendship is Magic
  • Awards BOTM Winner
    • View Profile
    • Awards
Re: Is combining OmniInverted and Popup .py possible.
« Reply #5 on: November 05, 2012, 10:41:14 AM »
Thanks.  So all I needed now is something for the starting location.