Skip to content

Commit

Permalink
increase live cell seed amount
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Feb 28, 2016
1 parent e4bbb9e commit 76a2942
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
8 changes: 6 additions & 2 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ def __init__(self, server):
self.data = None
self.gamecontroller = None
self.current_state = None

self.lights = visuals.Lights()

try:
self.lights = visuals.Lights()
except Exception:
print "self lights equals None"
self.lights = None

def signal_handler(self, signal, frame):
self.lights.set_lights_off()
Expand Down
2 changes: 1 addition & 1 deletion controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, width = 16, height = 16):
def init_mat(self, width = None, height = None):
width = self.game_width if width == None else width
height = self.game_height if height == None else height
matrix = [(1 if rand.randint(0, 100) < 15 else 0) for x in range(self.game_width * height)]
matrix = [(1 if rand.randint(0, 100) < 30 else 0) for x in range(self.game_width * height)]
return matrix

def set_display_mode(self, disp_mode):
Expand Down
41 changes: 29 additions & 12 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ def __init__(self, host, port, gamecontroller):
self.update_msg = None

self.gamecontroller = gamecontroller

self.lights = visuals.Lights()

try:
self.lights = visuals.Lights()
except Exception:
self.lights = None

self.subsection = None

Expand Down Expand Up @@ -60,27 +63,41 @@ def process(self):
self.client.close()
self.update_lights()

def process_exists(pid_str):
try:
os.kill(int(pid_str), 0)
except OSError:
return False
else:
return True

def update_lights(self):
# read /tmp/fallback.pid. if it has a p_id, check if p active
# if p not active replace with own, if active, keep trying
self.lights.update(self.gamecontroller.get_partial_grid())
'''
#self.lights.update(self.gamecontroller.get_partial_grid())

if self.lights == None:
return

try:
busy = False
pid_valid = False
f = open("/tmp/fallback.pid", "w+")
if f.readline() != "":
busy = True
pid = f.readline()

if pid != "" and pid != str(os.getpid()) and self.process_exists(pid):
pid_valid = True

if busy:
sleep(0.5)
self.update_lights()
if pid_valid:
f.close()
return
else:
f.seek(0)
f.write(str(os.getpid()))
f.close()
self.lights.update(self.gamecontroller.get_partial_grid())
f.close()

except IOError as err:
print ("err")
'''

def main():
server = Server('', 8000)
Expand Down

0 comments on commit 76a2942

Please sign in to comment.