Does anyone use Jython to implement a robot of Robocode? I hava a problem.
hanzac
hanzac at cmmail.com
Tue Nov 26 07:41:35 EST 2002
I have succeeded in creating & running a robot which was coded in
Jython,
But the problem is when I first run the robot, it is disabled but
after a round it runs well.
The code is here (SampleBlaze.py):
// The Robot
from robocode import *
class SampleBlaze(Robot):
dist = 50
def run(self):
while 1:
self.turnGunRight(5)
def onScannedRobot(self, e):
if e.getDistance() < 50 and self.getEnergy() > 50:
self.fire(3)
else:
self.fire(1)
self.scan()
def onHitByBullet(self, e):
self.turnRight(self.normalRelativeAngle(90-(self.getHeading()-e.getHeading())))
self.ahead(self.dist)
self.dist *= -1
self.scan()
def onHitRobot(self, e):
turnGunAmt = self.normalRelativeAngle(e.getBearing()+self.getHeading()-self.getGunHeading())
self.turnGunRight(turnGunAmt)
self.fire(3)
def normalRelativeAngle(self, angle):
if angle > -180 and angle <= 180:
return angle
fixedAngle = angle
while fixedAngle <= -180:
fixedAngle += 360
while fixedAngle > 180:
fixedAngle -= 360
return fixedAngle
More information about the Python-list
mailing list