-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyAgentStones.py
44 lines (32 loc) · 1.16 KB
/
MyAgentStones.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from MyAgent import MyAgent
from Board import Color
import pygame
#inherits MyAgent
class MyAgentStones(MyAgent):
def __init__(self, id, initX, initY, env, capacity):
MyAgent.__init__(self, id, initX, initY, env)
self.stone = 0
self.backPack = capacity
# return quantity of precious stones collected and not unloaded yet
def getTreasure(self):
return self.stone
# unload precious stones in the pack back at the current position
def unload(self):
self.env.unload(self)
self.stone = 0
#return the agent's type
def getType(self):
return 1
# load the treasure at the current position
def load(self,env):
env.load(self)
# add some precious stones to the backpack of the agent (quantity t)
# if the quantity exceeds the back pack capacity, the remaining is lost
def addTreasure(self, t):
if(self.stone + t <= self.backPack) :
self.stone = self.stone + t
else :
self.stone = self.backPack
def __str__(self):
res ="agent Stone "+ self.id + " ("+ str(self.posX) + " , " + str(self.posY) + ")"
return res