Загрузка данных


import numpy as np

np.random.seed(42)

board = np.zeros((8, 8), dtype=np.int32)

black_cells = np.where((np.arange(8)[:, None] + np.arange(8)) % 2 == 0)
black_cells = list(zip(black_cells[0], black_cells[1]))

chosen_indices = np.random.choice(len(black_cells), size=16, replace=False)
chosen_cells = [black_cells[i] for i in chosen_indices]

for idx in range(8):
    i, j = chosen_cells[idx]
    board[i, j] = 1

for idx in range(8, 16):
    i, j = chosen_cells[idx]
    board[i, j] = -1

print(board)


def count_captures(board, player):
    opponent = -player
    captures = 0
    directions = [(-1, -1), (-1, 1), (1, -1), (1, 1)]

    positions = np.where(board == player)
    positions = list(zip(positions[0], positions[1]))

    for i, j in positions:
        for di, dj in directions:
            ni, nj = i + di, j + dj
            bi, bj = i + 2 * di, j + 2 * dj
            if 0 <= ni < 8 and 0 <= nj < 8 and 0 <= bi < 8 and 0 <= bj < 8:
                if board[ni, nj] == opponent and board[bi, bj] == 0:
                    captures += 1

    return captures


captures_white = count_captures(board, 1)
captures_black = count_captures(board, -1)
print(captures_white)
print(captures_black)