コード例 #1
0
    def setUp(self):
        # [[ 0,0 0,1 0,2  0,3 ] [1,0 1,1 1,2 1,3] .....]
        self.baseList = [['-', '-', '-', '-'],['-', '*', '*', '-'],\
                        ['-', '*', '*', '-'],['-', '-', '-', '-']]
        self.newList = self.baseList
        self.objseed = GameOfLife.Seed(self.baseList, self.newList, 2, 2)

        self.baseList1 = [['-', '-', '-', '-', '-'],['-', '-', '*', '-', '-']\
            ,['-', '-', '*', '-', '-'],['-', '-', '*', '-', '-'],\
            ['-', '-', '-', '-', '-']]
        self.newList1 = self.baseList1
        self.objseed1 = GameOfLife.Seed(self.baseList1, self.newList1, 3, 3)
コード例 #2
0
def game_setup():
    grid_x = int(entr1.get())
    grid_y = int(entr2.get())
    selected_pattern = comboBox.current()
    init_state = [[0 for x in range(0, grid_x)] for y in range(0, grid_y)]
    if selected_pattern == 0:  #glider
        init_state[2][2] = 1
        init_state[3][3] = 1
        init_state[4][3] = 1
        init_state[4][2] = 1
        init_state[4][1] = 1

    if selected_pattern == 1:  #oscillator
        init_state[3][4] = 1
        init_state[2][4] = 1
        init_state[1][4] = 1

    if selected_pattern == 2:  #still life
        init_state[1][4] = 1
        init_state[1][5] = 1
        init_state[3][4] = 1
        init_state[3][5] = 1
        init_state[2][3] = 1
        init_state[2][6] = 1

    if selected_pattern == 3:  #random
        init_state = [[np.random.randint(2) for x in range(0, grid_x)]
                      for y in range(0, grid_y)]

    gol = GameOfLife.GameOfLife(grid_x, grid_y, init_state)
    gol.game_of_life()
コード例 #3
0
ファイル: test.py プロジェクト: mfwils0n/GameOfLife
class Test(unittest.TestCase):
	##### Canary Test #####
	def test_canary_1(self):
		self.assertTrue(True)
	
	## Universe Tests ##
	u = GameOfLife.Universe(10, 11)

	def test_universe_init(self):
		self.assertEqual(self.u.width, 10)
		self.assertEqual(self.u.height, 11)

	def test_universe_build_grid(self):
		self.u.build_grid()
		self.assertEqual(self.u.grid, [[col+1 for col in range(10)] for row in range(11)])
コード例 #4
0
ファイル: playGameOfLife.py プロジェクト: daniloqb/gameoflife
#!/usr/bin/python
import GameOfLife as gol
from ConwayPatterns import *
import random


if __name__ == "__main__":


    game = gol.Game("Game of Life", (1024, 768))

    ConwayPatterns.fill_environment(game.environment)


    #for g in range(0,1000,5):
      #Patterns.glider((random.randint(0,g),g),random.randint(1,4),random.randint(1,4),game.environment)

    #Patterns.glider((10,10),1, 4, game.environment)
    #Patterns.glider((10,10),2, 1, game.environment)

    #ConwayPatterns.beacon((20, 20), 1, 2, game.environment)

    while game.running:

        game.event()
        game.update()
コード例 #5
0
#!/usr/bin/python3

import json
import GameOfLife as gol

if __name__ == '__main__':
    with open('config.json', encoding='utf-8') as config_file:
        config = json.loads(config_file.read())
    config['is_test'] = 1
    config['test_pattern'] = "Pulsar"
    gol.GameOfLife(config)
コード例 #6
0
from Game of Life import GameOfLife

game = GameOfLife()
game.run()
コード例 #7
0
ファイル: main.py プロジェクト: slubinga/classroom_code
def main():
    GameOfLife.GameOfLife()
