Repository: bsatrom/py-conway

Issue:
Add method to re-seed the board

Discussion:

Patch:
diff --git a/py_conway/game.py b/py_conway/game.py
index dc7da7c..3666139 100644
--- a/py_conway/game.py
+++ b/py_conway/game.py
@@ -212,6 +212,18 @@ class Game:
         self.generations = 0
         self.live_cells = self._count_live_cells(self.current_board)
 
+    def reseed(self):
+        """Reseed the game board.
+
+        Should only be called when the game is not started. Calling when a game
+        is running will return silently.
+        """
+        if self.state != GameState.RUNNING:
+            self.seed = self._create_random_seed()
+            self.live_cells = self._count_live_cells(self.seed)
+            self.current_board = deepcopy(self.seed)
+            self.state = GameState.READY
+
     def run_generation(self):
         """Run a single generation across all cells.
 


Test patch:
diff --git a/tests/test_conway.py b/tests/test_conway.py
index 76decfc..2cebdba 100644
--- a/tests/test_conway.py
+++ b/tests/test_conway.py
@@ -1,4 +1,5 @@
 import pytest
+from copy import deepcopy
 
 import os
 import sys
@@ -370,3 +371,24 @@ def test_start_can_be_used_to_restart_the_game():
     test_game.start()
 
     assert test_game.current_board == random_seed
+
+
+def test_reseed_can_be_used_to_create_a_new_random_seed():
+    test_game = Game(random=True)
+
+    first_random_seed = deepcopy(test_game.current_board)
+
+    test_game.reseed()
+
+    assert first_random_seed != test_game.current_board
+
+
+def test_cannot_reseed_when_game_is_active():
+    test_game = Game(random=True)
+
+    first_random_seed = deepcopy(test_game.current_board)
+
+    test_game.start()
+    test_game.reseed()
+
+    assert first_random_seed == test_game.current_board