Example #1
0
    def test_scillator(self):
        """blinker"""
        A = np.zeros((10, 10))
        A[1:4, 1] = 1
        B = conway(A)
        assert (B[2, 0:3] == 1).all()

        B = conway(B)
        assert (A == B).all()
    def test_scillator(self):
        """blinker"""
        A = np.zeros((10,10))
        A[1:4,1] = 1
        B = conway(A)
        assert (B[2, 0:3] == 1).all()

        B = conway(B)
        assert (A == B).all()
Example #3
0
    def test_still(self):
        """2x2 block"""

        A = np.zeros((10, 10))
        A[1:3, 1:3] = 1
        B = conway(A)
        assert (A == B).all()
Example #4
0
def endpoint():
    width = int(request.values.get('M'))
    height = int(request.values.get('N'))
    liveCells = []
    i = 0
    liveCells = parseQuery(str(request.query_string))
    return jsonpify(output=conway(width, height, liveCells))
Example #5
0
def simulate():
   H = 40
   V = 30
   C = conway(H,V,'zeros')
   C.setPos(10,10,1)
   C.setPos(9,10,1)
   C.setPos(12,10,1)
   C.setPos(10,9,1)
   C.setPos(11,9,1)
   C.setPos(10,11,1)
   C.setPos(11,11,1)
   C.setPos(10,20,1)
   C.setPos(11,21,1)
   C.setPos(12,19,1)
   C.setPos(12,20,1)
   C.setPos(12,21,1)
   n = 0
   while True:
      C.evolve(rule)
      os.system('clear')
      C.printDisp()
      print("STEP:", n)
      sleep(0)
      n += 1
   return True
    def test_still(self):
        """2x2 block"""

        A = np.zeros((10,10))
        A[1:3,1:3] = 1
        B = conway(A)
        assert (A == B).all()
Example #7
0
import pygame
import conway
realwidth = 600
realheight = 600
width = 50
height = 50

screen = pygame.display.set_mode((realwidth, realheight))
running = True

scaleFactor = float(realwidth / width)
conway = conway.conway(width, height)

conway.displayGrid(screen, scaleFactor)
pix2set = [[False for i in range(height)] for j in range(width)]
clock = pygame.time.Clock()
while (pygame.mouse.get_pressed()[1] != True):
    if (pygame.mouse.get_pressed()[0] == True):
        mousepos = pygame.mouse.get_pos()
        val1 = int(mousepos[0] / scaleFactor)
        val2 = int(mousepos[1] / scaleFactor)
        conway.toggleSquare(val1, val2, scaleFactor, screen, True)
        pygame.display.flip()
    elif (pygame.mouse.get_pressed()[2] == True):
        mousepos = pygame.mouse.get_pos()
        val1 = int(mousepos[0] / scaleFactor)
        val2 = int(mousepos[1] / scaleFactor)
        conway.toggleSquare(val1, val2, scaleFactor, screen, False)
        conway.displayGrid(screen, scaleFactor)
        pygame.display.flip()
    pygame.event.get()
Example #8
0
import conway, time


size = 20
conway = conway.conway(size)


def printGrid(grid):
    for i in range(size):
        print str(grid[i]).replace('[','').replace(']','').replace(',',' ').replace('0', ' ')


while(True):
    time.sleep(0.5)
    printGrid(conway.takeAStep())
    print("\n")
Example #9
0
#import matplotlib.pyplot as plt
import numpy as np
from conway import conway

if __name__ == "__main__":
	# set up board
	m,n = 100,100

	A = np.array([ [ 1 if x=="#" else 0 for x in l.strip()] for l in open('day18.input').readlines() ]).reshape(m, n)

	#A = np.array([[0,1,0,1,0,1],[0,0,0,1,1,0],[1,0,0,0,0,1],[0,0,1,0,0,0],[1,0,1,0,0,1],[1,1,1,1,0,0]])

	print A
	for i in range(100):
		A = conway(A)
		A[0,0] = 1
		A[m-1,0] = 1
		A[0,n-1] = 1
		A[m-1,n-1] = 1
	print np.sum(A)
Example #10
0
import conway, time

size = 20
conway = conway.conway(size)


def printGrid(grid):
    for i in range(size):
        print str(grid[i]).replace('[', '').replace(']', '').replace(
            ',', ' ').replace('0', ' ')


while (True):
    time.sleep(0.5)
    printGrid(conway.takeAStep())
    print("\n")
Example #11
0
 def test_evolution(self):
     """test that something changes"""
     m, n = 10, 10
     A = np.random.random(m * n).reshape((m, n)).round()
     B = conway(A)
     assert (B != A).any()
Example #12
0
 def test_evolution(self):
     """test that something changes"""
     m, n = 10, 10
     A = np.random.random(m*n).reshape((m, n)).round()
     B = conway(A)
     assert (B != A).any()