chessai.chess.piece
1import chessai.core.coordinate 2import chessai.core.piece 3import chessai.core.types 4 5UNICODE_PIECE_SYMBOLS: dict[str, str] = { 6 "r": "♖", "R": "♜", 7 "n": "♘", "N": "♞", 8 "b": "♗", "B": "♝", 9 "q": "♕", "Q": "♛", 10 "k": "♔", "K": "♚", 11 "p": "♙", "P": "♟", 12} 13 14class King(chessai.core.piece.Piece, symbols = ('K', 'k')): 15 """ The King in chess. """ 16 17 _move_vectors: list[chessai.core.piece.MoveVector] = [ 18 chessai.core.piece.MoveVector( 1, 0), 19 chessai.core.piece.MoveVector( 1, 1), 20 chessai.core.piece.MoveVector( 1, -1), 21 chessai.core.piece.MoveVector(-1, 0), 22 chessai.core.piece.MoveVector(-1, 1), 23 chessai.core.piece.MoveVector(-1, -1), 24 chessai.core.piece.MoveVector( 0, 1), 25 chessai.core.piece.MoveVector( 0, -1), 26 ] 27 28 def symbol(self) -> str: 29 if (self.color == chessai.core.types.Color.WHITE): 30 return 'K' 31 32 return 'k' 33 34 def unicode_symbol(self) -> str: 35 return UNICODE_PIECE_SYMBOLS[self.symbol()] 36 37 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 38 return self._move_vectors 39 40class Queen(chessai.core.piece.Piece, symbols = ('Q', 'q')): 41 """ The Queen in chess. """ 42 43 _move_vectors: list[chessai.core.piece.MoveVector] = [ 44 chessai.core.piece.MoveVector( 1, 0, num_repetitions = -1), 45 chessai.core.piece.MoveVector( 1, 1, num_repetitions = -1), 46 chessai.core.piece.MoveVector( 1, -1, num_repetitions = -1), 47 chessai.core.piece.MoveVector(-1, 0, num_repetitions = -1), 48 chessai.core.piece.MoveVector(-1, 1, num_repetitions = -1), 49 chessai.core.piece.MoveVector(-1, -1, num_repetitions = -1), 50 chessai.core.piece.MoveVector( 0, 1, num_repetitions = -1), 51 chessai.core.piece.MoveVector( 0, -1, num_repetitions = -1), 52 ] 53 54 def symbol(self) -> str: 55 if (self.color == chessai.core.types.Color.WHITE): 56 return 'Q' 57 58 return 'q' 59 60 def unicode_symbol(self) -> str: 61 return UNICODE_PIECE_SYMBOLS[self.symbol()] 62 63 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 64 return self._move_vectors 65 66class Rook(chessai.core.piece.Piece, symbols = ('R', 'r')): 67 """ The Rook in chess. """ 68 69 _move_vectors: list[chessai.core.piece.MoveVector] = [ 70 chessai.core.piece.MoveVector( 1, 0, num_repetitions = -1), 71 chessai.core.piece.MoveVector(-1, 0, num_repetitions = -1), 72 chessai.core.piece.MoveVector( 0, 1, num_repetitions = -1), 73 chessai.core.piece.MoveVector( 0, -1, num_repetitions = -1), 74 ] 75 76 def symbol(self) -> str: 77 if (self.color == chessai.core.types.Color.WHITE): 78 return 'R' 79 80 return 'r' 81 82 def unicode_symbol(self) -> str: 83 return UNICODE_PIECE_SYMBOLS[self.symbol()] 84 85 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 86 return self._move_vectors 87 88class Bishop(chessai.core.piece.Piece, symbols = ('B', 'b')): 89 """ The Bishop in chess. """ 90 91 _move_vectors: list[chessai.core.piece.MoveVector] = [ 92 chessai.core.piece.MoveVector( 1, 1, num_repetitions = -1), 93 chessai.core.piece.MoveVector(-1, 1, num_repetitions = -1), 94 chessai.core.piece.MoveVector( 1, -1, num_repetitions = -1), 95 chessai.core.piece.MoveVector(-1, -1, num_repetitions = -1), 96 ] 97 98 def symbol(self) -> str: 99 if (self.color == chessai.core.types.Color.WHITE): 100 return 'B' 101 102 return 'b' 103 104 def unicode_symbol(self) -> str: 105 return UNICODE_PIECE_SYMBOLS[self.symbol()] 106 107 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 108 return self._move_vectors 109 110class Knight(chessai.core.piece.Piece, symbols = ('N', 'n')): 111 """ The Knight in chess. """ 112 113 _move_vectors: list[chessai.core.piece.MoveVector] = [ 114 chessai.core.piece.MoveVector( 2, 1), 115 chessai.core.piece.MoveVector( 2, -1), 116 chessai.core.piece.MoveVector(-2, 1), 117 chessai.core.piece.MoveVector(-2, -1), 118 chessai.core.piece.MoveVector( 1, 2), 119 chessai.core.piece.MoveVector( 1, -2), 120 chessai.core.piece.MoveVector(-1, 2), 121 chessai.core.piece.MoveVector(-1, -2), 122 ] 123 124 def symbol(self) -> str: 125 if (self.color == chessai.core.types.Color.WHITE): 126 return 'N' 127 128 return 'n' 129 130 def unicode_symbol(self) -> str: 131 return UNICODE_PIECE_SYMBOLS[self.symbol()] 132 133 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 134 return self._move_vectors 135 136class Pawn(chessai.core.piece.Piece, symbols = ('P', 'p')): 137 """ The Pawn in chess. """ 138 139 _move_vectors: dict[chessai.core.types.Color, list[chessai.core.piece.MoveVector]] = { 140 chessai.core.types.Color.WHITE: [ 141 chessai.core.piece.MoveVector( 0, 1, kind = chessai.core.piece.MoveKind.PUSH), 142 chessai.core.piece.MoveVector( 1, 1, kind = chessai.core.piece.MoveKind.CAPTURE), 143 chessai.core.piece.MoveVector(-1, 1, kind = chessai.core.piece.MoveKind.CAPTURE), 144 ], 145 chessai.core.types.Color.BLACK: [ 146 chessai.core.piece.MoveVector( 0, -1, kind = chessai.core.piece.MoveKind.PUSH), 147 chessai.core.piece.MoveVector( 1, -1, kind = chessai.core.piece.MoveKind.CAPTURE), 148 chessai.core.piece.MoveVector(-1, -1, kind = chessai.core.piece.MoveKind.CAPTURE), 149 ], 150 } 151 152 def symbol(self) -> str: 153 if (self.color == chessai.core.types.Color.WHITE): 154 return 'P' 155 156 return 'p' 157 158 def unicode_symbol(self) -> str: 159 return UNICODE_PIECE_SYMBOLS[self.symbol()] 160 161 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 162 return self._move_vectors[self.color]
15class King(chessai.core.piece.Piece, symbols = ('K', 'k')): 16 """ The King in chess. """ 17 18 _move_vectors: list[chessai.core.piece.MoveVector] = [ 19 chessai.core.piece.MoveVector( 1, 0), 20 chessai.core.piece.MoveVector( 1, 1), 21 chessai.core.piece.MoveVector( 1, -1), 22 chessai.core.piece.MoveVector(-1, 0), 23 chessai.core.piece.MoveVector(-1, 1), 24 chessai.core.piece.MoveVector(-1, -1), 25 chessai.core.piece.MoveVector( 0, 1), 26 chessai.core.piece.MoveVector( 0, -1), 27 ] 28 29 def symbol(self) -> str: 30 if (self.color == chessai.core.types.Color.WHITE): 31 return 'K' 32 33 return 'k' 34 35 def unicode_symbol(self) -> str: 36 return UNICODE_PIECE_SYMBOLS[self.symbol()] 37 38 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 39 return self._move_vectors
The King in chess.
29 def symbol(self) -> str: 30 if (self.color == chessai.core.types.Color.WHITE): 31 return 'K' 32 33 return 'k'
Gets the symbol for the piece. Upper-case symbols are white pieces and lower-case symbols are black pieces.
Inherited Members
41class Queen(chessai.core.piece.Piece, symbols = ('Q', 'q')): 42 """ The Queen in chess. """ 43 44 _move_vectors: list[chessai.core.piece.MoveVector] = [ 45 chessai.core.piece.MoveVector( 1, 0, num_repetitions = -1), 46 chessai.core.piece.MoveVector( 1, 1, num_repetitions = -1), 47 chessai.core.piece.MoveVector( 1, -1, num_repetitions = -1), 48 chessai.core.piece.MoveVector(-1, 0, num_repetitions = -1), 49 chessai.core.piece.MoveVector(-1, 1, num_repetitions = -1), 50 chessai.core.piece.MoveVector(-1, -1, num_repetitions = -1), 51 chessai.core.piece.MoveVector( 0, 1, num_repetitions = -1), 52 chessai.core.piece.MoveVector( 0, -1, num_repetitions = -1), 53 ] 54 55 def symbol(self) -> str: 56 if (self.color == chessai.core.types.Color.WHITE): 57 return 'Q' 58 59 return 'q' 60 61 def unicode_symbol(self) -> str: 62 return UNICODE_PIECE_SYMBOLS[self.symbol()] 63 64 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 65 return self._move_vectors
The Queen in chess.
55 def symbol(self) -> str: 56 if (self.color == chessai.core.types.Color.WHITE): 57 return 'Q' 58 59 return 'q'
Gets the symbol for the piece. Upper-case symbols are white pieces and lower-case symbols are black pieces.
Inherited Members
67class Rook(chessai.core.piece.Piece, symbols = ('R', 'r')): 68 """ The Rook in chess. """ 69 70 _move_vectors: list[chessai.core.piece.MoveVector] = [ 71 chessai.core.piece.MoveVector( 1, 0, num_repetitions = -1), 72 chessai.core.piece.MoveVector(-1, 0, num_repetitions = -1), 73 chessai.core.piece.MoveVector( 0, 1, num_repetitions = -1), 74 chessai.core.piece.MoveVector( 0, -1, num_repetitions = -1), 75 ] 76 77 def symbol(self) -> str: 78 if (self.color == chessai.core.types.Color.WHITE): 79 return 'R' 80 81 return 'r' 82 83 def unicode_symbol(self) -> str: 84 return UNICODE_PIECE_SYMBOLS[self.symbol()] 85 86 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 87 return self._move_vectors
The Rook in chess.
77 def symbol(self) -> str: 78 if (self.color == chessai.core.types.Color.WHITE): 79 return 'R' 80 81 return 'r'
Gets the symbol for the piece. Upper-case symbols are white pieces and lower-case symbols are black pieces.
Inherited Members
89class Bishop(chessai.core.piece.Piece, symbols = ('B', 'b')): 90 """ The Bishop in chess. """ 91 92 _move_vectors: list[chessai.core.piece.MoveVector] = [ 93 chessai.core.piece.MoveVector( 1, 1, num_repetitions = -1), 94 chessai.core.piece.MoveVector(-1, 1, num_repetitions = -1), 95 chessai.core.piece.MoveVector( 1, -1, num_repetitions = -1), 96 chessai.core.piece.MoveVector(-1, -1, num_repetitions = -1), 97 ] 98 99 def symbol(self) -> str: 100 if (self.color == chessai.core.types.Color.WHITE): 101 return 'B' 102 103 return 'b' 104 105 def unicode_symbol(self) -> str: 106 return UNICODE_PIECE_SYMBOLS[self.symbol()] 107 108 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 109 return self._move_vectors
The Bishop in chess.
99 def symbol(self) -> str: 100 if (self.color == chessai.core.types.Color.WHITE): 101 return 'B' 102 103 return 'b'
Gets the symbol for the piece. Upper-case symbols are white pieces and lower-case symbols are black pieces.
Inherited Members
111class Knight(chessai.core.piece.Piece, symbols = ('N', 'n')): 112 """ The Knight in chess. """ 113 114 _move_vectors: list[chessai.core.piece.MoveVector] = [ 115 chessai.core.piece.MoveVector( 2, 1), 116 chessai.core.piece.MoveVector( 2, -1), 117 chessai.core.piece.MoveVector(-2, 1), 118 chessai.core.piece.MoveVector(-2, -1), 119 chessai.core.piece.MoveVector( 1, 2), 120 chessai.core.piece.MoveVector( 1, -2), 121 chessai.core.piece.MoveVector(-1, 2), 122 chessai.core.piece.MoveVector(-1, -2), 123 ] 124 125 def symbol(self) -> str: 126 if (self.color == chessai.core.types.Color.WHITE): 127 return 'N' 128 129 return 'n' 130 131 def unicode_symbol(self) -> str: 132 return UNICODE_PIECE_SYMBOLS[self.symbol()] 133 134 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 135 return self._move_vectors
The Knight in chess.
125 def symbol(self) -> str: 126 if (self.color == chessai.core.types.Color.WHITE): 127 return 'N' 128 129 return 'n'
Gets the symbol for the piece. Upper-case symbols are white pieces and lower-case symbols are black pieces.
Inherited Members
137class Pawn(chessai.core.piece.Piece, symbols = ('P', 'p')): 138 """ The Pawn in chess. """ 139 140 _move_vectors: dict[chessai.core.types.Color, list[chessai.core.piece.MoveVector]] = { 141 chessai.core.types.Color.WHITE: [ 142 chessai.core.piece.MoveVector( 0, 1, kind = chessai.core.piece.MoveKind.PUSH), 143 chessai.core.piece.MoveVector( 1, 1, kind = chessai.core.piece.MoveKind.CAPTURE), 144 chessai.core.piece.MoveVector(-1, 1, kind = chessai.core.piece.MoveKind.CAPTURE), 145 ], 146 chessai.core.types.Color.BLACK: [ 147 chessai.core.piece.MoveVector( 0, -1, kind = chessai.core.piece.MoveKind.PUSH), 148 chessai.core.piece.MoveVector( 1, -1, kind = chessai.core.piece.MoveKind.CAPTURE), 149 chessai.core.piece.MoveVector(-1, -1, kind = chessai.core.piece.MoveKind.CAPTURE), 150 ], 151 } 152 153 def symbol(self) -> str: 154 if (self.color == chessai.core.types.Color.WHITE): 155 return 'P' 156 157 return 'p' 158 159 def unicode_symbol(self) -> str: 160 return UNICODE_PIECE_SYMBOLS[self.symbol()] 161 162 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 163 return self._move_vectors[self.color]
The Pawn in chess.
153 def symbol(self) -> str: 154 if (self.color == chessai.core.types.Color.WHITE): 155 return 'P' 156 157 return 'p'
Gets the symbol for the piece. Upper-case symbols are white pieces and lower-case symbols are black pieces.
162 def move_vectors(self) -> list[chessai.core.piece.MoveVector]: 163 return self._move_vectors[self.color]
Returns the movement vectors for this piece.