コード例 #8
0
ファイル: GuiLogic.py プロジェクト: lothamersam/GameOfLife
class GuiLogic(object):
    GOL = GameOfLife.GameOfLife()  # Set up game logic
    DONE = False  # Loop until the user clicks the close button.
    ADVANCE = False
    BLACK = (0, 0, 0)  # Define some colors
    WHITE = (255, 255, 255)
    GREEN = (0, 255, 0)
    RED = (255, 0, 0)
    WIDTH = 15  # This sets the WIDTH and HEIGHT of each grid location
    HEIGHT = 15
    MARGIN = 2  # This sets the margin between each cell
    WINDOW_SIZE = []  # Set the HEIGHT and WIDTH of the SCREEN
    SCREEN = None
    CLOCK = pygame.time.Clock()  # Used to manage how fast the SCREEN updates

    def examineEvents(self):
        for event in pygame.event.get():  # User did something
            if event.type == pygame.QUIT:  # If user clicked close
                self.DONE = True  # Flag that we are DONE so we exit this loop

            elif event.type == pygame.MOUSEBUTTONDOWN:
                # User clicks the mouse. Get the position
                pos = pygame.mouse.get_pos()

                # Change the x/y SCREEN coordinates to grid coordinates
                column = pos[0] // (self.WIDTH + self.MARGIN)
                row = pos[1] // (self.HEIGHT + self.MARGIN)

                # Set that location to one
                self.GOL.board[column][row] = not (self.GOL.board[column][row])
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    self.ADVANCE = not (self.ADVANCE
                                        )  #Stop iterating generations
                if event.key == pygame.K_c:
                    self.clearBoard()

    def clearBoard(self):
        self.GOL.reset()

    def drawGrid(self):
        for row in range(self.GOL.B_HEIGHT):
            for column in range(self.GOL.B_WIDTH):
                color = self.WHITE
                if self.GOL.board[column][row] == 1:
                    color = self.BLACK
                pygame.draw.rect(
                    self.SCREEN, color,
                    [(self.MARGIN + self.WIDTH) * column + self.MARGIN,
                     (self.MARGIN + self.HEIGHT) * row + self.MARGIN,
                     self.WIDTH, self.HEIGHT])

    def mainLoop(self):
        time_since_last_gen = 0

        while not self.DONE:
            self.examineEvents()

            self.SCREEN.fill(self.BLACK)  # Set the SCREEN background
            self.drawGrid()  # Draw the grid

            dt = self.CLOCK.tick(60)  # Limit to 60 frames per second
            time_since_last_gen += dt  # Calculate millis seconds passed since last loop

            # If one second has passed move forward one generation
            if (time_since_last_gen > 500):
                if (self.ADVANCE):
                    self.GOL.nextGeneration()
                # Reset
                time_since_last_gen = 0

            # Go ahead and update the SCREEN with what we've drawn.
            pygame.display.flip()

        pygame.quit()

    def __init__(self):
        pygame.init()  # Initialize pygame
        pygame.display.set_caption(
            "Conways Game Of Life")  # Set title of SCREEN
        self.WINDOW_SIZE = [((self.WIDTH * self.GOL.B_WIDTH) +
                             (self.MARGIN * (self.GOL.B_WIDTH + 1))),
                            ((self.HEIGHT * self.GOL.B_HEIGHT) +
                             (self.MARGIN * (self.GOL.B_HEIGHT + 1)))]
        self.SCREEN = pygame.display.set_mode(self.WINDOW_SIZE)
コード例 #9
0
import Animation
import GameOfLife

__author__ = "CP-12GSP"
# Animation.main()
GameOfLife.main()
コード例 #10
0
#!/usr/bin/python
import GameOfLife as gof

import random
import time

if __name__ == "__main__":

    start_time = time.time()
    resolution = (100, 100)

    board = gof.Board(resolution)
    env = gof.Environment(resolution)

    #for x in range(3):
    #  for y in range(3):
    #    env.add_cell((x,y),1)

    gof.ConwayPatterns.glider((3, 3), 1, 1, env)

    board.update_screen(env.cells_map)
    env.check()
    #print env.show_live_cells_location()
    print time.time() - start_time

    env.update()

    board.update_screen(env.cells_map)
コード例 #11
0
from GameOfLife import *

game = GameOfLife(100, 100, 1000)
game.read_state_from_file("Ronaldo", red = True)
game.read_state_from_file("Messi", red = False)
game.update_display()
input("Press enter to continue")

