Exemplo n.º 1
0
class MoveValidity(object):

    def __init__(self, pieces):
        self.pieces = pieces
        self.edges = EdgesFromPieces(pieces).create_edges()

    def is_valid_move(self, old_points, new_points):
        for point in new_points:
            if self._outside_or_occupied_point(old_points, point):
                return False
        return True

    def is_valid_first_move(self, new_points):
        for point in new_points:
            if self._within_boundary_and_occupied(point):
                return False
        return True

    def _outside_or_occupied_point(self, old_points, point):
        return self.edges.is_point_outside_boundary_except_top(point) \
            or (self.edges.is_point_within_top_boundary(point)\
                and not self.pieces[point.row][point.col].is_empty()\
                and point not in old_points)
            
    def _within_boundary_and_occupied(self, point):
        return not self.edges.is_point_outside_boundary(point) \
            and not self.pieces[point.row][point.col].is_empty()
 def test_get_edges_from_pieces(self):
     pieces = []
     for i in range(0, 5):
         pieces.append([i,i,i,i])
     
     edges = EdgesFromPieces(pieces).create_edges()
     self.assertEqual(0, edges.get_edge(LEFT))
     self.assertEqual(3, edges.get_edge(RIGHT))
     self.assertEqual(0, edges.get_edge(UP))
     self.assertEqual(4, edges.get_edge(DOWN))
Exemplo n.º 3
0
 def __init__(self, pieces):
     self.pieces = pieces
     self.edges = EdgesFromPieces(pieces).create_edges()
Exemplo n.º 4
0
 def _set_points_in_board_to_tile(self, points, tile):
     edges = EdgesFromPieces(self.pieces).create_edges()
     for point in points:
         if not edges.is_point_outside_boundary(point):
             self.pieces[point.row][point.col] = tile