Пример #1
0
    def test_pawn(self):
        b = board.Board()

        b.set_piece((1, 1), board.Piece(board.PieceType.PAWN, True))
        b.set_piece((6, 1), board.Piece(board.PieceType.PAWN, False))

        self.assertItemsEqual([(2, 1), (3, 1)],
                              Pawn.get_moves((1, 1), b[(1, 1)], b))
        self.assertItemsEqual([(5, 1), (4, 1)],
                              Pawn.get_moves((6, 1), b[(6, 1)], b))
Пример #2
0
 def next_piece(self):
     shape = self.next_shape()
     self.shapes.remove(shape)
     row = col = 0
     if shape in (board.SHAPE_I, board.SHAPE_O):
         col = self.board.cols / 2
     self.piece = board.Piece(shape, row, col)
Пример #3
0
    def test_knight(self):
        b = board.Board()

        b.set_piece((1, 1), board.Piece(board.PieceType.KNIGHT, True))

        self.assertItemsEqual([(3, 2), (2, 3), (0, 3), (3, 0)],
                              Knight.get_moves((1, 1), b[(1, 1)], b))
Пример #4
0
    def test_bishop(self):
        b = board.Board()

        b.set_piece((1, 1), board.Piece(board.PieceType.BISHOP, True))

        self.assertItemsEqual([(0, 0), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6),
                               (7, 7), (0, 2), (2, 0)],
                              Bishop.get_moves((1, 1), b[(1, 1)], b))
Пример #5
0
    def test_king(self):
        b = board.Board()

        b.set_piece((1, 1), board.Piece(board.PieceType.KING, True))

        self.assertItemsEqual([(0, 0), (0, 1), (0, 2), (1, 0), (1, 2), (2, 0),
                               (2, 1), (2, 2)],
                              King.get_moves((1, 1), b[(1, 1)], b))
Пример #6
0
    def test_rook(self):
        b = board.Board()

        b.set_piece((1, 1), board.Piece(board.PieceType.ROOK, True))

        self.assertItemsEqual([(0, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1),
                               (7, 1), (1, 0), (1, 2), (1, 3), (1, 4), (1, 5),
                               (1, 6), (1, 7)],
                              Rook.get_moves((1, 1), b[(1, 1)], b))
Пример #7
0
 def test_rotate_and_back_should_not_change_blocks(self):
     for s in board.ALL_SHAPES:
         p = board.Piece(s)
         initial_blocks = p.blocks()
         p.rotate()
         p.rotate(ccw=True)
         rotated_blocks = p.blocks()
         self.assertEqual(initial_blocks, rotated_blocks,
                          "failed for {}".format(s))
Пример #8
0
 def draw_next_piece(self, y):
     x = self.board_width + \
         (self.width - self.board_width - self.block_size) / 2
     row = y / self.block_size
     col = x / self.block_size - 1
     piece = board.Piece(self.state.next_shape(), row, col)
     pygame.draw.rect(self.screen, piece.shape.color,
                      (x - self.block_size * 2, y - self.block_size / 2,
                       self.block_size * 5, self.block_size * 4), 1)
     self.draw_piece(piece)
Пример #9
0
    def test_queen(self):
        b = board.Board()

        b.set_piece((1, 1), board.Piece(board.PieceType.QUEEN, True))

        self.assertItemsEqual([(0, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1),
                               (7, 1), (1, 0), (1, 2), (1, 3), (1, 4), (1, 5),
                               (1, 6), (1, 7), (0, 0), (2, 2), (3, 3), (4, 4),
                               (5, 5), (6, 6), (7, 7), (0, 2), (2, 0)],
                              Queen.get_moves((1, 1), b[(1, 1)], b))
Пример #10
0
 def test_move(self):
     test_data = ((board.DIRECTION_RIGHT, (1, 1),
                   (1, 2)), (board.DIRECTION_LEFT, (1, 1), (1, 0)),
                  (board.DIRECTION_DOWN, (1, 1), (2, 1)))
     for s in board.ALL_SHAPES:
         for t in test_data:
             direction, position, expected_position = t
             p = board.Piece(s, *position)
             p.move(direction)
             self.assertEqual(expected_position, p.position(),
                              "failed for {}".format(s))
Пример #11
0
 def test_rotate_should_change_blocks_except_for_O(self):
     for s in board.ALL_SHAPES:
         p = board.Piece(s)
         initial_blocks = p.blocks()
         p.rotate()
         rotated_blocks = p.blocks()
         if s != board.SHAPE_O:
             self.assertNotEqual(initial_blocks, rotated_blocks,
                                 "failed for {}".format(s))
         else:
             self.assertEqual(initial_blocks, rotated_blocks,
                              "failed for O")
Пример #12
0
 def setUp(self):
     self.squares = [-1, 0, 0, 1, -1, 2, 2, 1]
     self.piece = board.Piece(0, [1, 2])
Пример #13
0
 def test_make_move(self):
     new_piece = board.Piece(0, [2, 3])
     new_board = self.board.make_move(self.piece, new_piece)
     self.assertEqual(len(new_board._pieces), 1)
     self.assertEqual(new_board._pieces[0], new_piece)
     self.assertEqual(new_board._squares, [-1, -1, 0, 0, 1, 1, 1, 1])
Пример #14
0
 def setUp(self):
     self.piece = board.Piece(0, [1, 2])
     self.board = board.Board([self.piece], [-1, 0, 0, -1, 1, 1, 1, 1])
Пример #15
0
 def test_blocks(self):
     for s in board.ALL_SHAPES:
         p = board.Piece(s)
         self.assertTrue(p.blocks())