예제 #1
0
    def test_it_validates_the_move(self):
        piece = Rook(Color.BLACK)

        self.assertTrue(piece.is_valid_move('c4', 'c8'))
        self.assertTrue(piece.is_valid_move('c4', 'f4'))
        self.assertTrue(piece.is_valid_move('c4', 'c1'))
        self.assertTrue(piece.is_valid_move('c4', 'a4'))
        self.assertFalse(piece.is_valid_move('c4', 'a2'))
        self.assertFalse(piece.is_valid_move('c4', 'h2'))
예제 #2
0
    def _place_pieces(self):
        self.tiles[0][0].piece = Rook(Color.BLACK)
        self.tiles[0][1].piece = Knight(Color.BLACK)
        self.tiles[0][2].piece = Bishop(Color.BLACK)
        self.tiles[0][3].piece = Queen(Color.BLACK)
        self.tiles[0][4].piece = King(Color.BLACK)
        self.tiles[0][5].piece = Bishop(Color.BLACK)
        self.tiles[0][6].piece = Knight(Color.BLACK)
        self.tiles[0][7].piece = Rook(Color.BLACK)

        for i in range(self.width):
            self.tiles[1][i].piece = Pawn(Color.BLACK)
            self.tiles[6][i].piece = Pawn(Color.WHITE)

        self.tiles[7][0].piece = Rook(Color.WHITE)
        self.tiles[7][1].piece = Knight(Color.WHITE)
        self.tiles[7][2].piece = Bishop(Color.WHITE)
        self.tiles[7][3].piece = Queen(Color.WHITE)
        self.tiles[7][4].piece = King(Color.WHITE)
        self.tiles[7][5].piece = Bishop(Color.WHITE)
        self.tiles[7][6].piece = Knight(Color.WHITE)
        self.tiles[7][7].piece = Rook(Color.WHITE)
예제 #3
0
  def reset_board(self):
    boxes = self.__boxes
    # initialize white pieces
    boxes[0][0] = Box(Rook(True), 0, 0);
    boxes[0][1] = Box(Knight(True), 0, 1);
    boxes[0][2] = Box(Bishop(True), 0, 2);
    #...
    boxes[1][0] = Box(Pawn(True), 1, 0);
    boxes[1][1] = Box(Pawn(True), 1, 1);
    #...

    # initialize black pieces
    boxes[7][0] = Box(Rook(False), 7, 0);
    boxes[7][1] = Box(Knight(False), 7, 1);
    boxes[7][2] = Box(Bishop(False), 7, 2);
    #...
    boxes[6][0] = Box(Pawn(False), 6, 0);
    boxes[6][1] = Box(Pawn(False), 6, 1);
    # ...

    # initialize remaining boxes without any piece
    for i in range(2, 6):
      for j in range(0, 8):
        boxes[i][j] = Box(i, j, None)
예제 #4
0
 def __init__(self, team: Team, chessboard, pos: Position):
     super().__init__()
     self.chessboard = chessboard
     self.pos = pos
     self.pieces = [Tile(Queen(pos, team)), Tile(Rook(pos, team)), Tile(Bishop(pos, team)),Tile(Knight(pos, team))]
     self.initUI()
예제 #5
0
from chess.pieces.bishop import Bishop
from chess.pieces.knight import Knight
from chess.pieces.rook import Rook
from chess.pieces.queen import Queen
from chess.pieces.king import King

from chess.position import Position
from chess.team import Team
from chess.check import *




chessBoard_init = [
        [
            Rook(Position(0, 0), Team.BLACK), Knight(Position(1, 0), Team.BLACK), Bishop(Position(2, 0), Team.BLACK), Queen(Position(3, 0), Team.BLACK), King(Position(4, 0), Team.BLACK), Bishop(Position(5, 0), Team.BLACK), Knight(Position(6, 0), Team.BLACK), Rook(Position(7, 0), Team.BLACK)
        ],
        [
            Pawn(Position(x, 1), Team.BLACK) for x in range(8)
        ],
        [None for _ in range(8)],
        [None for _ in range(8)],
        [None for _ in range(8)],
        [None for _ in range(8)],
        [
            Pawn(Position(x, 6), Team.WHITE) for x in range(8)
        ],
        [
            Rook(Position(0, 7), Team.WHITE), Knight(Position(1, 7), Team.WHITE), Bishop(Position(2, 7), Team.WHITE), Queen(Position(3, 7), Team.WHITE), King(Position(4, 7), Team.WHITE), Bishop(Position(5, 7), Team.WHITE), Knight(Position(6, 7), Team.WHITE), Rook(Position(7, 7), Team.WHITE)
        ],
        
예제 #6
0
 def test_it_can_be_occupied(self):
     tile = Tile(Rook('white'))
     self.assertTrue(tile.is_not_empty())
     self.assertFalse(tile.is_empty())
예제 #7
0
 def test_it_can_be_instantiated(self):
     piece = Rook(Color.BLACK)
     self.assertIsInstance(piece, Rook)
예제 #8
0
 def test_it_has_the_proper_strong_representation_for_its_color(self):
     b_rook = Rook(Color.BLACK)
     self.assertEqual(str(b_rook), '\u265C')
     w_rook = Rook(Color.WHITE)
     self.assertEqual(str(w_rook), '\u2656')
예제 #9
0
파일: pawn.py 프로젝트: Dark-Leader/Chess
 def promote_to_rook(self):
     if self.color == WHITE:
         return Rook(self.row, self.col, WHITE, WHITE_ROOK)
     else:
         return Rook(self.row, self.col, BLACK, BLACK_ROOK)