while True:
    for _ in range(3):
        game.evolve()
        if game.red_has_won():
            game.update_display()
            game.display_result("red")
            input("Press enter to continue")
            exit()
        if game.black_has_won():
            game.update_display()
            game.display_result("black")
            input("Press enter to continue")
            exit()
        if game.tiebreaker_needed():
            game.update_display()
            game.display_result("tie")
            input("Press enter to continue")
            break
    game.update_display()

game.t = game.T
while True:
    game.seed_random_cells()
コード例 #12
0
 def test_middle(self):
     pair = (3, 7)
     expected = {(2, 6), (2, 7), (2, 8), (3, 6), (3, 8), (4, 6), (4, 7),
                 (4, 8)}
     actual = GameOfLife.find_neighbors(pair)
     self.assertEqual(actual, expected)
コード例 #13
0
 def test_corner(self):
     pair = (0, 0)
     expected = {(1, 0), (0, 1), (1, 1)}
     actual = GameOfLife.find_neighbors(pair)
     self.assertEqual(actual, expected)
コード例 #14
0
ファイル: Tijolo.py プロジェクト: tcvieira/Tijolo
    s.close()

elif (options.mode == "gol"):
    #s = serial.Serial('/dev/ttyS0', 115200)
    s = serial.Serial(Config.SERIAL_PORT, Config.SERIAL_BAUD_RATE, dsrdtr=True)
    s.open()
    turn = 0
    if not options.wall:
        grid = Bricks.build_grid(options.x, options.y)
        while True:
            brick_list = Bricks.build_bricklist(options.x, options.y, grid)
            Bricks.sendserial(brick_list, s)
            turn = turn + 1
            print "geracao ", turn
            time.sleep(0.05)
            grid = GameOfLife.update(grid, options.x, options.y, turn)
    else:
        print "modo wall"
        grid = Bricks.build_grid_wall(options.x, options.y)
        while True:
            brick_list = Bricks.build_wall_bricklist(options.x, options.y,
                                                     grid)
            Bricks.sendserial(brick_list, s)
            turn = turn + 1
            print "geracao ", turn
            time.sleep(0.05)
            grid = GameOfLife.update_wall(grid, options.x, options.y, turn)
    s.close()

elif (options.mode == "hib"):
    listing = glob.glob(options.folder)
コード例 #15
0
ファイル: Tijolo.py プロジェクト: tcvieira/Tijolo
   s.close()
   
elif (options.mode == "gol"):
   #s = serial.Serial('/dev/ttyS0', 115200)
   s = serial.Serial(Config.SERIAL_PORT, Config.SERIAL_BAUD_RATE, dsrdtr=True)
   s.open()
   turn = 0
   if not options.wall:
       grid = Bricks.build_grid(options.x, options.y)
       while True:
          brick_list = Bricks.build_bricklist(options.x, options.y, grid)
          Bricks.sendserial(brick_list,s)
          turn = turn + 1
          print "geracao ", turn
          time.sleep(0.05)
          grid = GameOfLife.update(grid, options.x, options.y, turn)
   else:
       print "modo wall"
       grid = Bricks.build_grid_wall(options.x, options.y)
       while True:
          brick_list = Bricks.build_wall_bricklist(options.x, options.y, grid)
          Bricks.sendserial(brick_list,s)
          turn = turn + 1
          print "geracao ", turn
          time.sleep(0.05)
          grid = GameOfLife.update_wall(grid, options.x, options.y, turn)
   s.close()
   
elif (options.mode == "hib"):
   listing = glob.glob(options.folder)
   for infile in listing:       
コード例 #16
0
#!/usr/bin/python
import GameOfLife as gof

import random
import time

if __name__ == "__main__":

    env = gof.Environment((800, 600))

    gof.ConwayPatterns.glider((10, 10), 1, 1, env)

    gof.ConwayPatterns.glider((30, 30), 2, 1, env)

    print "cells:",
    env.show_live_cells_location()

    p_born = 0
    p_dead = 0
    for cell in env.live_cells:
        env.update(cell)
        for b in range(p_born, len(env.cells_to_born)):
            print b, env.cells_to_born[b][0]
            p_born += 1

    env.kill_cells()
    env.born_cells()

    print "cells:",
    env.show_live_cells_location()