From 91d222f17f03c17e7b7a310f6553f9816e0adadc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <jmm@yavook.de>
Date: Sun, 27 Aug 2023 21:52:48 +0000
Subject: [PATCH] click -> clone

---
 pigeon_magnet_solver/board.py | 12 +++++++++---
 tests/test_board.py           |  3 +++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/pigeon_magnet_solver/board.py b/pigeon_magnet_solver/board.py
index b195f41..e43a69f 100644
--- a/pigeon_magnet_solver/board.py
+++ b/pigeon_magnet_solver/board.py
@@ -89,7 +89,7 @@ class Board:
         old_row = self.rows[row]
         self.rows[row] = old_row[:col] + value + old_row[col+1:]
 
-    def click(self, index: int) -> None:
+    def click(self, index: int) -> Self:
         # check is clickable
         row, col = index // self.width, index % self.width
         assert self.rows[row][col] == "1", f"{index} is not clickable!"
@@ -105,6 +105,12 @@ class Board:
         # rotate neighbors
         nb_rot = rotate_r([self[rc] for rc in nb_rc])
 
-        # set new neighbors
+        # create new state
+        result = self.__class__(
+            rows=self.rows.copy(),
+            buttons=self.buttons,
+        )
         for rc, val in zip(nb_rc, nb_rot):
-            self[rc] = val
+            result[rc] = val
+
+        return result
diff --git a/tests/test_board.py b/tests/test_board.py
index dcdb9ad..ba596f3 100644
--- a/tests/test_board.py
+++ b/tests/test_board.py
@@ -13,6 +13,9 @@ def test_default():
     assert board.binary_repr == (4, 11, 3), "Wrong binary repr"
     assert board.solution_class == (1, 3, 2), "Wrong solution class"
 
+    assert board.click(4).binary_repr == (4, 14, 3)
+    assert board.click(5).binary_repr == (4, 11, 6)
+
     for idx in (3, 7):
         with pytest.raises(AssertionError):
             board.click(idx)