コード例 #1
0
	 def test_getPossibleNeighbors(self):
		grid = {}
	 	obj = gameOfLife.GameOfLife(grid)

	 	neighborTuples = obj.getPossibleNeighbors(0, 0)

	 	self.assertTrue(len(neighborTuples) == 9)
コード例 #2
0
    def workerThread(self):
        '''
        Creates a new GameOfLife board and starts an infinite loop where the state
        of the will be iteratively updated by calling a update method
        '''

        # create new game
        game = gameOfLife.GameOfLife(self.dim)

        # create queue for simulated client server communication
        self.server_to_client_queue = queue.Queue() #queue sending messages to server
        self.client_to_server_queue = queue.Queue() #queue receiving from server
        server = Threaded_server(dim,self.server_to_client_queue, self.client_to_server_queue, game.encryption.context)
        server.start() # start server as a thread

        generation = 0

        while self.running:
            print("[CLIENT / GUI] Generation", generation)
            print("[CLIENT / GUI] Homomorphic encryption == ", self.gui.homomorphic_encryption.get())
            if generation == 0:
                # grid initialization
                msg = game.old_grid
            else:
                # compute new grid state
                time.sleep(0.1)
                game.update_grid(self.server_to_client_queue, self.client_to_server_queue, self.gui.homomorphic_encryption.get())
                msg = game.new_grid
            generation += 1
            # add to message queue and hand it over to GUI to visualize it
            self.queue.put(msg)
コード例 #3
0
	 def test_evolveFromOnePoint(self):
	 	grid = {}
	 	obj = gameOfLife.GameOfLife(grid)

	 	obj.evolve(0, 0)

		self.assertTrue(len(grid) == 0)	 
コード例 #4
0
	 def test_addPointToGame(self):
	 	grid = {}
	 	obj = gameOfLife.GameOfLife(grid)

	 	self.assertTrue(len(grid) == 0)

	 	obj.addPoint(0, 0)

	 	self.assertTrue(len(grid) == 1)
コード例 #5
0
	 def test_countOfNeighborsAlive(self):
	 	grid = {}
	 	obj = gameOfLife.GameOfLife(grid)

	 	obj.addPoint(0, 0)
	 	obj.addPoint(1, 0)
	 	obj.addPoint(0, 1)

	 	aliveNeighbors = obj.countOfNeighborsAlive(0, 0)

	 	self.assertTrue(aliveNeighbors == 2)	
コード例 #6
0
	 def test_evolveFromFourPoints(self):
	 	grid = {}
	 	obj = gameOfLife.GameOfLife(grid)

	 	obj.addPoint(0, 0)
	 	obj.addPoint(1, 0)
	 	obj.addPoint(0, 1)
	 	obj.addPoint(1, 1)

	 	self.assertTrue(len(grid) == 4)	

	 	obj.evolve(0, 0)

		self.assertTrue(len(grid) == 4)	 	
コード例 #7
0
import gameOfLife
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

if __name__ == '__main__':
    length = 400
    width = 400
    size = 20
    thing = gameOfLife.GameOfLife(width, length, size, .23)
    thing.run_rules()
    x = np.linspace(int(0 - (width / (2 * size))),
                    int(0 + (width / (2 * size))), int(width / size))
    y = np.linspace(int(0 - (length / (2 * size))),
                    int(0 + (length / (2 * size))), int(length / size))
    xgrid, ygrid = np.meshgrid(x, y)

    print(xgrid)
    print(thing.totalSum)

    fig = plt.figure()
    ax = Axes3D(fig)

    ax.plot_surface(xgrid, ygrid, thing.totalSum)
    plt.show()
コード例 #8
0
	 def test_objectExists(self):
	 	obj = gameOfLife.GameOfLife({})

	 	self.assertTrue(obj != None)