Skip to content

Commit

Permalink
fixed dna issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ngraham20 committed Apr 20, 2018
1 parent d85f159 commit 646eb1b
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 23 deletions.
11 changes: 6 additions & 5 deletions virtupet/Pudgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ def __init__(self, parents=None, load_file=None):

self.handler.load_file(constants.DEFAULT_PUDGI)
self.json_object = self.handler.get_data()

self.happiness = self.json_object["happiness"]
self.uid = hex(random.randint(0, 100000))

self.handler.close()
self.handler.load_file("./data/names.json")
names = self.handler.get_data()
self.name = random.choice(names)

self.handler.load_file("./data/names.json")
names = self.handler.get_data()
self.name = random.choice(names)
self.handler.close()

# ------- general data -------
self.known_decisions = []
self.known_decisions = self.json_object["known_decisions"]

# TODO move this so it only happens upon creation of new Pudgi. Load pudgi should grab json attributes
self.splice_dna()

# ------- animation variables -------
Expand Down Expand Up @@ -303,6 +303,7 @@ def export_to_json(self):
self.json_object["personality"] = self.personality
self.json_object["known_decisions"] = self.known_decisions
self.json_object["parents"] = self.parents
self.json_object["dna"] = self.dna.get_strand()

self.handler.save_as("./data/pudgies/" + self.uid + ".json", self.json_object)

Expand Down
19 changes: 15 additions & 4 deletions virtupet/clock.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# this file will have the functions to deal with the accumulation of time data and the printing of a timestamp

import time
import datetime


class Clock:
Expand All @@ -15,10 +16,20 @@ def elapsed_time(self):

def time_stamp(self):
stamp = ""
hours = "%02d" % ((int((self.elapsed_time()))/60),)
minutes = "%02d" % (int((self.elapsed_time())),)

return hours + ":" + minutes
# hours = "%02d" % ((int((self.elapsed_time()))/ 60),)
# minutes = "%02d" % (int((self.elapsed_time()))% 60,)
# hours = "%02d" % ((int((time.time())) / 60),)
# minutes = "%02d" % ((int((time.time())) % 60),)
time = datetime.datetime.now()
hours = "%02d" % (time.minute % 24,)
minutes = "%02d" % (time.second,)

if int(hours) == 00:
return str(12) + ":" + minutes + "am"
elif int(hours) == 13:
return str(12) + ":" + minutes + "pm"
else:
return str(int(hours) % 12) + ":" + minutes + "pm"

def update_time(self):
self.cur_time = int(self.elapsed_time())
148 changes: 148 additions & 0 deletions virtupet/data/pudgies/0x8653.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"uid": "0x8653",
"name": "Madalynn",
"dna": [
0,
1,
1,
0,
1,
0,
1,
0,
1,
1,
1,
1,
0,
0,
1,
0,
1,
0,
1,
0,
0,
1,
1,
1,
0,
0,
0,
1,
0,
0,
1,
0,
0,
1,
1,
0,
1,
0,
1,
0,
0,
0,
1,
1,
0,
0,
0,
0,
0,
1,
1,
0,
0,
1,
0,
0,
1,
1,
1,
0,
0,
1,
0,
1,
0,
1,
0,
1,
1,
0,
1,
1,
0,
0,
1,
1,
1,
1,
1,
1,
0,
0,
1,
0,
1,
1,
0,
0,
0,
0,
1,
0,
0,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
0,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
1,
1,
1,
0,
1,
0,
1,
0,
0,
0,
1,
1
],
"color": "Purple",
"personality": "ISTP",
"parents": [
null,
null
],
"happiness": 0.5,
"known_decisions": []
}
31 changes: 17 additions & 14 deletions virtupet/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,29 @@
import pygame
import constants
import environments
from file_handler import JSONHandler
from clock import Clock
from pudgi import Pudgi


def main():
handler = JSONHandler()
handler.load_file(constants.DEFAULT_PUDGI)
json_object = handler.get_data()

time_clock = Clock()

# ----------- pygame objects -----------
pygame.init()

pygame.font.init()

font = pygame.font.SysFont('Comic Sans MS', 30)

size = [constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT]
screen = pygame.display.set_mode(size)

pygame.display.set_caption(json_object["name"])
pygame.display.set_caption("Pudgi Simulation")

parents = ["0x9c08", "0x11e66"]
# agent = Pudgi(parents)
# agent = Pudgi(None, "./data/pudgies/0x9c08.json")
agent = Pudgi()
agent = Pudgi(None, "./data/pudgies/0x8653.json")
# agent = Pudgi()
env_list = [environments.EnvironmentHouse(agent)]

current_env_no = 0
Expand Down Expand Up @@ -56,10 +55,6 @@ def main():
# --------------Main While loop---------------
while not done:

if time_clock.elapsed_time() > time_clock.cur_time:
time_clock.update_time()
print(time_clock.time_stamp())

for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
Expand All @@ -85,9 +80,17 @@ def main():
current_env.draw(screen)
active_sprite_list.draw(screen)

clock.tick(30)
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.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)

# print(clock.get_fps())
clock.tick(30)

pygame.display.flip()

Expand Down

0 comments on commit 646eb1b

Please sign in to comment.