idea: Robocode for Python
C. Porter Bassett
porter at et.byu.edu
Tue Sep 11 11:51:55 EDT 2001
> Wouldn't jython fill the bill in this case?
I had the same thought, and decided to try it. Since I don't have any
java nor jython experience, I didn't get very far. I'll post my
progress here in the hopes that somebody can help me get a litte
further.
First of all, here's a very simple .java robot:
package porter;
import robocode.*;
public class CPB extends Robot
{
public void run()
while(true)
ahead(100);
turnGunRight(360);
back(100);
turnGunRight(360);
}
}
public void onScannedRobot(ScannedRobotEvent e)
{
fire(1);
}
}
I have no idea what the package porter; line is for, so I ignored it.
I
added the robocode.jar to my classpath, and tried to translate this
java
code to python. Here's my python file:
from robocode import *
class pyrobot(Robot):
def run(self):
while(1):
ahead(100)
turnGunRight(360)
back(100)
turnGunRight(360)
def onScannedRobot(self, event):
fire(1)
I ran that through jythonc, and it compiled, but I got a depracation
warning. I recompiled with -deprecation, and here's the output from
jythonc:
0932:PWORK://d/robocode/robots/porter$ jythonc pyrobot.py
processing pyrobot
Required packages:
robocode.dialog
robocode.jdk13bugfix
robocode.editor
robocode*
Creating adapters:
Creating .java files:
pyrobot module
pyrobot extends robocode.Robot
Compiling .java to .class...
Compiling with args: ['c://jdk1.3.1_01/bin/javac.exe',
'-deprecation',
'-classpath', 'C:\\jython-2.0\\jython.jar;.;C:\\Program
Files\\proe2000i2\\modchk\\java\\xml\\xml4j.jar;c:\\jython-2.0\\jython.jar;d
:\\robocode\\robocode.jar;.\\jpywork;;C:\\jython-2.0\\Tools\\jythonc;d:\\rob
ocode\\robots\\porter\\.;C:\\jython-2.0\\Lib;c:\\jython\\lib;C:\\jython-2.0'
, '.\\jpywork\\pyrobot.java']
0 .\jpywork\pyrobot.java:100: warning:
jfindattr(org.python.core.PyProxy,java.lang.String) in
org.python.core.Py
has been deprecated
PyObject inst = Py.jfindattr(this, "onScannedRobot");
^
.\jpywork\pyrobot.java:110: warning:
jfindattr(org.python.core.PyProxy,java.lang.String) in
org.python.core.Py
has been deprecated
PyObject inst = Py.jfindattr(this, "run");
^
2 warnings
When I try to run a robocode battle with this robot, the robocode
console
gives me the following error:
java.lang.NoClassDefFoundError: porter/jpywork/pyrobot (wrong name:
pyrobot)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at
robocode.JBotsClassLoader.loadRobotClass(JBotsClassLoader.java:55)
at robocode.Battle.initialize(Battle.java:350)
at robocode.Battle.run(Battle.java:42)
at java.lang.Thread.run(Unknown Source)
Because of my utter lack of java knowledge, I am completely stuck. Is
it
even possible to do what I am trying to do? If so, what should I try
next?
More information about the Python-list
mailing list