Ejemplo n.º 1
0
    def test_promotion(self):
        board = Board(4, 2)
        board.add(Pawn, (0, 0), Color.WHITE)

        for i in range(3):
            board.move((0, i), (0, i + 1))

        board.promote((0, 3), Queen)
        self.assertEqual(Queen, board.get((0, 3))[1])
Ejemplo n.º 2
0
    def test_contains(self):
        board = Board(4, 2)

        for i in range(4):
            for j in range(4):
                board.add(Piece, (i, j), Color.BLACK if i % 2 else Color.WHITE)

        for i in range(4):
            for j in range(4):
                self.assertTrue(board.contains((i, j)))
Ejemplo n.º 3
0
    def test_remove(self):
        board = Board(4, 2)

        board.add(Queen, (0, 0), Color.WHITE)
        board.add(Queen, (3, 3), Color.BLACK)

        self.assertEqual(2, len(board.board))

        board.remove((3, 3))

        self.assertEqual(1, len(board.board))
Ejemplo n.º 4
0
    def test_get(self):
        board = Board(4, 2)

        for i in range(4):
            for j in range(4):
                board.add(Piece, (i, j), Color.BLACK if i % 2 else Color.WHITE)

        for i in range(4):
            for j in range(4):
                self.assertEqual(Color.BLACK if i % 2 else Color.WHITE,
                                 board.get((i, j))[0])
Ejemplo n.º 5
0
    def test_add(self):
        board = Board(4, 2)

        for i in range(4):
            for j in range(4):
                board.add(Piece, (i, j), Color.BLACK if i % 2 else Color.WHITE)
        self.assertEqual(len(board.board), 16)

        for i in range(4):
            for j in range(4):
                self.assertTrue((i, j) in board.board)
                self.assertEqual(Color.BLACK if i % 2 else Color.WHITE,
                                 board.board[(i, j)][0])
                self.assertEqual(Piece, board.board[(i, j)][1])
Ejemplo n.º 6
0
from Chess.Piece.King import King
from Chess.Piece.Queen import Queen
from Chess.Board import Board, Color
from Chess.Piece.Pawn import Pawn
from Chess.Utility import print_2d_board

board = Board(4, 2)
board.add(Pawn, (0, 0), Color.WHITE)
board.add(Pawn, (1, 1), Color.BLACK)

print_2d_board(board)
print(f"White Pawn movements: {Pawn.movements(board, (0, 0))}")
print(f"Black Pawn movements: {Pawn.movements(board, (1, 1))}")