diff --git a/virtupet/.idea/misc.xml b/virtupet/.idea/misc.xml
index b4221f4..5da332e 100644
--- a/virtupet/.idea/misc.xml
+++ b/virtupet/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/virtupet/.idea/virtupet.iml b/virtupet/.idea/virtupet.iml
index 6711606..e0841ce 100644
--- a/virtupet/.idea/virtupet.iml
+++ b/virtupet/.idea/virtupet.iml
@@ -2,7 +2,7 @@
-
+
diff --git a/virtupet/Pudgi.py b/virtupet/Pudgi.py
index 3d56f92..5a5929e 100644
--- a/virtupet/Pudgi.py
+++ b/virtupet/Pudgi.py
@@ -38,9 +38,16 @@ def __init__(self, parents=None, load_file=None):
if parents is not None:
alpha = parents[0]
beta = parents[1]
- self.dna = Pudgi.generate_dna_from(alpha, beta)
+
+ handler = JSONHandler()
+ handler.load_file("./data/pudgies/" + alpha + ".json")
+ alpha_json = handler.get_data()
+ handler.load_file("./data/pudgies/" + beta + ".json")
+ beta_json = handler.get_data()
+
+ self.dna = Pudgi.generate_dna_from(alpha_json, beta_json)
Pudgi.mutate_dna_strand(self.dna.get_strand())
- self.parents = parents
+ self.parents = [alpha_json["name"], beta_json["name"]]
else:
self.dna = DNA()
self.dna.gen_rand()
@@ -59,8 +66,9 @@ def __init__(self, parents=None, load_file=None):
self.handler.close()
# ------- general data -------
- self.known_decisions = []
self.known_decisions = self.json_object["known_decisions"]
+ self.age = self.json_object["age"]
+ self.lifespan = random.randint(540, 660) # approximately 10 minute irl lifespan
# TODO move this so it only happens upon creation of new Pudgi. Load pudgi should grab json attributes
self.splice_dna()
@@ -90,14 +98,17 @@ def __init__(self, parents=None, load_file=None):
@staticmethod
def generate_dna_from(alpha, beta):
- handler = JSONHandler()
- handler.load_file("./data/pudgies/" + alpha + ".json")
- alpha_json = handler.get_data()
- handler.load_file("./data/pudgies/" + beta + ".json")
- beta_json = handler.get_data()
-
- alpha_dna = DNA(alpha_json["dna"])
- beta_dna = DNA(beta_json["dna"])
+ # handler = JSONHandler()
+ # handler.load_file("./data/pudgies/" + alpha + ".json")
+ # alpha_json = handler.get_data()
+ # handler.load_file("./data/pudgies/" + beta + ".json")
+ # beta_json = handler.get_data()
+ #
+ # alpha_dna = DNA(alpha_json["dna"])
+ # beta_dna = DNA(beta_json["dna"])
+
+ alpha_dna = DNA(alpha["dna"])
+ beta_dna = DNA(beta["dna"])
strand = DNA.combine_dna(alpha_dna, beta_dna)
return DNA(strand)
diff --git a/virtupet/data/pudgies/default.json b/virtupet/data/pudgies/default.json
index 397e5ed..8a31727 100644
--- a/virtupet/data/pudgies/default.json
+++ b/virtupet/data/pudgies/default.json
@@ -74,6 +74,8 @@
1
],
"color": null,
+ "age": 0,
+ "lifespan": null,
"personality": null,
"parents": [null, null],
"happiness": 3.0,
diff --git a/virtupet/main.py b/virtupet/main.py
index e44fe0e..b9c01ae 100644
--- a/virtupet/main.py
+++ b/virtupet/main.py
@@ -113,13 +113,15 @@ def main():
# agent.stop()
for pudgi in active_agent_list:
- #if not pudgi.sleeping:
- # if movement[pudgi.name]["time"] <= 0:
- # movement[pudgi.name]["time"] = random.randint(30, 90)
- # movement[pudgi.name]["direction"] = random.choice(["L", "R", ""])
- #else: # pudgi is sleeping
- # movement[pudgi.name]["direction"] = "S"
-
+ if pudgi.age >= pudgi.lifespan:
+ active_agent_list.remove(pudgi)
+ active_sprite_list.remove(pudgi)
+ death_count += 1
+
+ print("---------------------------------------------")
+ print("<<<---" + pudgi.name + " died of old age--->>>")
+ print("Death Count: " + str(death_count))
+ print("---------------------------------------------")
if pudgi.sleeping:
movement[pudgi.name]["direction"] = "S"
pudgi.direction = "S"
@@ -141,12 +143,18 @@ def main():
time_clock.update_time()
clockSurface = font.render(time_clock.time_stamp(), True, constants.BLACK, constants.WHITE)
clockRect = clockSurface.get_rect()
- clockRect.centerx = screen.get_rect().centerx
+ clockRect.x = screen.get_rect().centerx - 120
clockRect.y = 2
clockBorder = pygame.draw.rect(screen, constants.BLACK, (clockRect.x - 2, clockRect.y - 2, clockRect.width + 4, clockRect.height + 4))
screen.blit(clockSurface, clockRect)
- screen.blit(clockSurface, clockRect)
+ deathCountSurface = font.render("Deaths: " + str(death_count), True, constants.BLACK, constants.WHITE)
+ deathCountRect = deathCountSurface.get_rect()
+ deathCountRect.x = clockRect.x + 120
+ deathCountRect.y = 2
+ deathCountBorder = pygame.draw.rect(screen, constants.BLACK,
+ (deathCountRect.x - 2, deathCountRect.y - 2, deathCountRect.width + 4, deathCountRect.height + 4))
+ screen.blit(deathCountSurface, deathCountRect)
game_clock.tick(30)
@@ -156,7 +164,10 @@ def main():
active_agent_list.remove(pudgi)
active_sprite_list.remove(pudgi)
death_count += 1
+ print("---------------------------------------------")
+ print("<<<---" + pudgi.name + " died in childbirth--->>>")
print("Death Count: " + str(death_count))
+ print("---------------------------------------------")
if int(time_clock.get_minutes()) % 15 == 0:
pudgi.make_decision()