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 main(): gof = GameOfLife() try: gof.run() except Exception as e: traceback.print_exc(e) return -1
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
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_())
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 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 testCreateNewGenerationNotEqual(self): game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '*', '*', '.', '.', '.'], ['.', '.', '.', '*', '*', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 3) self.assertNotEqual(game.createNewGeneration(), True)
# ----------------------------------------------- # 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 testCreateNewGenerationFalse(self): game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 4) self.assertEqual(game.createNewGeneration(), False)
def testCreateNewGenerationEmpty(self): game = GameOfLife(0, 0, [[]], 2) self.assertEqual(game.createNewGeneration(), False)
def testGetGenerations3(self): game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']], 5) self.assertEqual(game.getGenerations(), 1)
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)
def setUp(self): self.game = GameOfLife() self.game.generateBoard()
def setUp(self): self.game_of_life = GameOfLife(world_size=10)
''' # 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_())
## 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_())
#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()
def weak_scaling(): for i in range(1, 11): gol = GameOfLife(1000, i * 500) gol.update_parallel(i)
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 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))
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)
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)