|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Writing Robots in Python / Jython?Hello,
I'm looking for a possibility to write a Robocode-robot in Python. Thus I tries Jython but without success. The robot Pambo.py looks like this: >--- from robocode import * class Pambo(Robot): def listMods(self): return "net.sourceforge.robocodeng.mods.ShotgunMod" def run(self): print "Rambo is running..." while True: ahead(100) # Move ahead 100 turnGunRight(360) # Spin gun around back(100) # Move back 100 turnGunRight(360) # Spin gun around def onScannedRobot(ScannedRobotEvent): fire(1) # We were hit! Turn perpendicular to the bullet, # so our seesaw might avoid a future shot. def onHitByBullet(HitByBulletEvent): turnLeft(90 - HitByBulletEvent.getBearing()) >--- Compilation by typing "jythonc -A ~/RobocodeNG/RobocodeNG.jar Pambo.py" succeeded. I started Robocode successfully with "java -cp RobocodeNG.jar:/usr/share/jython/jython.jar:. robocode.Robocode" but the message "sample.Pambo : Something is wrong with this class: java.lang.NoClassDefFoundError: sample/Pambo (wrong name: Pambo)" showed up. My Python-robot does not start when selected for a battle. I use Ubuntu Linux, Sun's Java 1.5 and Jython 2.1. Any ideas how to make my robot runnable? Other suggestions how to use Python with Robocode? Regards, Lutz Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/Robocode/ <*> To unsubscribe from this group, send an email to: Robocode-unsubscribe@... <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/ |
|
|
Re: Writing Robots in Python / Jython?I can run jython robocode-robot!
Some changes of course. 1. Compile it to a package with -p: jythonc -p sample pambo.py You can see "package sample;" in the resulting pambo.java. 2. Add self argument to class member function def, such as: def onScannedRobot(self, ScannedRobotEvent): 3. Add self to function calls, such as: self.ahead(100) --- In Robocode@..., Lutzer <m.lutzer@...> wrote: > > Hello, > I'm looking for a possibility to write a Robocode-robot in Python. Thus > I tries Jython but without success. The robot Pambo.py looks like this: > > >--- > from robocode import * > > class Pambo(Robot): > > def listMods(self): > return "net.sourceforge.robocodeng.mods.ShotgunMod" > > def run(self): > print "Rambo is running..." > while True: > ahead(100) # Move ahead 100 > turnGunRight(360) # Spin gun around > back(100) # Move back 100 > turnGunRight(360) # Spin gun around > > def onScannedRobot(ScannedRobotEvent): > fire(1) > > # We were hit! Turn perpendicular to the bullet, > # so our seesaw might avoid a future shot. > def onHitByBullet(HitByBulletEvent): > turnLeft(90 - HitByBulletEvent.getBearing()) > >--- > > Compilation by typing "jythonc -A ~/RobocodeNG/RobocodeNG.jar Pambo.py" > succeeded. I started Robocode successfully with > "java -cp RobocodeNG.jar:/usr/share/jython/jython.jar:. > robocode.Robocode" but the message "sample.Pambo : Something is wrong > with this class: java.lang.NoClassDefFoundError: sample/Pambo (wrong > name: Pambo)" showed up. My Python-robot does not start when selected > for a battle. > > I use Ubuntu Linux, Sun's Java 1.5 and Jython 2.1. > > Any ideas how to make my robot runnable? Other suggestions how to use > Python with Robocode? > > Regards, Lutz > |
| Free embeddable forum powered by Nabble | Forum Help |