Exemplo n.º 1
0
 def spawn(
     self,
     brains: (Brain
              for _ in range(sample_size)) = (None
                                              for _ in range(sample_size))):
     if use_memorized:
         past_brains = import_brains()
         if past_brains:
             brains = (brain for brain in past_brains)
     self.germs = [
         Germ.from_random(self, brains.__next__())
         for _ in range(sample_size)
     ]
     self.planks = [
         Border(self, (5, 10), 0,
                self.canvas.winfo_width() - 10, "blue"),
         Border(self, (5, self.canvas.winfo_height() - 10), 0,
                self.canvas.winfo_width() - 10, "green"),
         Border(self, (5, 10), 90,
                self.canvas.winfo_height() - 10, "red"),
         Border(self, (self.canvas.winfo_width() - 10, 10), 90,
                self.canvas.winfo_width() - 10, "yellow")
     ]
     self.killers = [
     ]  #Killer.from_random(get_state, set_state, canvas) for killer_count in range(4)]
     self.death_log = []
Exemplo n.º 2
0
 def spawn(self, brains: (Brain for _ in range(sample_size))=(None for _ in range(sample_size))):
     if use_memorized:
         past_brains = import_brains()
         if past_brains:
             brains = (brain for brain in past_brains)
     self.germs = [Germ.from_random(self, brains.__next__()) for _ in range(sample_size)]
     self.planks = [Border(self, (5, 10), 0, self.canvas.winfo_width() - 10, "blue"),
                    Border(self, (5, self.canvas.winfo_height() - 10), 0, self.canvas.winfo_width() - 10, "green"),
                    Border(self, (5, 10), 90, self.canvas.winfo_height() - 10, "red"),
                    Border(self, (self.canvas.winfo_width() - 10, 10), 90, self.canvas.winfo_width() - 10, "yellow")]
     self.killers = []#Killer.from_random(get_state, set_state, canvas) for killer_count in range(4)]
     self.death_log = []
Exemplo n.º 3
0
sample_size = 50       # The number of initial germs in each generation.
use_memorized = False   # Whether to pull brains from file, if such a file exists.
save_last = (True, 5)   # Whether to save the brains, and how many generations to go through before a save.

from tkinter import *
import time, random
import pickle
from germ import Germ
from plank import Plank, Border
from brain import Brain

root = Tk()
root.title("The Hunger Planks")

canvas = Canvas(root, width=500, height=500)
canvas.bind("<Button-1>", lambda event: state.germs.append(Germ.from_random(state)))
canvas.bind("<Button-3>", lambda event: state.planks.append(Plank.from_random(state)))
canvas.pack(fill=BOTH, expand=YES)

root.update()

class State():
    def __init__(self, canvas):
        self.canvas = canvas
        self.spawn()
        self.current_gen = 0

    def spawn(self, brains: (Brain for _ in range(sample_size))=(None for _ in range(sample_size))):
        if use_memorized:
            past_brains = import_brains()
            if past_brains:
Exemplo n.º 4
0
    True, 5
)  # Whether to save the brains, and how many generations to go through before a save.

from tkinter import *
import time, random
import pickle
from germ import Germ
from plank import Plank, Border
from brain import Brain

root = Tk()
root.title("The Hunger Planks")

canvas = Canvas(root, width=500, height=500)
canvas.bind("<Button-1>",
            lambda event: state.germs.append(Germ.from_random(state)))
canvas.bind("<Button-3>",
            lambda event: state.planks.append(Plank.from_random(state)))
canvas.pack(fill=BOTH, expand=YES)

root.update()


class State():
    def __init__(self, canvas):
        self.canvas = canvas
        self.spawn()
        self.current_gen = 0

    def spawn(
        self,