Beispiel #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])
Beispiel #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)))
Beispiel #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))
Beispiel #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])
Beispiel #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])
Beispiel #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))}")
Beispiel #7
0
    def test_in_bounds(self):
        board = Board(4, 2)

        for i in range(4):
            for j in range(4):
                self.assertTrue(board.in_bounds((i, j)))