Author Topic: From Text to Phyton  (Read 1075 times)

Offline Gauche Suede

  • Ultra Heavyweight
  • Posts: 1232
  • Rep: 1
    • View Profile
    • Awards
From Text to Phyton
« on: March 10, 2012, 10:09:16 PM »
i've just finished my very own AI code(RS Hybrid), but i still have it on text document. how do i turn it into a phyton file? ;)

Offline Mr. AS

  • TheGloriousCarbideArstotzkanIronsideChaosProtocol
  • *
  • Posts: 7557
  • Rep: 19
    • robotarenagtm
  • Awards BOTM Winner
    • View Profile
    • Awards
Re: From Text to Phyton
« Reply #1 on: March 10, 2012, 10:11:33 PM »
make a copy of an already existing .py file and edit that with notepad
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: From Text to Phyton
« Reply #2 on: March 10, 2012, 11:17:19 PM »
okay, i've did that, but now, after i tested the AI on Ninja Asassin, when i tried to battle it, the game won't load. what is missing?

Offline Gauche Suede

  • Ultra Heavyweight
  • Posts: 1232
  • Rep: 1
    • View Profile
    • Awards
Re: From Text to Phyton
« Reply #3 on: March 11, 2012, 12:07:01 AM »
@Larrain
i use Windows XP..

Offline martymidget

  • *
  • Posts: 3459
  • Rep: 7
  • Mr Flibble is very cross.
    • http://tts.imtranslator.n
    • View Profile
    • :)
    • Awards
Re: From Text to Phyton
« Reply #4 on: March 11, 2012, 03:18:21 AM »
You need notepad++ to save pythons, I believe.


Offline cephalopod

Re: From Text to Phyton
« Reply #5 on: March 11, 2012, 10:32:43 AM »
I doubt it's that - Notepad++ is just a fancier, nicer-for-editing Notepad. May be a little issue with the code, but I'll let someone more experienced in that business take it further, 'cos I have no idea :3
bristol bot builders / two headed death flamingo / snappy robots
//
kindest and friendliest '13, '15, '16, '17 / favourite staff member '14, '15

Offline ty4er

Re: From Text to Phyton
« Reply #6 on: March 11, 2012, 10:35:12 AM »
i'm sure it is notepad c++, you might want to ask clickbeetle or trovaner or someone like that
DSL Showcase
is this bot don't lost all razors in a fight before do a damage thought

Offline Trovaner

  • *
  • Posts: 1222
  • Rep: 32
    • View Profile
    • Awards
Re: From Text to Phyton
« Reply #7 on: March 11, 2012, 01:16:24 PM »
A python file is basically a text file that has the .py extension (as far as you need to concern yourself). Python files are read by an interpreter which in RA2's case I believe is version 2.3. If your game crashes during startup, you usually have a syntax error. If this is the case, IDLE or some unix based terminal can tell you whats wrong with the "grammer."

Notepad++ is in no way required to program especially in python but its my favorite text editor (scite is also pretty good). 

Offline Gauche Suede

  • Ultra Heavyweight
  • Posts: 1232
  • Rep: 1
    • View Profile
    • Awards
Re: From Text to Phyton
« Reply #8 on: March 12, 2012, 06:29:44 AM »
Guys, here's my RS Hybrid AI:
Code: [Select]
from __future__ import generators
import plus
import AI
from AI import vector3
import Arenas
import Gooey
import math
import Tactics

class RS Hybrid(AI.SuperAI):
    "Spins and Rams!"
    name = "RS Hybrid"

    def __init__(self, **args):
        AI.SuperAI.__init__(self, **args)

   self.spin_range = 40.0
   
   if 'range' in args:
            self.spin_range = args.get('range')

   self.tactics.append(Tactics.Ram(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("")

   return AI.SuperAI.Activate(self, active)

    def Tick(self):
        if self.weapons:
            # spin up depending on enemy's range
            enemy, range = self.GetNearestEnemy()
           
            if enemy is not None and range < self.spin_range:
                self.Input("Spin", 0, 1)
            elif self.GetInputStatus("Spin", 0) != 0:
                self.Input("Spin", 0, 0)

   return AI.SuperAI.Tick(self)

    def RobotInRange(self, robot_id):
        "Return tuple of (part-of-robot-in-range, chassis-in-range)"
        # GetLastDamage returns:  component damaged, amount, at time, by player, by component
        range = self.GetDistanceToID(robot_id)
        if range < self.spin_range:
            damage = self.GetLastDamageReceived()
            if damage[3] == robot_id and (plus.getTimeElapsed() - damage[2] < 1.0):
                return (True, True)

        return (False, False)
       
    def LostComponent(self, id):
        #print "Lost Component!"
        return AI.SuperAI.LostComponent(self, id)

    def LostComponent(self, id):
        # if we lose all our weapons, stop using the Ram 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)

AI.register(RS Hybrid)
Is this good? what should i change from it?
« Last Edit: March 12, 2012, 11:47:00 AM by Trovaner »

Offline Trovaner

  • *
  • Posts: 1222
  • Rep: 32
    • View Profile
    • Awards
Re: From Text to Phyton
« Reply #9 on: March 12, 2012, 11:42:57 AM »
TTYTT, it doesn't look like you changed that much. From what I can tell, you changed the default spin_range (which was already adjustable via the bindings) and made Ram the main tactic (which has already been done inside OmniTrueRam.py). Though by building upon Spinner.py, you have a specialized version of RobotInRange code that isn't found inside of any of the Omni variants (IIRC).

Issues:
1. Remove the first LostComponent method. I am aware that it was in Spinner.py but it is overridden anyways so its just wasting space.
2. Fix your __init__ method so that everything is indented by 8 spaces.
3. Fix your LostComponent method so that it properly switches tactics when all the weapons fall off (replace "Engage" with "Ram").
4. Due to an issue with how RA2's AI uses switches, you'll want to change the self.Input("Spin", 0, 1) to self.Input("Spin", 0, 100). This makes it compatible with Analog controls while still allowing it to work with buttons.

For anyone interested in using this, ram is not preinstalled in stock or DSL so you'll need to download Clickbeetle's upgraded tactics.py to use it (it may be found in BBEANS AI). You may also want to wait until he fixes the above issues.