Николай обнови решението на 28.11.2022 14:59 (преди почти 3 години)
+class ChessException(Exception):
+    pass
+
+class ChessScore:
+    piece_scores = {
+        'p': 1,
+        'r': 5,
+        'n': 3,
+        'b': 3,
+        'k': 4,
+        'q': 9
+    }
+
+    def __init__(self, chess_pieces):
+        self.total_score = 0
+        for piece in chess_pieces:
+            self.total_score += ChessScore.piece_scores[piece.lower()]
+
+    def __int__(self):
+        return self.total_score
+
+    def __lt__(self, other):
+        return self.total_score < other.total_score
+
+    def __le__(self, other):
+        return self.total_score <= other.total_score
+
+    def __gt__(self, other):
+        return self.total_score > other.total_score
+
+    def __ge__(self, other):
+        return self.total_score >= other.total_score
+
+    def __eq__(self, other):
+        return self.total_score == other.total_score
+
+    def __ne__(self, other):
+        return self.total_score != other.total_score
+
+    def __add__(self, other):
+        return self.total_score + other.total_score
+
+    def __sub__(self, other):
+        return self.total_score - other.total_score
+
+class ChessPosition:
+    def __init__(self, chess_position_string):
+        self.chess_position_string = chess_position_string
+        self.white_pieces = []
+        self.black_pieces = []
+        self.board = [];
За точка и запетая взимаме точки. Махни го преди да го видя и с другото око :)
Опа, без да искам по навик съм я сложил :D
+        for row in chess_position_string.split("/"):
+            board_row = []
+            for piece in row:
+                if piece.isdigit():
+                    board_row.extend([''] * int(piece))
+                else:
+                    board_row.append(piece)
+            self.board.append(board_row)
+        self.validate_position()
+        for row in self.board:
+            for piece in row:
+                if piece.isalpha() and piece.isupper():
+                    self.white_pieces.append(piece)
+                elif piece.isalpha() and piece.islower():
+                    self.black_pieces.append(piece)
+
+    def validate_position(self):
+        white_king_count = 0
+        black_king_count = 0
+        pawn_positions_valid = True
+        for i in range(len(self.board)):
+            for j in range(len(self.board[i])):
+                if self.board[i][j] == 'K':
+                    white_king_position = (i, j)
+                    white_king_count += 1
+                elif self.board[i][j] == 'k':
+                    black_king_position = (i, j)
+                    black_king_count += 1
+                elif self.board[i][j] == 'P' or self.board[i][j] == 'p':
+                    if i == 0 or i == 7:
+                        pawn_positions_valid = False
+
+        if white_king_count != 1 or black_king_count != 1:
+            raise ChessException("kings")
+
+        if abs(white_king_position[0] - black_king_position[0]) <= 1 and abs(white_king_position[1] - black_king_position[1]) <= 1:
+            raise ChessException("kings")
+
+        if not pawn_positions_valid:
+            raise ChessException("pawns")
+
+    def get_white_score(self):
+        return ChessScore(self.white_pieces)
+
+    def get_black_score(self):
+        return ChessScore(self.black_pieces)
+
+    def white_is_winning(self):
+        return self.get_white_score() > self.get_black_score()
+
+    def black_is_winning(self):
+        return self.get_black_score() > self.get_white_score()
+
+    def is_equal(self):
+        return self.get_white_score() == self.get_black_score()
+
+    def __str__(self):
+        return self.chess_position_string
+
+    def __len__(self):
+        return len(self.white_pieces) + len(self.black_pieces)
+
+    def __getitem__(self, key):
Моля убеди се, че връщаш очаквания резултат във всички случаи.
+        column_idx = ord(key[0]) - ord('A')
+        row_idx = len(self.board) - int(key[1])
+        return self.board[row_idx][column_idx]

Моля убеди се, че връщаш очаквания резултат във всички случаи.