def main(): # create a connection to the display with size 8 with matrixdisplay.MatrixDispaly(DDIM) as display: im = pil.Image.open('img/mario.jpg') display.draw_frame(to_pix(im)) time.sleep(5) while True: game = gameoflife.GameOfLife(display, (179, 240, 0), 100) display.clear_screen() game.play() fr = frame.Frame(DDIM) while True: for i in range(0, 16): draw_line(fr, (i, 0), (15 - i, 15), (250, 0, 10)) draw_line(fr, (0, i), (15, 15 - i), (0, 0, 255)) display.draw_frame(fr) #time.sleep(0.1) fr = frame.Frame(DDIM) #time.sleep(0.1) t = 0.09 while True: display.fill_screen((0, 255, 0)) time.sleep(t) display.fill_screen((0, 255, 255)) time.sleep(t) display.fill_screen((255, 255, 0)) time.sleep(t) display.fill_screen((255, 255, 255)) time.sleep(t)
def test_set_cell(self): given_cell = (1, 2) gol = g.GameOfLife() gol.set_cell(given_cell, True) self.assertEqual(gol.cells, {given_cell}) gol.set_cell(given_cell, False) self.assertEqual(gol.cells, set()) gol.set_cell(given_cell, False) self.assertEqual(gol.cells, set())
def test_set_cells_iterate__call__(self): given_keys = {(0, 1), (1, 1), (2, 1)} gol = g.GameOfLife() self.assertEqual(gol(), set()) gol.cells = given_keys self.assertEqual(gol(), given_keys) gol.iterate() self.assertEqual(gol(), {(1, 0), (1, 1), (1, 2)})
def test_population(self): gol = g.GameOfLife() self.assertEqual(gol.population, 0) self.assertEqual(len(gol), 0) # Glider gol.cells = [(1, 0), (2, 1), (0, 2), (1, 2), (2, 2)] self.assertEqual(gol.population, 5) self.assertEqual(len(gol), 5)
def run(params): arms = params["arms"] env = gameoflife.GameOfLife(arms, params["gameoflife_init"]) horizon = params["horizon"] fig, ax = plt.subplots() player = experts.EpsilonGreedy(env, epsilon=.4) player.run(horizon, render=True)
def run(params): arms = params["arms"] env = gameoflife.GameOfLife(arms, params["gameoflife_init"]) algos = { "FTAL": partial.FTAL(env), "AUER": partial.AUER(env), "Epsilon 0.4": partial.EpsilonGreedy(env, .4), "AnnealingEpsilon 0.6": partial.AnnealingEpsilonGreedy(env, .6), } fig, ax = plt.subplots() tests.util.run(params, env, algos, ax, "Sleeping bandits with side information")
def run(params): arms = params["arms"] env = gameoflife.GameOfLife(arms, params["gameoflife_init"]) algos = { "FTAL": experts.FTAL(env), "Epsilon 0.4": experts.EpsilonGreedy(env, .4), "Epsilon 0.1": experts.EpsilonGreedy(env, .1), "Annealing Eps 0.6": experts.AnnealingEpsilonGreedy(env, .6) } fig, ax = plt.subplots() tests.util.run(params, env, algos, ax, "Sleeping experts")
def run(params): arms = params["arms"] env = gameoflife.GameOfLife(arms, params["gameoflife_init"]) algos = { "AUER": bandits.AUER(env), "Epsilon 0.4": bandits.EpsilonGreedy(env, .4), "Epsilon 0.8": bandits.EpsilonGreedy(env, .8), "Epsilon 0.1": bandits.EpsilonGreedy(env, .1) } fig, ax = plt.subplots() # ax.plot(np.repeat(bandits.oracle(env, params["horizon"]), params["horizon"]), label="oracle") tests.util.run(params, env, algos, ax, "Sleeping bandits")
import gameoflife boardHeight = 25 boardWidth = 25 originalProbability = 0.5 game = gameoflife.GameOfLife(boardWidth, boardHeight) board = game.geneticAlgorithm()
def main(): window_width = 400 window_height = 400 block_size = 20 margin = 5 screen = pygame.display.set_mode((window_height, window_width)) board = [] n = window_height // block_size m = window_width // block_size for i in range(0, n): board.append([]) for j in range(0, m): board[i].append(cell.Cell(i, j)) board[5][5].state = 1 board[5][6].state = 1 board[5][7].state = 1 board[6][8].state = 1 board[6][7].state = 1 board[6][6].state = 1 my_game = gameoflife.GameOfLife(n, m) my_game.set_board(board) my_game.print_board() print() clock = pygame.time.Clock() start = False while True: draw_grid(screen, my_game, block_size, margin, n, m) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() row = pos[0] // (block_size + margin) col = pos[1] // (block_size + margin) if my_game.board.board[col][row].state == 0: my_game.board.board[col][row].state = 1 else: my_game.board.board[col][row].state = 0 elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: start = not start pygame.display.update() if start: pygame.time.wait(1000) my_game.advance()