Repository: fabiobatalha/chess_master

Issue:
Implement threatening zone for bishops

Discussion:

Patch:
diff --git a/masterchess/chess.py b/masterchess/chess.py
index 63f5aab..35ba524 100644
--- a/masterchess/chess.py
+++ b/masterchess/chess.py
@@ -79,6 +79,74 @@ class Pieces(object):
 
         self.set_position(position or (0, 0))
 
+    def _se_positions(self, max_size):
+        """
+            Retrieve the south east positions of as given position
+        """
+        ne_positions = []
+
+        x, y = self.position
+        rg = range(max_size)
+        while True:
+            x += 1
+            y -= 1
+            if x not in rg or y not in rg:
+                break
+            ne_positions.append((x, y))
+
+        return ne_positions
+
+    def _ne_positions(self, max_size):
+        """
+            Retrieve the north east positions of as given position
+        """
+        ne_positions = []
+
+        x, y = self.position
+        rg = range(max_size)
+        while True:
+            x += 1
+            y += 1
+            if x not in rg or y not in rg:
+                break
+            ne_positions.append((x, y))
+
+        return ne_positions
+
+    def _nw_positions(self, max_size):
+        """
+            Retrieve the south weast positions of as given position
+        """
+        ne_positions = []
+
+        x, y = self.position
+        rg = range(max_size)
+        while True:
+            x -= 1
+            y += 1
+            if x not in rg or y not in rg:
+                break
+            ne_positions.append((x, y))
+
+        return ne_positions
+
+    def _sw_positions(self, max_size):
+        """
+            Retrieve the south weast positions of as given position
+        """
+        ne_positions = []
+
+        x, y = self.position
+        rg = range(max_size)
+        while True:
+            x -= 1
+            y -= 1
+            if x not in rg or y not in rg:
+                break
+            ne_positions.append((x, y))
+
+        return ne_positions
+
     def set_position(self, position):
         """
         Set the x,y position of the piece on the board.
@@ -113,7 +181,14 @@ class Bishop(Pieces):
         Arguments:
         max_size -- integer that defines de boundary limits of the board.
         """
-        pass
+        zone = []
+
+        zone += self._se_positions(max_size)
+        zone += self._ne_positions(max_size)
+        zone += self._nw_positions(max_size)
+        zone += self._sw_positions(max_size)
+
+        return zone
 
 
 class Kinight(Pieces):


Test patch:
diff --git a/tests/tests.py b/tests/tests.py
index c70e5aa..a6db443 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -1,4 +1,3 @@
-# coding: utf-8
 import unittest
 
 from masterchess import chess
@@ -164,6 +163,92 @@ class TestsChessMasterPiece(unittest.TestCase):
             sorted(pawn.threatening_zone(8)), sorted(expected)
         )
 
+    def test_se_positions(self):
+
+        piece = chess.Pieces((3, 4))
+
+        expected = [
+            (4, 3),
+            (5, 2),
+            (6, 1),
+            (7, 0),
+        ]
+
+        self.assertEqual(
+            sorted(piece._se_positions(8)), sorted(expected)
+        )
+
+    def test_ne_positions(self):
+
+        piece = chess.Pieces((3, 4))
+
+        expected = [
+            (4, 5),
+            (5, 6),
+            (6, 7)
+        ]
+
+        self.assertEqual(
+            sorted(piece._ne_positions(8)), sorted(expected)
+        )
+
+    def test_nw_positions(self):
+
+        piece = chess.Pieces((3, 4))
+
+        expected = [
+            (2, 5),
+            (1, 6),
+            (0, 7)
+        ]
+
+        self.assertEqual(
+            sorted(piece._nw_positions(8)), sorted(expected)
+        )
+
+    def test_sw_positions(self):
+
+        piece = chess.Pieces((3, 4))
+
+        expected = [
+            (2, 3),
+            (1, 2),
+            (0, 1)
+        ]
+
+        self.assertEqual(
+            sorted(piece._sw_positions(8)), sorted(expected)
+        )
+
+
+    def test_bishop_threatening_zone(self):
+        """
+        Testing bishop moves when the piece is able to threatening other pieces
+        in all directions.
+        """
+
+        bishop = chess.Bishop((3, 4))
+
+        expected = [
+            (0, 1),
+            (0, 7),
+            (1, 2),
+            (1, 6),
+            (2, 3),
+            (2, 5),
+            (4, 3),
+            (4, 5),
+            (5, 2),
+            (5, 6),
+            (6, 1),
+            (6, 7),
+            (7, 0)
+        ]
+
+        self.assertEqual(
+            sorted(bishop.threatening_zone(8)), sorted(expected)
+        )
+
 
 class TestsChessMasterBoard(unittest.TestCase):