Esempio n. 1
0
    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)
Esempio n. 2
0
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
Esempio n. 4
0
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_())
Esempio n. 5
0
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)
Esempio n. 6
0
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()
Esempio n. 7
0
    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)
Esempio n. 8
0
 def testCreateNewGenerationNotEqual(self):
     game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'],
                              ['.', '.', '.', '*', '*', '.', '.', '.'],
                              ['.', '.', '.', '*', '*', '.', '.', '.'],
                              ['.', '.', '.', '.', '.', '.', '.', '.']], 3)
     self.assertNotEqual(game.createNewGeneration(), True)
Esempio n. 9
0
# -----------------------------------------------
# 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()
Esempio n. 10
0
 def testCreateNewGenerationFalse(self):
     game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'],
                              ['.', '.', '.', '.', '.', '.', '.', '.'],
                              ['.', '.', '.', '.', '.', '.', '.', '.'],
                              ['.', '.', '.', '.', '.', '.', '.', '.']], 4)
     self.assertEqual(game.createNewGeneration(), False)
Esempio n. 11
0
 def testCreateNewGenerationEmpty(self):
     game = GameOfLife(0, 0, [[]], 2)
     self.assertEqual(game.createNewGeneration(), False)
Esempio n. 12
0
 def testGetGenerations3(self):
     game = GameOfLife(4, 8, [['.', '.', '.', '.', '.', '.', '.', '.'],
                              ['.', '.', '.', '.', '.', '.', '.', '.'],
                              ['.', '.', '.', '.', '.', '.', '.', '.'],
                              ['.', '.', '.', '.', '.', '.', '.', '.']], 5)
     self.assertEqual(game.getGenerations(), 1)
Esempio n. 13
0
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)
Esempio n. 14
0
 def setUp(self):
     self.game = GameOfLife()
     self.game.generateBoard()
Esempio n. 15
0
 def setUp(self):
     self.game_of_life = GameOfLife(world_size=10)
Esempio n. 16
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_())
Esempio n. 17
0
## 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)
Esempio n. 20
0
 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))
Esempio n. 21
0
 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))
Esempio n. 22
0
 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)
Esempio n. 23
0
 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)