Пример #1
0
 def test_piece_overlap(self):
     standard_piece = Piece.from_attributes()
     opposite_piece = Piece.from_attributes(True, True, False, True)
     self.assertTrue(
         Piece.overlap(
             standard_piece,
             opposite_piece
         )
     )
Пример #2
0
 def test_no_overlap(self):
     a = Piece.from_attributes(True, True, False, True)
     b = Piece.from_attributes(True, False, True, True)
     c = Piece.from_attributes(False, True, False, False)
     d = Piece.from_attributes(True, False, False, False)
     self.assertFalse(
         Piece.overlap(
             a, b, c, d
         )
     )
Пример #3
0
 def check_win(self, x, y):
     # Check if we've just won a game, based on having added
     # a piece to position x, y
     for winning_sets in self.board.get_rows(x, y):
         pieces = []
         for _x, _y in winning_sets:
             last_piece = self.board.get(_x, _y)
             if last_piece is None:
                 break
             pieces.append(last_piece)
         if (
             len(pieces) == 4 and
             Piece.overlap(*pieces)
         ):
             return True
     return False
Пример #4
0
    def test_full_overlap(self):
        pieces = []
        for black in (True, False):
            for tall in (True, False):
                for hole in (True, False):
                    for square in (True, False):
                        pieces.append(
                            Piece.from_attributes(black, tall, hole, square)
                        )
        for piece in pieces:
            overlaps = 0
            for other_piece in pieces:
                if piece == other_piece:
                    continue
                if Piece.overlap(piece, other_piece):
                    overlaps += 1

            self.assertEqual(
                overlaps, 14
            )