Skip to content

Commit

Permalink
Added continue button which continuously steps
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwager committed Jul 5, 2018
1 parent ce0f328 commit 6bf5cce
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_yacgol.py
Expand Up @@ -108,6 +108,36 @@ def test_block_step(self):
self.assertTrue(cell_grid.cell_buttons[1][2].alive)
self.assertTrue(cell_grid.cell_buttons[2][2].alive)

def test_beacon_cont(self):
"""
https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life#Examples_of_patterns
OOXX OOXX
OXXX -> OOXX
XXXO XXOO
XXOO XXOO
"""
root = tkinter.Tk()

cell_grid = yacgol.CellGrid(root, 4, 4)

cell_grid.cell_buttons[0][0].flip()
cell_grid.cell_buttons[0][1].flip()
cell_grid.cell_buttons[1][0].flip()
cell_grid.cell_buttons[3][3].flip()
cell_grid.cell_buttons[2][3].flip()
cell_grid.cell_buttons[3][2].flip()

cell_grid.cont(seconds=0, times=2)

# This oscillator has period 2 so it should be the same
self.assertTrue(cell_grid.cell_buttons[0][0].alive)
self.assertTrue(cell_grid.cell_buttons[0][1].alive)
self.assertTrue(cell_grid.cell_buttons[1][0].alive)
self.assertTrue(cell_grid.cell_buttons[3][3].alive)
self.assertTrue(cell_grid.cell_buttons[2][3].alive)
self.assertTrue(cell_grid.cell_buttons[3][2].alive)


if __name__ == "__main__":
unittest.main()
13 changes: 13 additions & 0 deletions yacgol.py
Expand Up @@ -96,6 +96,16 @@ def apply_rules(cell_button, x, y):

self._apply_cell_buttons(apply_rules)

def cont(self, seconds=1, times=None):
milliseconds = 1000 * seconds

self.step()

if times is None:
self.window.after(milliseconds, self.cont, seconds, None)
elif times > 0:
self.window.after(milliseconds, self.cont, seconds, times - 1)


def parse_args():
p = argparse.ArgumentParser(description='''
Expand Down Expand Up @@ -141,6 +151,9 @@ def main():
step_button = tkinter.Button(command_frame, text='Step', command=cell_grid.step)
step_button.pack(side=tkinter.TOP)

continue_button = tkinter.Button(command_frame, text='Continue', command=cell_grid.cont)
continue_button.pack(side=tkinter.TOP)

reset_button = tkinter.Button(command_frame, text='Reset', command=cell_grid.reset)
reset_button.pack(side=tkinter.TOP)

Expand Down

0 comments on commit 6bf5cce

Please sign in to comment.