From 1625e093e32b5bb292dfbb479b29bc1b98187df3 Mon Sep 17 00:00:00 2001
From: Sébastien Dailly <sebastien@chimrod.com>
Date: Sun, 24 Aug 2014 20:37:19 +0200
Subject: Placement correction

---
 qml/python/game.py            | 27 +++++++++------------------
 qml/python/tests/test_game.py | 34 ++++------------------------------
 qml/python/transformations.py |  8 ++++----
 3 files changed, 17 insertions(+), 52 deletions(-)

(limited to 'qml')

diff --git a/qml/python/game.py b/qml/python/game.py
index 7a91ae7..f4cb929 100644
--- a/qml/python/game.py
+++ b/qml/python/game.py
@@ -36,23 +36,16 @@ class Game(object):
         x_space = 2
         y_space = 2
 
-        if self.min_y > y_space:
-            self.min_y -= y_space
-
-        if self.min_x > x_space:
-            self.min_x -= x_space
-
-        if self.max_y < 19 - y_space:
-            self.max_y += y_space
-
-        if self.max_x < 19 - x_space:
-            self.max_x += x_space
+        self.min_y = max(1, self.min_y - y_space)
+        self.min_x = max(1, self.min_x - x_space)
+        self.max_y = min(19, self.max_y + y_space)
+        self.max_x = min(19, self.max_x + x_space)
 
         self.side = {
-            "TOP": self.min_y != 0,
-            "LEFT": self.min_x != 0,
-            "RIGHT": self.max_x != 19,
-            "BOTTOM": self.max_y != 19,
+            "TOP": self.min_y == 1,
+            "LEFT": self.min_x == 1,
+            "RIGHT": self.max_x == 19,
+            "BOTTOM": self.max_y == 19,
         }
 
 
@@ -110,8 +103,6 @@ class Game(object):
         """ This takes coordinates in SGF style (aa - qq) and returns the
         corresponding integer coordinates (between 1 and 19). """
 
-        print(x)
-
         return tuple([ord(c) - 96 for c in x])
 
     def parse_tree(self, fun, elements=None):
@@ -136,7 +127,7 @@ class Game(object):
         """ Create a normalized board, translated on lower coord.
         """
 
-        for transformation in [Translation(self), Rotation(self), Translation(self), Symmetry(self)]:
+        for transformation in [Translation(self), Rotation(self), Symmetry(self)]:
             if not transformation.is_valid():
                 continue
 
diff --git a/qml/python/tests/test_game.py b/qml/python/tests/test_game.py
index de43909..737e55b 100644
--- a/qml/python/tests/test_game.py
+++ b/qml/python/tests/test_game.py
@@ -66,36 +66,10 @@ class TestBoard(unittest.TestCase):
         # There is only 2 state : initial board, and 2 possibilities.
         self.assertEqual(2, len(currentgame.tree))
 
-        self.assertTrue(currentgame.side['TOP'])
-        self.assertTrue(currentgame.side['LEFT'])
-        self.assertFalse(currentgame.side['BOTTOM'])
-        self.assertFalse(currentgame.side['RIGHT'])
+        self.assertFalse(currentgame.side['TOP'])
+        self.assertFalse(currentgame.side['LEFT'])
+        self.assertTrue(currentgame.side['BOTTOM'])
+        self.assertTrue(currentgame.side['RIGHT'])
 
         currentgame.normalize()
 
-    def test_level2(self):
-
-        def fun(pos):
-            return (0,0)
-        currentgame = create_board("test2.sgf")
-
-        print(currentgame.tree)
-
-        currentgame.normalize()
-
-        self.assertEqual(11, currentgame.min_x)
-        self.assertEqual(13, currentgame.min_y)
-        self.assertEqual(19, currentgame.max_x)
-        self.assertEqual(19, currentgame.max_y)
-
-        self.assertEqual((9, 7), currentgame.get_size())
-
-        # There is only 2 state : initial board, and 2 possibilities.
-        self.assertEqual(2, len(currentgame.tree))
-
-        self.assertTrue(currentgame.side['TOP'])
-        self.assertTrue(currentgame.side['LEFT'])
-        self.assertFalse(currentgame.side['BOTTOM'])
-        self.assertFalse(currentgame.side['RIGHT'])
-
-        currentgame.normalize()
diff --git a/qml/python/transformations.py b/qml/python/transformations.py
index 380c30c..adf0395 100644
--- a/qml/python/transformations.py
+++ b/qml/python/transformations.py
@@ -72,10 +72,10 @@ class Rotation(object):
         """ Apply the transformations on the sides.
         """
         return {
-            "TOP":   self.board.side["RIGHT"],
-            "LEFT":  self.board.side["TOP"],
-            "RIGHT": self.board.side["BOTTOM"],
-            "BOTTOM":self.board.side["LEFT"]
+            "BOTTOM":   self.board.side["RIGHT"],
+            "RIGHT":  self.board.side["TOP"],
+            "LEFT": self.board.side["BOTTOM"],
+            "TOP":self.board.side["LEFT"]
         }
 
 class Symmetry(object):
-- 
cgit v1.2.3