Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09f929c

Browse files
author
charlie-lutaud
committed
bug solved (need to clear the scene)
1 parent 2bd493b commit 09f929c

File tree

7 files changed

+57
-31
lines changed

7 files changed

+57
-31
lines changed

Python-Robocode/.datas/lastArena

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,11 @@ I700
55
sS'botList'
66
p2
77
(lp3
8-
ccharlier
9-
Charlier
8+
ccharlie
9+
Charlie
1010
p4
1111
ag4
12-
ag4
13-
ag4
14-
ag4
15-
ag4
16-
accharlie
17-
Charlie
18-
p5
19-
ag5
20-
ag5
21-
ag5
22-
ag5
23-
ag5
24-
ag5
2512
asS'height'
26-
p6
13+
p5
2714
I500
2815
s.

Python-Robocode/GUI/RobotInfo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def on_progressBar_valueChanged(self, value):
3535
"""
3636
Slot documentation goes here.
3737
"""
38-
green = value*2
39-
red = 50 + 200 - value*2
38+
green = int(value*2)
39+
red = int(50 + 200 - value*2)
4040
self.progressBar.setStyleSheet("""
4141
QProgressBar {
4242
border: 2px solid grey;

Python-Robocode/GUI/window.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def on_pushButton_clicked(self):
3333
"""
3434
Start the last battle
3535
"""
36+
try:
37+
self.scene.clear()
38+
except:
39+
pass
3640
with open(os.getcwd() + "/.datas/lastArena", 'rb') as file:
3741
unpickler = pickle.Unpickler(file)
3842
dico = unpickler.load()

Python-Robocode/Objects/graph.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ def AddRobots(self, botList):
4545

4646
def battleFinished(self):
4747
print "battle terminated"
48-
self.deadBots.append(self.aliveBots[0])
49-
self.removeItem(self.aliveBots[0])
48+
try:
49+
self.deadBots.append(self.aliveBots[0])
50+
self.removeItem(self.aliveBots[0])
51+
except IndexError:
52+
pass
5053
j = len(self.deadBots)
5154
for i in range(j):
5255
print "N°", j - i , ":", self.deadBots[i]

Python-Robocode/Objects/physics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ def __init__(self):
2020
def reverse(self):
2121
self.animationList.reverse()
2222

23-
def newAnimation(self):
24-
23+
def newAnimation(self):
2524
self.makeAnimation()
2625
self.animation.reverse()
2726
self.animationList.append(self.animation)

Python-Robocode/Objects/robot.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,29 @@ def getPosition(self):
242242
r = self.boundingRect()
243243
return QtCore.QPointF(p.x() + r.width()/2, p.y()+r.height()/2)
244244

245+
def getGunHeading(self):
246+
return self.gun.rotation()
247+
248+
def getHeading(self):
249+
return self.gun.rotation()
250+
251+
def getRadarHeading(self):
252+
return self.gun.rotation()
253+
245254
def reset(self):
246255
self.physics.reset()
247256

248-
def getNbrOfEnemiesLeft(self):
257+
def getEnemiesLeft(self):
249258
return len(self.parent.aliveBots)
250259

251260
def rPrint(self, msg):
252261
self.info.out.add(str(msg))
253262

254-
263+
def pause(self, duration):
264+
self.stop()
265+
for i in range(int(duration)):
266+
self.physics.move.append(0)
267+
self.stop()
255268
###end of functions accessable from robot###
256269

257270
# Calculus
@@ -289,6 +302,7 @@ def wallRebound(self, item):
289302
y = - self.physics.step*1.1
290303
self.setPos(self.pos().x() + x, self.pos().y() + y)
291304
self.changeHealth(self, -1)
305+
self.onHitWall()
292306

293307

294308
def robotRebound(self, robot):
@@ -307,6 +321,7 @@ def robotRebound(self, robot):
307321
robot.setPos(x+dx, y+dy)
308322
self.changeHealth(robot, -1)
309323
self.changeHealth(self, -1)
324+
self.onRobotHit(id(robot))
310325

311326
def bulletRebound(self, bullet):
312327
self.changeHealth(self, - bullet.power)
@@ -330,7 +345,7 @@ def death(self):
330345
self.parent.aliveBots.remove(self)
331346
self.onRobotDeath()
332347
self.parent.removeItem(self)
333-
348+
print len(self.parent.aliveBots)
334349
if len(self.parent.aliveBots) <= 1:
335350
self.parent.battleFinished()
336351

Python-Robocode/Robots/charlie.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ def init(self):# NECESARY FOR THE GAME To initialyse your robot
2121
def run(self): #NECESARY FOR THE GAME main loop to command the bot
2222

2323

24-
#self.move(90) # for moving (negative values go back)
25-
#self.stop()
26-
24+
self.move(90) # for moving (negative values go back)
2725
self.turn(360) #for turning (negative values turn counter-clockwise)
2826
self.stop()
27+
"""
28+
the stop command is used to make moving sequences: here the robot will move 90steps and turn 360° at the same time
29+
"""
30+
2931
#self.setGunDirection(40) # set the Gun direction (bottom = 0°)
3032

3133
self.fire(9.2) # To Fire (power between 1 and 10)
@@ -36,20 +38,36 @@ def run(self): #NECESARY FOR THE GAME main loop to command the bot
3638

3739
self.move(180)
3840
self.turn(180)
39-
self.gunTurn(90)
41+
self.gunTurn(90) #to turn the gun (negative values turn counter-clockwise)
4042
self.stop()
4143

42-
self.radarTurn(180)
44+
self.radarTurn(180) #to turn the radar (negative values turn counter-clockwise)
4345
self.stop()
4446

4547
def sensors(self): #NECESARY FOR THE GAME
4648
"""Tick each frame to have datas about the game"""
4749

4850
pos = self.getPosition() #return the center of the bot
49-
#print pos.x(), pos.y()
51+
x = pos.x() #get the x coordinate
52+
y = pos.y() #get the y coordinate
53+
54+
angle = self.getGunHeading() #Returns the direction that the robot's gun is facing
55+
angle = self.getHeading() #Returns the direction that the robot is facing
56+
angle = self.getRadarHeading() #Returns the direction that the robot's radar is facing
57+
58+
def onHitWall(self):
59+
self.reset() #To reset the run fonction to the begining (auomatically called on hitWall, and robotHit event)
60+
self.pause(100)
61+
self.move(-100)
62+
self.stop() # DON'T forget this if you want to do not combine this action with the begining of the run fonction
63+
64+
def onRobotHit(self, robotId):
65+
self.rPrint(robotId)
5066

5167
def onHitByBullet(self, bulletBotId, bulletPower): #NECESARY FOR THE GAME
5268
""" When i'm hit by a bullet"""
69+
self.reset() #To reset the run fonction to the begining (auomatically called on hitWall, and robotHit event)
70+
self.pause(100)
5371
self.rPrint ("hit by " + str(bulletBotId) + "with power:" +str( bulletPower))
5472

5573
def onBulletHit(self, botId, bulletId):#NECESARY FOR THE GAME

0 commit comments

Comments
 (0)