def test_example_should_render_expected_output_after_1_generation(self): next_frame = GameOfLife.from_file( 'console-and-pyplot/data/input_gen1.txt').next_step() expected_frame = GameOfLife.from_file( 'console-and-pyplot/data/output_gen1.txt').current() self.assertTrue(next_frame.is_equal_to(expected_frame))
def main(): gof = GameOfLife() try: gof.run() except Exception as e: traceback.print_exc(e) return -1
def test_example3_should_just_run(self): rows = 20 cols = 20 data = ['Generation 1:', '{} {}'.format(rows, cols)] for row in range(rows): data.append(self._random_line(cols)) GameOfLife.from_list(data).run()
def main(): clear() print("Game of Life") rows, cols = int(input("How many Rows:")), int(input("How many Columns:")) game = GameOfLife(rows, cols) while True: clear() print(game) game.iterate() time.sleep(0.5)
def testAWorldCanEvolveTwice(self): coordinates = [ [1, 1], [2, 2], [3, 3] ]; gameOfLife = GameOfLife(coordinates) gameOfLife.evolve() new_cells = gameOfLife.evolve() self.assertEquals(0, len(new_cells))
def main(): game = GameOfLife((width // rowSize), (height // rowSize)) window = pygame.display.set_mode((width, height)) flow = True clock = pygame.time.Clock() frame = game.frameA while flow: clock.tick(framerate) redrawWindow(window, frame) frame = game.updateGeneration()
def test_can_update(self): game = GameOfLife(width=self.width, height=self.height, cell_size=1) game.clist = self.clist with open('steps.txt') as f: steps = json.load(f) num_updates = 0 for step in sorted(steps.keys(), key=int): with self.subTest(step=step): for _ in range(int(step) - num_updates): game.clist = game.update_cell_list(game.clist) self.assertEqual(steps[step], game.clist) num_updates += int(step)
def toad(): game = GameOfLife(6) game.add_living_cell(2, 2) game.add_living_cell(3, 2) game.add_living_cell(4, 2) game.add_living_cell(1, 3) game.add_living_cell(2, 3) game.add_living_cell(3, 3) return game
def beacon(): game = GameOfLife(6) game.add_living_cell(1, 1) game.add_living_cell(2, 1) game.add_living_cell(1, 2) game.add_living_cell(4, 3) game.add_living_cell(3, 4) game.add_living_cell(4, 4) return game
def testAWorldCanEvolve3Times(self): coordinates = [ [1, 1], [1, 2], [1, 3], [2, 2], [2, 3] ]; gameOfLife = GameOfLife(coordinates) new_cells = gameOfLife.evolve() new_cells = gameOfLife.evolve() new_cells = gameOfLife.evolve() self.assertEquals(2, len(new_cells)) self.assertEquals([0, 2], new_cells[0]) self.assertEquals([1, 2], new_cells[1])
def Set_Clicked(self, widget, data = None): a = self.WidthText.get_text() b = self.HeightText.get_text() changed = False #Max = 1000000 #Hann raedur vid thad, en thad sest ekki i individual frumur. Max = 500 if not (re.match('\\d+',a) and re.match('\\d+',b)) : print 'Sla verdur inn tolur' return if(self.__Width != int(a)): if int(a) in range(1,self.MaxWidth): self.__Width = int(a) changed = True elif int(a) >= self.MaxWidth: self.__Width = self.MaxWidth; changed = True if(self.__Height != int(b)): if int(b) in range(1,self.MaxHeight): self.__Height = int(b) changed = True elif int(b) >= self.MaxHeight: self.__Height = self.MaxHeight; changed = True if(changed): self.__GOL = GameOfLife(self.__Width,self.__Height,self.__Wrap,None) self.__GOL.setBS(self.BornText.get_text(),self.SurvivesText.get_text()) self.__Born, self.__Survives = self.__GOL.Born, self.__GOL.Survives self.updateStrings() self.drawField(self.Teiknibord) return True
def main(): """Configure board""" size = 800 game_of_life = GameOfLife(size) app = QtGui.QApplication(sys.argv) win = Form(game_of_life) sys.exit(app.exec_())
class GameOFLifeTest(unittest.TestCase): def setUp(self): self.game = GameOfLife(5, 5) # Any live cell with less than two live neighbours dies, # as if caused by under-population. def test_cell_with_less_than_two_live_neighbours_die(self): board = self.game.iterate([ (0, 0) ]) self.assertTrue((0,0) not in board) # Any live cell with two or three live neighbours lives on to the next generation. def test_cell_with_two_neighbours_live(self): board = self.game.iterate([ (0, 0), (0, 1), (0, 2) ]) self.assertTrue((0, 1) in board) def test_cell_with_three_neighbours_live(self): board = self.game.iterate([ (0, 0), (0, 1), (0, 2), (1, 1) ]) self.assertTrue((1, 1) in board) # # Any live cell with more than three live neighbours dies, as if by overcrowding. def test_cell_with_more_than_three_neighbours_die(self): board = self.game.iterate([ (1, 0), (1, 1), (1, 2), (2, 0), (2, 1) ]) self.assertTrue((1, 1) not in board) # Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. def test_dead_cell_with_three_neighbours_lives(self): board = self.game.iterate([ (0, 0), (0, 1), (1, 0), ]) self.assertTrue((1, 1) in board)
def strong_scaling(): gol = GameOfLife(1000, 500) gol.generate_random_mesh() mesh = gol.mesh for i in range(1, 11): gol.update_parallel(i) gol.mesh = mesh
class TestIsAlive(unittest.TestCase): def setUp(self): self.game = GameOfLife(5) self.game.add_living_cell(1, 2) self.game.add_living_cell(2, 2) self.game.add_living_cell(2, 1) def test_that_it_returns_false_if_cell_was_not_added(self): self.assertEqual(self.game.is_alive(2, 3), False) def test_that_it_returns_true_if_cell_was_not_added(self): self.assertEqual(self.game.is_alive(1, 2), True) def test_that_it_validates_coordinates(self): with self.assertRaises(ValueError): self.game.is_alive(- 1, 2)
def setUp(self): self.game = GameOfLife(10) self.game.add_living_cell(1, 1) self.game.add_living_cell(2, 1) self.game.add_living_cell(3, 1) self.game.add_living_cell(1, 2) self.game.add_living_cell(3, 2) self.game.add_living_cell(1, 3) self.game.add_living_cell(2, 3) self.game.add_living_cell(3, 3) self.game.add_living_cell(4, 4)
def setUp(self): self.gameValidateEnum = GameOfLife(2, 2, [['.', '*'], ['*', '.']], 3) self.gameValidateCountNeighbours = GameOfLife( 2, 3, [['.', '.', '.'], ['*', '.', '*']], 3) self.gameValidateNeighbours = GameOfLife( 4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '*', '.', '.', '.'], ['.', '.', '.', '*', '*', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 2) self.validateKillToReviveCell = GameOfLife( 3, 2, [['.', '*'], ['.', '.'], ['*', '.']], 2)
class TestAddLivingCellMethod(unittest.TestCase): def setUp(self): self.game = GameOfLife(5) def test_that_it_raises_value_error_when_x_is_not_in_range(self): with self.assertRaises(ValueError): self.game.add_living_cell(5, 0) def test_that_it_raises_value_error_when_y_is_not_in_range(self): with self.assertRaises(ValueError): self.game.add_living_cell(2, 5) def test_that_it_raises_value_error_when_both_are_not_in_range(self): with self.assertRaises(ValueError): self.game.add_living_cell(7, 5) def test_that_it_returns_true_when_both_are_good(self): self.assertEqual(self.game.add_living_cell(2, 3), True)
def test_example2_should_just_run(self): GameOfLife.from_file('console-and-pyplot/data/input2_gen1.txt').run()
def doGameOfLife(): global curThread curThread = GameOfLife(disp) curThread.start()
class TestGameOfLife(unittest.TestCase): def setUp(self): self.game = GameOfLife() self.game.generateBoard() def test_canAddToBoard(self): self.game.generateBoard() self.game.addLiveCell((1, 1)) def test_canCheckIfCellAlive(self): self.game.addLiveCell((1, 2)) self.assertEqual(self.game.CellIsAlive((1, 2)), 1) self.assertEqual(self.game.CellIsAlive((2, 2)), 0) # def test_canKillCell(self): # self.game.addLiveCell((1,2)) # self.game.addLiveCell((2,2)) # self.game.killCell((2,2)) # self.assertEqual(self.game.CellIsAlive((1,2)), 1) # self.assertEqual(self.game.CellIsAlive((2,2)), 0) def test_canGetNeighbors(self): self.game.addLiveCell((0, 0)) self.game.addLiveCell((1, 1)) self.game.addLiveCell((2, 2)) self.assertEqual(self.game.getNumNeighbors((1, 1)), 2) def test_cellIsLonely(self): self.game.addLiveCell((0, 0)) self.game.addLiveCell((1, 1)) self.game.addLiveCell((2, 2)) self.game.addLiveCell((3, 3)) self.assertEqual(self.game.cellIsLonely((1, 1)), 0) self.assertEqual(self.game.cellIsLonely((3, 3)), 1) def test_cellIsOvercrowded(self): self.game.addLiveCell((0, 0)) self.game.addLiveCell((1, 1)) self.game.addLiveCell((2, 2)) self.game.addLiveCell((2, 1)) self.game.addLiveCell((0, 1)) self.assertEqual(self.game.cellIsOvercrowded((1, 1)), 1) self.assertEqual(self.game.cellIsOvercrowded((2, 2)), 0) def test_canAdvanceByKillingCells(self): self.game.addLiveCell((0, 0)) self.game.addLiveCell((1, 1)) self.game.addLiveCell((2, 2)) self.game.addLiveCell((2, 1)) self.game.addLiveCell((0, 1)) self.game.addLiveCell((3, 3)) self.game.advanceGame() self.assertEqual(self.game.CellIsAlive((1, 1)), 0) self.assertEqual(self.game.CellIsAlive((3, 3)), 0)
''' # gui.py - Handles starting the Graphical User Interface for the Simulation ''' import sys from PyQt5.QtWidgets import QApplication from PyQt5.QtGui import QPalette from PyQt5.QtCore import Qt from GameOfLife import GameOfLife from DataParser import DataParser APP = QApplication(sys.argv) APP.setStyleSheet(open('styles.css').read()) PARSER = DataParser() PARSER.LoadDataFile("inputData.xml") WINDOW = GameOfLife() sys.exit(APP.exec_())
class MyTestCase(unittest.TestCase): def setUp(self): self.game_of_life = GameOfLife(world_size=10) def test_can_create_gol(self): self.assertIsNotNone(self.game_of_life) def test_get_current_world(self): self.assertIsNotNone(self.game_of_life.world) def test_initially_all_cells_dead(self): for row in self.game_of_life.world: for cell in row: self.assertFalse(cell.alive) def test_live_cell_with_fewer_than_two_live_neighbours_dies_in_next_round(self): self.game_of_life.world[0][0].alive = True self.game_of_life.next_round() self.assertFalse(self.game_of_life.world[0][0].alive) def test_live_cell_with_more_than_three_live_neighbours_dies_in_next_round(self): self.game_of_life.world[1][1].alive = True self.game_of_life.world[0][1].alive = True self.game_of_life.world[1][0].alive = True self.game_of_life.world[2][1].alive = True self.game_of_life.world[1][2].alive = True self.game_of_life.next_round() self.assertFalse(self.game_of_life.world[1][1].alive) def test_live_cell_with_two_live_neighbours_lives_on_to_the_next_generation(self): self.game_of_life.world[1][1].alive = True self.game_of_life.world[0][1].alive = True self.game_of_life.world[1][0].alive = True self.game_of_life.next_round() self.assertTrue(self.game_of_life.world[1][1].alive) def test_live_cell_with_three_live_neighbours_lives_on_to_the_next_generation(self): self.game_of_life.world[1][1].alive = True self.game_of_life.world[0][1].alive = True self.game_of_life.world[1][0].alive = True self.game_of_life.world[2][1].alive = True self.game_of_life.next_round() self.assertTrue(self.game_of_life.world[1][1].alive) def test_dead_cell_with_exactly_three_live_neighbours_becomes_a_live_cell(self): self.game_of_life.world[0][1].alive = True self.game_of_life.world[1][0].alive = True self.game_of_life.world[2][1].alive = True self.game_of_life.next_round() self.assertTrue(self.game_of_life.world[1][1].alive)
class TestOverCrowding(unittest.TestCase): def setUp(self): self.game = GameOfLife(10) self.game.add_living_cell(1, 1) self.game.add_living_cell(2, 1) self.game.add_living_cell(3, 1) self.game.add_living_cell(1, 2) self.game.add_living_cell(3, 2) self.game.add_living_cell(1, 3) self.game.add_living_cell(2, 3) self.game.add_living_cell(3, 3) self.game.add_living_cell(4, 4) def test_that_live_cell_more_then_3_neighbours_dies(self): self.game.add_living_cell(2, 2) self.assertEqual(self.game.is_alive(2, 2), True) self.assertEqual(self.game.neighbours_count(2, 2), 8) self.game.evolve() self.assertEqual(self.game.is_alive(2, 2), False)
# ----------------------------------------------- # Author: Hany Hamed # Description: This is the main file for the user of the game # ----------------------------------------------- from GameOfLife import GameOfLife g = GameOfLife((75, 75)) g.random() g.game_gui()
def setUp(self): self.game = GameOfLife(5) self.game.add_living_cell(1, 2) self.game.add_living_cell(2, 2) self.game.add_living_cell(1, 2)
def test_that_neighbours_count_is_0(self): self.game = GameOfLife(10) self.assertEqual(self.game.neighbours_count(1, 2), 0) self.assertEqual(self.game.neighbours_count(2, 2), 0) self.assertEqual(self.game.neighbours_count(3, 2), 0) self.assertEqual(self.game.neighbours_count(4, 2), 0)
def blinker(): game = GameOfLife(6) game.add_living_cell(3, 2) game.add_living_cell(3, 3) game.add_living_cell(3, 4) return game
def Clear_Clicked(self, widget, data = None): self.__GOL = GameOfLife(self.__Width,self.__Height,self.__Wrap,None) self.__GOL.resetGenerations() self.updateStrings() self.drawField(self.Teiknibord) return True
class GameOfLifeGUI: '''This is a class which creates a GUI for the GameOfLife. It should be created with GameOfLifeGUI(GOL) where GOL is a GameOfLife, and then run with while(GUI.Running): gtk.main_iteration(True) if gtk.events_pending(): continue if(GUI.Play): GUI.tick() time.sleep(1/float(GUI.PlaySpeed*5)) ''' MaxWidth = 500 MaxHeight = 300 condition = Condition() FieldIsNew = False __Pollrate = 200 __Born = [] __Survives = [] __pixmap = None __GOL = None __gladeskjal = 'GameOfLifeGUI.glade' Play = False __Width, __Height = 7,7 __Wrap = False __DrawX, __DrawY, __DrawH, __DrawW = 0,0,0,0 PlaySpeed = 2.5 Running = True __Grid = True __gcGrid = None __gcCells = None __gcBackground = None __Color = None #Litur frumnanna __GridColor = None #Litur nets __BackgroundColor = None #Litur bakgrunns filename = None #Nafn skjals #Kallad a thegar glugganum er lokad. Hofum gtk.main_quit() ef klasinn skyldi vera keyrdur med gtk.main() def on_window_destroy (self, widget, data = None): self.Running = False try: gtk.main_quit() except RuntimeError: pass return True #Kallad a thegar hradanum er breytt, og uppfyllir skilyrdid um ad hrada a hermun def Speed_ValueChange(self,widget,data = None): self.PlaySpeed = self.Speed.get_value() #Kveikir og slekkur a Wrappinu, thad er ad allir endarnir eru tengdir vid byrjun sina #Kallad a thegar ytt er a wrap takkann def Wrap_toggled(self, widget, data = None): self.__Wrap = not self.__Wrap self.__GOL.setWrap(self.__Wrap) self.updateStrings() return True #Kveikir og slekkur a linum def Grid_Toggle(self, widget, data = None): self.__Grid = not self.__Grid self.drawField(self.Teiknibord) return True #Kallad a til ad fa nuverandi hrada. def getSpeed(self): return self.PlaySpeed #Tokum inn stadsetningu og breytum thar hvort fruman se lifandi eda daud. #Uppfyllir skilyrdid um ad teikna frumur def changeCell(self,xin,yin): jin = xin/float(self.__DrawW) * self.__Width iin = yin/float(self.__DrawH) * self.__Height self.__GOL.changeCell(int(iin),int(jin)) return True #Fall til ad teikna myndina af frumunum def drawField(self,widget): if not self.__gcGrid: self.__gcGrid = widget.window.new_gc() self.__gcGrid.set_rgb_fg_color(gtk.gdk.color_parse(self.__GridColor)) if not self.__gcCells: self.__gcCells = widget.window.new_gc() self.__gcCells.set_rgb_fg_color(gtk.gdk.color_parse(self.__Color)) if not self.__gcBackground: self.__gcBackground = widget.window.new_gc() self.__gcBackground.set_rgb_fg_color(gtk.gdk.color_parse(self.__BackgroundColor)) width = self.__DrawW/float(self.__Width) height = self.__DrawH/float(self.__Height) self.__pixmap.draw_rectangle(self.__gcBackground,True,0,0,self.__DrawW, self.__DrawH) Keys = self.__GOL.getGOLKeys() for key in Keys: i,j = key self.__pixmap.draw_rectangle(self.__gcCells, True,int(j*width),int(i*height),int(width),int(height)) for i in range(self.__Height): if self.__Grid: self.__pixmap.draw_line(self.__gcGrid,0,int(i*height),self.__DrawW,int(i*height)) for j in range(self.__Width): if self.__Grid: self.__pixmap.draw_line(self.__gcGrid,int(j*width),0,int(j*width),self.__DrawH) self.Teiknibord.queue_draw_area(self.__DrawX, self.__DrawY, self.__DrawW, self.__DrawH) #Finnum ut hvar var ytt a myndina og uppfaerum tha frumu #Kallad a thegar ytt er a takka a myndinni def mouseButtonPressed(self, widget, event): self.changeCell( int(event.x), int(event.y)) self.drawField(widget) return True #Keyrt thegar ramma er breytt og i fyrsta skipti til ad upphafsstilla breytur. Configure_event signals vidbrogd def fieldChanged(self, widget, event): #Upphafsstillum self.__DrawX, self.__DrawY,self.__DrawW,self.__DrawH = widget.get_allocation() self.__pixmap = gtk.gdk.Pixmap(widget.window, self.__DrawW, self.__DrawH) self.__pixmap.draw_rectangle(widget.get_style().white_gc,True,0,0,self.__DrawW, self.__DrawH) widget.queue_draw_area(self.__DrawX,self.__DrawY,self.__DrawW,self.__DrawH) self.drawField(self.Teiknibord) return True #Spilum eina umferd af Game of Life. #Uppfyllir skilyrdid um ad herma eftir. def tick(self): self.__GOL.play() self.Gens.set_text(str(self.__GOL.getGenerations())) self.drawField(self.Teiknibord) # Expose_event signals vidbrogd sem teiknar rammann i upphafi def reDraw(self, widget, event): x,y,width,height = event.area self.__DrawX, self.__DrawY,self.__DrawW,self.__DrawH = event.area widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL],self.__pixmap, x,y,x,y,width,height) return False #Breytum fylkinu, svaedinu og reglunum okkar. Keyrt thegar ytt er a set takkann. #Uppfyllir skilyrdunum um ad geta breytt reglum leiksvaedis, og einnig staerd thess. def Set_Clicked(self, widget, data = None): a = self.WidthText.get_text() b = self.HeightText.get_text() changed = False #Max = 1000000 #Hann raedur vid thad, en thad sest ekki i individual frumur. Max = 500 if not (re.match('\\d+',a) and re.match('\\d+',b)) : print 'Sla verdur inn tolur' return if(self.__Width != int(a)): if int(a) in range(1,self.MaxWidth): self.__Width = int(a) changed = True elif int(a) >= self.MaxWidth: self.__Width = self.MaxWidth; changed = True if(self.__Height != int(b)): if int(b) in range(1,self.MaxHeight): self.__Height = int(b) changed = True elif int(b) >= self.MaxHeight: self.__Height = self.MaxHeight; changed = True if(changed): self.__GOL = GameOfLife(self.__Width,self.__Height,self.__Wrap,None) self.__GOL.setBS(self.BornText.get_text(),self.SurvivesText.get_text()) self.__Born, self.__Survives = self.__GOL.Born, self.__GOL.Survives self.updateStrings() self.drawField(self.Teiknibord) return True #Keyrt thegar ytt er a clear takkann. Hreinsar svaedid. def Clear_Clicked(self, widget, data = None): self.__GOL = GameOfLife(self.__Width,self.__Height,self.__Wrap,None) self.__GOL.resetGenerations() self.updateStrings() self.drawField(self.Teiknibord) return True #Lokar Open glugganum. def Cancel_Open_Clicked(self,widget,data = None): self.OpenDial.hide() return True #Opnar nytt skjal def Open_Clicked(self, widget, data = None): self.filename = self.OpenDial.get_filename() if self.filename: self.__GOL.openPattern(self.filename) self.__Born, self.__Survives = self.__GOL.Born, self.__GOL.Survives self.__Width, self.__Height = self.__GOL.width, self.__GOL.height self.__Wrap = self.__GOL.Wrap self.__GOL.resetGenerations() self.updateStrings() self.drawField(self.Teiknibord) self.OpenDial.hide() return True #Opnar Open gluggann def Open_Menu_Clicked(self, widget, data = None): self.OpenDial.show_all() return True #Save-ar fra menuinum def Save_Menu_Clicked(self, widget, data = None): self.__GOL.savePattern(self.filename) return True #Opnar save gluggann def Save_As_Menu_Clicked(self, widget, data = None): self.SaveDial.show_all() self.SaveDial.set_current_name(self.filename.split('.rle')[0] + ' - Copy') return True #Lokar Save glugganum def Cancel_Save_Clicked(self, widget, data = None): self.SaveDial.hide() return True #Save-ar skjalid def Save_Clicked(self, widget, data = None): filename = self.SaveDial.get_filename() filename = filename.rsplit('.rle')[0] + '.rle' if filename: self.__GOL.savePattern(filename) self.filename = filename self.updateStrings() self.SaveDial.hide() return True #Lokar about glugganum def Close_About(self, widget, data =None): self.About.hide() return True #Opnar about gluggann def About_Clicked(self, widget, data = None): self.About.show_all() return True #Til ad opna velja lit glugga. def Change_Cell_Color_Menu_Clicked(self, widget, data = None): self.Cell_Color.show_all() self.Cell_Color_Sel.set_current_color(gtk.gdk.Color(self.__Color)) return True #Til thess ad velja lit a frumum def Cell_Color_Choose(self, widget, data = None): self.__Color = self.Cell_Color_Sel.get_current_color().to_string() self.Cell_Color.hide() self.drawField(self.Teiknibord) return True #Til ad loka velja lit glugga def Cell_Color_Close(self, widget, data = None): self.Cell_Color.hide() return True #Til opna velja lit glugga. def Change_Background_Color_Menu_Clicked(self, widget, data = None): self.Background_Color.show_all() self.Background_Color_Sel.set_current_color(gtk.gdk.Color(self.__BackgroundColor)) return True #Til ad velja lit a bakgrunni def Background_Color_Choose(self, widget, data = None): self.__BackgroundColor = self.Background_Color_Sel.get_current_color().to_string() self.Background_Color.hide() self.drawField(self.Teiknibord) return True #Til ad loka velja lit glugga def Background_Color_Close(self, widget, data = None): self.Background_Color.hide() return True #Til opna velja lit glugga. def Change_Grid_Color_Menu_Clicked(self, widget, data = None): self.Grid_Color.show_all() self.Grid_Color_Sel.set_current_color(gtk.gdk.Color(self.__GridColor)) return True #Til ad velja lit a linum def Grid_Color_Choose(self, widget, data = None): self.__GridColor = self.Grid_Color_Sel.get_current_color().to_string() self.Grid_Color.hide() self.drawField(self.Teiknibord) return True #Til ad loka velja lit glugga def Grid_Color_Close(self, widget, data = None): self.Grid_Color.hide() return True #Keyrt thegar ytt er a Play/Stop takkann. Breytir thvi hvort verid er ad spila leikinn eda ekki. Viljum breyta fieldinu i byrjun til ad fordast hikst. def Play_toggled(self, widget, data = None): self.Play = not self.Play if(self.Play): self.PlayButton.set_label('Stop') else: self.PlayButton.set_label('Play') self.fieldChanged(self.Teiknibord,'configure_event') return True #Getum breytt hamarks og lagmarks hrada, og hamark haed og breidd. def SetMinSpeed_Clicked(self, widget, data = None): p = float(self.MinSpeedBox.get_text()) if p > 0: self.Speed.set_lower(p) else: self.Speed.set_lower(0.1) self.MinSpeedBox.set_text('0.1') if self.Speed.get_value() < p: self.Speed.set_value(p) def SetMaxHeight_Clicked(self, widget, data = None): p = int(self.MaxHeightBox.get_text()) if p > 0: self.MaxHeight = p else: self.MaxHeight = 1 self.MaxHeightBox.set_text(str(1)) if self.__Height > self.MaxHeight: self.HeightText.set_text(str(self.MaxWidth)) self.Set_Clicked(widget, data = None) def SetMaxWidth_Clicked(self, widget, data = None): p = int(self.MaxWidthBox.get_text()) if p > 0: self.MaxWidth = p else: self.MaxWidth = 1 self.MaxWidthBox.set_text(str(1)) if self.__Width > self.MaxWidth: self.WidthText.set_text(str(self.MaxWidth)) self.Set_Clicked(widget, data = None) def SetMaxSpeed_Clicked(self, widget, data = None): p = float(self.MaxSpeedBox.get_text()) if p > 0: self.Speed.set_upper(p) else: self.Speed.set_upper(50) self.MaxSpeedBox.set_text('50') if self.Speed.get_value() > p: self.Speed.set_value(p) #Til ad breyta hve oft er tjekkad a vidmoti def getPollrate(self): return self.__Pollrate def updatePollrate(self, widget, data = None): p = int(self.Pollbox.get_text()) if p > 0: self.__Pollrate = p else: self.__Pollrate = 1 self.Pollbox.set_text('1') #Valmoguleikar def closeSettings(self, widget, data = None): self.Settings.hide() return True def Settings_Menu(self, widget, data = None): self.Settings.show_all() self.Pollbox.set_text(str(self.__Pollrate)) self.MinSpeedBox.set_text(str(self.Speed.get_lower())) self.MaxSpeedBox.set_text(str(self.Speed.get_upper())) self.MaxHeightBox.set_text(str(self.MaxHeight)) self.MaxWidthBox.set_text(str(self.MaxWidth)) #Notum til ad geta keyrt forritid class Simulator(Process): def run(self,GUI): if gtk.gdk.event_peek() is gtk.gdk.MOTION_NOTIFY or not gtk.gdk.events_pending(): GUI.condition.acquire() GUI.Simulate() GUI.FieldIsNew = True GUI.condition.release() def Simulate(self): self.__GOL.play() class Waiter(Process): def run(self,GUI): GUI.condition.acquire() speed = GUI.getSpeed() pollrate = GUI.getPollrate() for i in range(pollrate): if gtk.gdk.event_peek() is not gtk.gdk.MOTION_NOTIFY: if gtk.events_pending(): GUI.condition.release() while gtk.events_pending(): gtk.main_iteration(False) GUI.condition.acquire() speed = GUI.getSpeed() time.sleep((1/float(speed*pollrate*5))) i += 1 if not gtk.events_pending() or gtk.gdk.event_peek() is None : GUI.condition.release() #Uppfaerir mynd og generations eftir ad umferd hefur verid spilur class Updater(Process): def run(self, GUI): if GUI.FieldIsNew: GUI.condition.acquire() GUI.updateAfterPlay() GUI.condition.release() def updateAfterPlay(self): self.Gens.set_text(str(self.__GOL.getGenerations())) self.drawField(self.Teiknibord) self.FieldIsNew = False #Viljum ad thad standi rett i kossunum svo folk geti vitad hve stadan er nuna. def updateStrings(self): self.WidthText.set_text(str(self.__Width)) self.HeightText.set_text(str(self.__Height)) self.Gens.set_text(str(self.__GOL.getGenerations())) BornString = '' for t in self.__Born: BornString += str(t) SurvivesString = '' for t in self.__Survives: SurvivesString += str(t) if(self.__Wrap): self.WrapLabel.set_text('On') else: self.WrapLabel.set_text('Off') self.BornText.set_text(BornString) self.SurvivesText.set_text(SurvivesString) string = "Game of Life - " + self.filename self.Window.set_title(string) # Smidurinn okkar def __init__(self,GameOfL): global GOL self.__GOL = GameOfL self.__Width, self.__Height, self.__Wrap, self.__Born, self.__Survives = self.__GOL.width, self.__GOL.height, self.__GOL.Wrap, self.__GOL.Born, self.__GOL.Survives #Setjum glade skjalid self.builder = gtk.Builder() self.gladefile = self.__gladeskjal with warnings.catch_warnings(): warnings.simplefilter("ignore") self.builder.add_from_file(self.gladefile) #Skilgreinum hlutina okkar sem vid notum i follunum self.Window = self.builder.get_object("Gluggi") self.Teiknibord = self.builder.get_object("Teiknibord") self.WidthText = self.builder.get_object('WidthT') self.HeightText = self.builder.get_object('HeightT') self.PlayButton = self.builder.get_object('Play') self.WrapLabel = self.builder.get_object('WrapL') self.Gens = self.builder.get_object('Generations') self.BornText = self.builder.get_object('Born') self.SurvivesText = self.builder.get_object('Survives') self.OpenDial = self.builder.get_object('OpenPattern') self.About = self.builder.get_object('About') self.SaveDial = self.builder.get_object('SavePattern') self.Cell_Color = self.builder.get_object('CellColor') self.Cell_Color_Sel = self.builder.get_object('CellColorSel') self.Background_Color = self.builder.get_object('BackgroundColor') self.Background_Color_Sel = self.builder.get_object('BackgroundColorSel') self.Grid_Color = self.builder.get_object('GridColor') self.Grid_Color_Sel = self.builder.get_object('GridColorSel') self.Pollbox = self.builder.get_object('Pollrater') self.Settings = self.builder.get_object('Settings') self.__Pollrate = 200 self.MinSpeedBox = self.builder.get_object('MinSpeedBox') self.MaxSpeedBox = self.builder.get_object('MaxSpeedBox') self.MaxHeightBox = self.builder.get_object('MaxHeightBox') self.MaxWidthBox = self.builder.get_object('MaxWidthBox') self.__Color = '#00FF00' #Litur frumunnar self.__GridColor = '#2F2F2F' #Litur Gridsins self.__BackgroundColor = '#000000'#Litur bakgrunnsins if(self.__Wrap): self.WrapLabel.set_text('On') else: self.WrapLabel.set_text('Off') self.Speed = self.builder.get_object('Speed') self.condition = Condition() self.Teiknibord.show() self.__Grid = True self.filename = "Default.rle" self.Window.set_title("Game of Life") gtk.Widget.show_all(self.Window) self.updateStrings() #og ad hafa keyrt allavegana eitt configure_event self.fieldChanged(self.Teiknibord,'configure_event') self.builder.connect_signals(self)
def test_that_neighbours_count_is_1(self): self.game = GameOfLife(10) self.assertEqual(self.game.neighbours_count(1, 2), 0) self.game.add_living_cell(0, 0) self.assertEqual(self.game.neighbours_count(1, 0), 1)
self.__Grid = True self.filename = "Default.rle" self.Window.set_title("Game of Life") gtk.Widget.show_all(self.Window) self.updateStrings() #og ad hafa keyrt allavegana eitt configure_event self.fieldChanged(self.Teiknibord,'configure_event') self.builder.connect_signals(self) if __name__ == "__main__": GOL = GameOfLife(50, 30,False, None) ##ToffMunstur til ad byrja med GOL.openPattern('Default.rle') GUI = GameOfLifeGUI(GOL) p, g = None, None #Thad er ekki haegt ad hafa thetta i thradum/processum, thvi badir thurfa ad keyra gtk.main_iteration til ad nota vidmotid/teikna g = Process(target = gtk.main_iteration, args = (False,)) w = GUI.Waiter() s = GUI.Simulator() u = GUI.Updater() gtk.gdk.threads_init() gtk.gdk.threads_enter() while(GUI.Running): while gtk.events_pending(): g.run()
import GameOfLife.GameOfLife import textbox GameOfLife.main()
def testCreateNewGenerationEmpty(self): game = GameOfLife(0, 0, [[]], 2) self.assertEqual(game.createNewGeneration(), False)
class TestGameOfLife(unittest.TestCase): def setUp(self): self.gameValidateEnum = GameOfLife(2, 2, [['.', '*'], ['*', '.']], 3) self.gameValidateCountNeighbours = GameOfLife( 2, 3, [['.', '.', '.'], ['*', '.', '*']], 3) self.gameValidateNeighbours = GameOfLife( 4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '*', '.', '.', '.'], ['.', '.', '.', '*', '*', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 2) self.validateKillToReviveCell = GameOfLife( 3, 2, [['.', '*'], ['.', '.'], ['*', '.']], 2) def testEnumDeadCellMatrix(self): self.assertEqual(self.gameValidateEnum.matrix[0][0], Cell.DEAD_CELL) def testEnumLivingCellMatrix(self): self.assertEqual(self.gameValidateEnum.matrix[0][1], Cell.LIVING_CELL) def testCountNeighbours(self): self.assertEqual( self.gameValidateCountNeighbours.countNeighbours([(0, 0), (0, 1), (1, 0)]), (1, 2)) def testCountNeighbours2(self): self.assertNotEqual( self.gameValidateCountNeighbours.countNeighbours([(0, 0), (0, 1), (1, 0)]), (0, 2)) def testCountNeighboursEmpty(self): self.assertEqual(self.gameValidateCountNeighbours.countNeighbours([]), (0, 0)) def testValidateNeighbours(self): self.assertEqual(self.gameValidateNeighbours.validateNeighbours(1, 3), (3, 5)) def testValidateNeighboursBoundaries1(self): self.assertEqual(self.gameValidateNeighbours.validateNeighbours(0, 0), (0, 3)) def testValidateNeighboursBoundaries2(self): self.assertEqual(self.gameValidateNeighbours.validateNeighbours(3, 0), (0, 3)) def testValidateNeighboursBoundaries3(self): self.assertNotEqual( self.gameValidateNeighbours.validateNeighbours(0, 7), (1, 3)) def testValidateNeighboursBoundaries4(self): self.assertNotEqual( self.gameValidateNeighbours.validateNeighbours(3, 7), (1, 0)) def testkillCell(self): self.validateKillToReviveCell.killCell(0, 1) self.assertEqual(self.validateKillToReviveCell.matrix[0][1], Cell.DEAD_CELL) def testkillCellThatIsDead(self): self.validateKillToReviveCell.killCell(0, 0) self.assertNotEqual(self.validateKillToReviveCell.matrix[0][0], Cell.LIVING_CELL) def testToReviveCell(self): self.validateKillToReviveCell.toReviveCell(2, 1) self.assertEqual(self.validateKillToReviveCell.matrix[2][1], Cell.LIVING_CELL) def testToReviveCellThatIsLife(self): self.validateKillToReviveCell.toReviveCell(2, 0) self.assertNotEqual(self.validateKillToReviveCell.matrix[2][0], Cell.DEAD_CELL) def testCreateNewGeneration(self): game = GameOfLife(4, 8, [['*', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '*', '.', '.', '.'], ['.', '.', '.', '*', '*', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 2) self.assertEqual(game.createNewGeneration(), True) def testCreateNewGenerationFalse(self): game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 4) self.assertEqual(game.createNewGeneration(), False) def testCreateNewGenerationNotEqual(self): game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '*', '*', '.', '.', '.'], ['.', '.', '.', '*', '*', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 3) self.assertNotEqual(game.createNewGeneration(), True) def testCreateNewGenerationEmpty(self): game = GameOfLife(0, 0, [[]], 2) self.assertEqual(game.createNewGeneration(), False) def testGetGenerations(self): game = GameOfLife(4, 8, [['.', '*', '.', '.', '.', '.', '.', '*'], ['.', '.', '.', '.', '*', '.', '.', '.'], ['.', '.', '.', '*', '*', '.', '.', '.'], ['.', '.', '.', '.', '.', '*', '.', '.']], 4) self.assertEqual(game.getGenerations(), 3) def testGetGenerations2(self): game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '*', '.', '.', '.'], ['.', '.', '.', '*', '*', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 4) self.assertEqual(game.getGenerations(), 2) def testGetGenerations3(self): game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 5) self.assertEqual(game.getGenerations(), 1)
class TestReproduction(unittest.TestCase): def setUp(self): self.game = GameOfLife(10) self.game.add_living_cell(1, 1) self.game.add_living_cell(2, 1) self.game.add_living_cell(3, 1) self.game.add_living_cell(1, 2) self.game.add_living_cell(3, 2) self.game.add_living_cell(1, 3) self.game.add_living_cell(2, 3) self.game.add_living_cell(3, 3) self.game.add_living_cell(4, 4) def test_that_dead_cell_3_neighbours_becomes_alive(self): self.assertEqual(self.game.is_alive(4, 2), False) self.assertEqual(self.game.neighbours_count(4, 2), 3) self.game.evolve() self.assertEqual(self.game.is_alive(4, 2), True) def test_that_dead_cell_without_3_neighbours_stays_dead(self): self.game.add_living_cell(4, 3) self.assertEqual(self.game.is_alive(4, 2), False) self.assertEqual(self.game.neighbours_count(4, 2), 4) self.game.evolve() self.assertEqual(self.game.is_alive(4, 2), False)
def testCreateNewGenerationFalse(self): game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 4) self.assertEqual(game.createNewGeneration(), False)
#ask user for patterns to select from with open('initial_patterns_file.json', 'r') as initial_patterns_file: patterns = json.load(initial_patterns_file) with open("config.json", 'r') as configuration_file: conifurations = json.load(configuration_file) load_pattern = input( "Do you want to Select a pattern of load a default Pattern(y/n) : ") if (load_pattern == 'y' or load_pattern == 'Y' or load_pattern == "yes" or load_pattern == "Yes"): for pattern_key in patterns.keys(): print("Pattern key : ", pattern_key) display_buffer(np.array(patterns[pattern_key])) selected_pattern_key = ( input("Enter the Pattern Key to initialize : ")) selected_pattern = np.array(patterns[selected_pattern_key]) else: selected_pattern = np.array(patterns[ conifurations['default_model']]) #deafault pattern to start from gameOfLife = GameOfLife() gameOfLife.setBoardSize(conifurations['board_size']) gameOfLife.setDelay(conifurations['delay']) gameOfLife.setBlankPixel(conifurations['blank_pixel']) gameOfLife.setLivePixel(conifurations['live_pixel']) gameOfLife.setPadding(conifurations['left_pad'], conifurations['left_pad']) gameOfLife.setPattern(selected_pattern) gameOfLife.live()
class TestNeighboursCount(unittest.TestCase): def setUp(self): self.game = GameOfLife(5) self.game.add_living_cell(1, 2) self.game.add_living_cell(2, 2) self.game.add_living_cell(1, 2) def test_that_neighbours_count_is_0(self): self.game = GameOfLife(10) self.assertEqual(self.game.neighbours_count(1, 2), 0) self.assertEqual(self.game.neighbours_count(2, 2), 0) self.assertEqual(self.game.neighbours_count(3, 2), 0) self.assertEqual(self.game.neighbours_count(4, 2), 0) def test_that_neighbours_count_is_1(self): self.game = GameOfLife(10) self.assertEqual(self.game.neighbours_count(1, 2), 0) self.game.add_living_cell(0, 0) self.assertEqual(self.game.neighbours_count(1, 0), 1) def test_that_neighbours_count_is_2(self): self.game.add_living_cell(0, 2) self.assertEqual(self.game.neighbours_count(1, 2), 2) def test_that_neighbours_count_is_3(self): self.game.add_living_cell(0, 3) self.assertEqual(self.game.neighbours_count(1, 3), 3) def test_that_neighbours_count_is_8(self): self.game.add_living_cell(1, 1) self.game.add_living_cell(2, 1) self.game.add_living_cell(3, 1) self.game.add_living_cell(1, 2) self.game.add_living_cell(3, 2) self.game.add_living_cell(1, 3) self.game.add_living_cell(2, 3) self.game.add_living_cell(3, 3) self.assertEqual(self.game.neighbours_count(2, 2), 8)
def setUp(self): self.game_of_life = GameOfLife(world_size=10)
class TestDrawMatrix(unittest.TestCase): def setUp(self): self.game = GameOfLife(10) self.game.add_living_cell(1, 1) self.game.add_living_cell(2, 1) self.game.add_living_cell(3, 1) self.game.add_living_cell(1, 2) self.game.add_living_cell(3, 2) self.game.add_living_cell(1, 3) self.game.add_living_cell(2, 3) self.game.add_living_cell(3, 3) self.game.add_living_cell(4, 4)
import time import numpy as np from GameOfLife import GameOfLife if __name__ == "__main__": #game = GameOfLife(x=10, y=10, starting_elements=50, wrap_grid=True) game = GameOfLife(wrap_grid=True) # game.from_grid(np.array([ # [0,0,1,0,0,0,0], # [1,0,1,0,0,0,0], # [0,1,1,0,0,0,0], # [0,0,0,0,0,0,0], # [0,0,0,0,0,0,0], # [0,0,0,0,0,0,0], # [0,0,0,0,0,0,0], # ])) game.from_params(10, 10) game.display_ascii_grid() for i in range(100): print("------------") game.iterate() game.display_ascii_grid() time.sleep(0.8)
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. ## import sys from PyQt5.QtWidgets import QApplication # pip install PyQt5 from GameOfLife import GameOfLife from GolLoop import GolLoop from MainWindow import MainWindow qdark_present = True try: import qdarkstyle # Qt styling package, pip install qdarkstyle except ImportError: qdark_present = False if __name__ == '__main__': gol = GameOfLife() # The model timer = GolLoop() # The game loop timer.timeout.connect(gol.next) app = QApplication(sys.argv) if qdark_present: app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) window = MainWindow(gol, timer) # The view controller / view (GUI) sys.exit(app.exec_())
def setUp(self): self.game = GameOfLife() self.game.generateBoard()
def test_can_create_an_empty_grid(self): game = GameOfLife(width=3, height=3, cell_size=1) clist = game.cell_list(randomize=False) self.assertEqual([[0, 0, 0], [0, 0, 0], [0, 0, 0]], clist)
class TestLiveCellThatLivesForNextGeneration(unittest.TestCase): def setUp(self): self.game = GameOfLife(10) self.game.add_living_cell(1, 1) self.game.add_living_cell(2, 1) self.game.add_living_cell(3, 1) self.game.add_living_cell(1, 2) self.game.add_living_cell(3, 2) self.game.add_living_cell(1, 3) self.game.add_living_cell(2, 3) self.game.add_living_cell(3, 3) self.game.add_living_cell(4, 4) def test_that_live_cell_with_two_neighbour_dosent_die(self): self.game.add_living_cell(4, 5) self.assertEqual(self.game.neighbours_count(4, 4), 2) self.assertEqual(self.game.is_alive(4, 4), True) self.game.evolve() self.assertEqual(self.game.is_alive(4, 4), True) def test_that_live_cell_with_3_neighbour_dosent_die(self): self.game.add_living_cell(4, 5) self.game.add_living_cell(4, 3) self.assertEqual(self.game.neighbours_count(4, 4), 3) self.assertEqual(self.game.is_alive(4, 4), True) self.game.evolve() self.assertEqual(self.game.is_alive(4, 4), True)
def test_can_create_a_random_grid(self): game = GameOfLife(width=3, height=3, cell_size=1) random.seed(12345) clist = game.cell_list(randomize=True) self.assertEqual([[1, 0, 1], [1, 0, 1], [1, 0, 1]], clist)
class TestUnderPopulation(unittest.TestCase): def setUp(self): self.game = GameOfLife(10) self.game.add_living_cell(1, 1) self.game.add_living_cell(2, 1) self.game.add_living_cell(3, 1) self.game.add_living_cell(1, 2) self.game.add_living_cell(3, 2) self.game.add_living_cell(1, 3) self.game.add_living_cell(2, 3) self.game.add_living_cell(3, 3) self.game.add_living_cell(4, 4) def test_that_live_cell_with_no_neighbour_dies(self): self.game.add_living_cell(9, 9) self.assertEqual(self.game.is_alive(9, 9), True) self.assertEqual(self.game.neighbours_count(9, 9), 0) self.game.evolve() self.assertEqual(self.game.is_alive(9, 9), False) def test_that_live_cell_with_one_neighbour_dies(self): self.assertEqual(self.game.is_alive(4, 4), True) self.assertEqual(self.game.neighbours_count(4, 4), 1) self.game.evolve() self.assertEqual(self.game.is_alive(4, 4), False)
def test_get_neighbours(self): game = GameOfLife(width=self.width, height=self.height, cell_size=1) game.clist = self.clist neighbours = game.get_neighbours((2, 3)) self.assertEqual(8, len(neighbours)) self.assertEqual(4, sum(neighbours))
import GameOfLife.GameOfLife import textbox GameOfLife.main ()
def test_get_neighbours_for_lower_right_corner(self): game = GameOfLife(width=self.width, height=self.height, cell_size=1) game.clist = self.clist neighbours = game.get_neighbours((5, 7)) self.assertEqual(3, len(neighbours)) self.assertEqual(1, sum(neighbours))
def testGetGenerations3(self): game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 5) self.assertEqual(game.getGenerations(), 1)
import pygame from GameOfLife import GameOfLife # game = GameOfLife(*(20, 20), height=640) # print(list(map(print, game.curr_generation))) # print(game.get_neighbours((1, 1))) # game.is_max_generations_exceeded game1 = GameOfLife.from_file('./patterns/72p6h2v0.cells.txt', max_generations=100) game1.run() game2 = GameOfLife.from_file('./patterns/55p9h3v0.cells.txt', max_generations=100) game2.run() game3 = GameOfLife.from_file('./patterns/achimsp11.cells.txt', max_generations=100) # game3.save('./patterns/test.cells.txt') game3.run() # game4 = GameOfLife.from_file('./patterns/5enginecordership.cells.txt', max_generations=100) # # # game4.play_pause() # game4.run() game5 = GameOfLife.from_file('./patterns/ak94.cells.txt', max_generations=500) game5.run() game6 = GameOfLife.from_file('./patterns/94p27.1.cells.txt') game6.run()
def setUp(self): self.game = GameOfLife(5, 5)
def runAliveCellsTest(self, coordinates, aliveCellsNumber): gameOfLife = GameOfLife(coordinates) new_cells = gameOfLife.evolve() self.assertEquals(aliveCellsNumber, len(new_cells)) return new_cells
def testCreateNewGenerationNotEqual(self): game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '*', '*', '.', '.', '.'], ['.', '.', '.', '*', '*', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 3) self.assertNotEqual(game.createNewGeneration(), True)
resolution = (800, 800) board_size = 20 gaps = 1 time_per_col = .25 LIVING_CELL_COLORS = MAT_ORANGE MUSIC_NOTE_COLOR = MAT_AMBER DEAD_CELL_COLORS = BLUE_GREY GRID_COLOR = BLUE_GREY HIGHLIGHT_COLOR = BLUE_GREY_HIGH # Global initialization pygame.init() pygame.display.set_caption("The Music of Life") DISPLAYSURF = pygame.display.set_mode(resolution, RESIZABLE) the_grid = SquareGridUI(DISPLAYSURF, board_size, resolution[0], gaps) the_game = GameOfLife(board_size, board_size) the_game.random_grid_init() audio = LifeAudio() current_column = 0 column_dir = 1 current_row = 0 row_dir = 1 paused = False def toggle_pause(): global paused paused = not paused def increase_speed(): global time_per_col