{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext blackcellmagic" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from typing import Final\n", "from scipy.ndimage import binary_dilation\n", "from tqdm.auto import tqdm\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "ENEMY: Final[int] = -1\n", "PLAYER: Final[int] = 1\n", "BOARD_SIZE: Final[int] = 8" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[-1, -1],\n", " [-1, 0],\n", " [-1, 1],\n", " [ 0, -1],\n", " [ 0, 1],\n", " [ 1, -1],\n", " [ 1, 0],\n", " [ 1, 1]])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DIRECTIONS: Final[np.ndarray] = np.array(\n", " [[i, j] for i in range(-1, 2) for j in range(-1, 2) if j != 0 or i != 0], dtype=int\n", ")\n", "DIRECTIONS" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 0, 0, 0, 0, 0, 0, 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0],\n", " [ 0, 0, 0, -1, 1, 0, 0, 0],\n", " [ 0, 0, 0, 1, -1, 0, 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0]])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def get_new_games(number_of_games: int):\n", " empty = np.zeros([number_of_games, BOARD_SIZE, BOARD_SIZE], dtype=int)\n", " empty[:, 3:5, 3:5] = np.array([[-1, 1], [1, -1]])\n", " return empty\n", "\n", "\n", "get_new_games(1)[0]" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "test_number_of_games = 3\n", "assert get_new_games(test_number_of_games).shape == (\n", " test_number_of_games,\n", " BOARD_SIZE,\n", " BOARD_SIZE,\n", ")\n", "np.testing.assert_equal(\n", " get_new_games(test_number_of_games).sum(axis=1),\n", " np.zeros(\n", " [\n", " test_number_of_games,\n", " 8,\n", " ]\n", " ),\n", ")\n", "np.testing.assert_equal(\n", " get_new_games(test_number_of_games).sum(axis=2),\n", " np.zeros(\n", " [\n", " test_number_of_games,\n", " 8,\n", " ]\n", " ),\n", ")\n", "assert np.all(get_new_games(test_number_of_games)[:, 3:4, 3:4] != 0)\n", "del test_number_of_games" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "def plot_othello_board(board, ax=None):\n", " size = 3\n", " plot_all = False\n", " if ax is None:\n", " plot_all = True\n", " fig, ax = plt.subplots(figsize=(size, size))\n", "\n", " ax.set_facecolor(\"green\")\n", " for i in range(BOARD_SIZE):\n", " for j in range(BOARD_SIZE):\n", " if board[i, j] == -1:\n", " color = \"white\"\n", " elif board[i, j] == 1:\n", " color = \"black\"\n", " else:\n", " continue\n", " ax.scatter(j, i, s=300 if plot_all else 150, c=color)\n", " for i in range(-1, 8):\n", " ax.axhline(i + 0.5, color=\"black\", lw=2)\n", " ax.axvline(i + 0.5, color=\"black\", lw=2)\n", " ax.set_xlim(-0.5, 7.5)\n", " ax.set_ylim(7.5, -0.5)\n", " ax.set_xticks(np.arange(8))\n", " ax.set_xticklabels(list(\"ABCDEFGH\"))\n", " ax.set_yticks(np.arange(8))\n", " ax.set_yticklabels(list(\"12345678\"))\n", " if plot_all:\n", " plt.tight_layout()\n", " plt.show()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "def plot_othello_boards(boards: np.ndarray) -> None:\n", " assert boards.shape[0] < 70\n", " plots_per_row = 4\n", " rows = int(np.ceil(boards.shape[0] / plots_per_row))\n", " fig, axs = plt.subplots(rows, plots_per_row, figsize=(12, 3 * rows))\n", " for game_index, ax in enumerate(axs.flatten()):\n", " if game_index >= boards.shape[0]:\n", " fig.delaxes(ax)\n", " else:\n", " plot_othello_board(boards[game_index], ax)\n", " plt.tight_layout()\n", " plt.show()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "8.49 ms ± 143 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", "80.9 ms ± 537 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" ] }, { "data": { "text/plain": [ "array([[[False, False, False, False, False, False, False, False],\n", " [False, False, False, False, False, False, False, False],\n", " [False, False, False, True, False, False, False, False],\n", " [False, False, True, False, False, False, False, False],\n", " [False, False, False, False, False, True, False, False],\n", " [False, False, False, False, True, False, False, False],\n", " [False, False, False, False, False, False, False, False],\n", " [False, False, False, False, False, False, False, False]]])" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def recursive_steps(_array, rec_direction, rec_position, step_one=True):\n", " rec_position = rec_position + rec_direction\n", " if np.any((rec_position >= BOARD_SIZE) | (rec_position < 0)):\n", " return False\n", " next_field = _array[tuple(rec_position.tolist())]\n", " if next_field == 0:\n", " return False\n", " if next_field == -1:\n", " return recursive_steps(_array, rec_direction, rec_position, step_one=False)\n", " if next_field == 1:\n", " return not step_one\n", "\n", "\n", "def get_possible_turns(boards: np.ndarray) -> np.ndarray:\n", " _poss_turns = (boards == 0) & binary_dilation(\n", " boards == -1, np.array([[[1, 1, 1], [1, 0, 1], [1, 1, 1]]])\n", " )\n", " for game in range(boards.shape[0]):\n", " for idx in range(BOARD_SIZE):\n", " for idy in range(BOARD_SIZE):\n", "\n", " position = idx, idy\n", " if _poss_turns[game, idx, idy]:\n", " _poss_turns[game, idx, idy] = any(\n", " recursive_steps(boards[game, :, :], direction, position)\n", " for direction in DIRECTIONS\n", " )\n", " return _poss_turns\n", "\n", "\n", "%timeit get_possible_turns(get_new_games(10))\n", "%timeit get_possible_turns(get_new_games(100))\n", "get_possible_turns(get_new_games(3))[:1]" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([2, 2, 2]), array([2, 2, 2]))" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def evaluate_boards(array: np.ndarray):\n", " return np.sum(array == 1, axis=(1, 2)), np.sum(array == -1, axis=(1, 2))\n", "\n", "\n", "evaluate_boards(get_new_games(3))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def move_possible(board: np.ndarray, move: np.ndarray) -> bool:\n", " if np.all(move == -1):\n", " return np.all(get_possible_turns(board))\n", " return any(\n", " recursive_steps(board[:, :], direction, move) for direction in DIRECTIONS\n", " )\n", "\n", "\n", "def moves_possible(boards: np.ndarray, moves: np.ndarray) -> np.ndarray:\n", " arr_moves_possible = np.zeros(boards.shape[0], dtype=bool)\n", " for game in range(boards.shape[0]):\n", " if np.all(moves[game] == -1):\n", " arr_moves_possible[game, :, :] = np.all(\n", " get_possible_turns(boards[game, :, :])\n", " )\n", " arr_moves_possible[game, :, :] = any(\n", " recursive_steps(boards[game, :, :], direction, moves[game])\n", " for direction in DIRECTIONS\n", " )\n", " return arr_moves_possible" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 0, 0, 0, 0, 0, 0, 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0],\n", " [ 0, 0, 0, -1, 0, 0, 0, 0],\n", " [ 0, 0, 0, -1, -1, 0, 0, 0],\n", " [ 0, 0, 0, -1, 1, 0, 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0]])" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "class InvalidTurn(ValueError):\n", " pass\n", "\n", "\n", "def to_moves(boards: np.ndarray, moves: np.ndarray) -> np.ndarray:\n", " def _do_directional_move(\n", " board: np.ndarray, rec_move: np.ndarray, rev_direction, step_one=True\n", " ) -> bool:\n", " rec_position = rec_move + rev_direction\n", " if np.any((rec_position >= 8) | (rec_position < 0)):\n", " return False\n", " next_field = board[tuple(rec_position.tolist())]\n", " if next_field == 0:\n", " return False\n", " if next_field == 1:\n", " return not step_one\n", " if next_field == -1:\n", " if _do_directional_move(board, rec_position, rev_direction, step_one=False):\n", " board[tuple(rec_position.tolist())] = 1\n", " return True\n", " return False\n", "\n", " def _do_move(_board: np.ndarray, move: np.ndarray) -> None:\n", " if _board[tuple(move.tolist())] != 0:\n", " raise InvalidTurn\n", " action = False\n", " for direction in DIRECTIONS:\n", " if _do_directional_move(_board, move, direction):\n", " action = True\n", " if not action:\n", " raise InvalidTurn()\n", " _board[tuple(move.tolist())] = 1\n", "\n", " for game in range(boards.shape[0]):\n", " _do_move(boards[game], moves[game])\n", "\n", "\n", "boards = get_new_games(10)\n", "to_moves(boards, np.array([[2, 3]] * 10))\n", "boards = boards * -1\n", "boards[0]" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "to_moves(get_new_games(10), np.array([[2, 3]] * 10))" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[4, 3],\n", " [4, 3],\n", " [4, 3],\n", " [4, 3],\n", " [4, 3],\n", " [4, 3],\n", " [4, 3],\n", " [4, 3],\n", " [4, 3],\n", " [4, 3]])" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.array([[4, 3]] * 10)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def create_test_game():\n", " test_array = []\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 1, 2, 0, 0, 0],\n", " [0, 0, 0, 2, 1, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 2, 0, 0, 0],\n", " [0, 0, 0, 2, 1, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 2, 0, 0, 0],\n", " [0, 0, 1, 1, 1, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 2, 0, 0, 0],\n", " [0, 0, 2, 1, 1, 0, 0, 0],\n", " [0, 2, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 1, 2, 0, 0, 0],\n", " [0, 0, 2, 1, 1, 0, 0, 0],\n", " [0, 2, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 0, 0, 0],\n", " [0, 0, 0, 1, 2, 0, 0, 0],\n", " [0, 0, 2, 1, 1, 0, 0, 0],\n", " [0, 2, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 0, 0, 0],\n", " [0, 0, 0, 1, 2, 0, 0, 0],\n", " [0, 0, 2, 2, 2, 2, 0, 0],\n", " [0, 2, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 0, 0, 0],\n", " [0, 0, 0, 1, 1, 1, 0, 0],\n", " [0, 0, 2, 2, 2, 2, 0, 0],\n", " [0, 2, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 2, 0, 0],\n", " [0, 0, 0, 1, 2, 2, 0, 0],\n", " [0, 0, 2, 2, 2, 2, 0, 0],\n", " [0, 2, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 2, 0, 0],\n", " [0, 0, 0, 1, 2, 2, 0, 0],\n", " [0, 0, 2, 2, 1, 2, 0, 0],\n", " [0, 2, 0, 0, 0, 1, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 2, 0, 0],\n", " [0, 0, 0, 1, 2, 2, 0, 0],\n", " [0, 0, 2, 2, 1, 2, 0, 0],\n", " [0, 2, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 2, 0, 0],\n", " [0, 0, 0, 1, 2, 2, 0, 0],\n", " [0, 1, 1, 1, 1, 2, 0, 0],\n", " [0, 2, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 2, 0, 0],\n", " [0, 0, 0, 1, 2, 2, 0, 0],\n", " [2, 2, 2, 2, 2, 2, 0, 0],\n", " [0, 2, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 2, 0, 0],\n", " [0, 0, 0, 1, 1, 1, 1, 0],\n", " [2, 2, 2, 2, 2, 2, 0, 0],\n", " [0, 2, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 0, 2, 0, 0],\n", " [0, 0, 0, 1, 1, 1, 1, 0],\n", " [2, 2, 2, 1, 2, 2, 0, 0],\n", " [0, 2, 0, 1, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 0, 0, 0],\n", " [0, 0, 0, 2, 2, 2, 0, 0],\n", " [0, 0, 0, 2, 2, 1, 1, 0],\n", " [2, 2, 2, 1, 2, 2, 0, 0],\n", " [0, 2, 0, 1, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 1, 0, 0],\n", " [0, 0, 0, 2, 2, 1, 0, 0],\n", " [0, 0, 0, 2, 2, 1, 1, 0],\n", " [2, 2, 2, 1, 2, 2, 0, 0],\n", " [0, 2, 0, 1, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 1, 0, 0],\n", " [0, 0, 0, 2, 2, 2, 2, 0],\n", " [0, 0, 0, 2, 2, 2, 1, 0],\n", " [2, 2, 2, 1, 2, 2, 0, 0],\n", " [0, 2, 0, 1, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 1, 0, 0],\n", " [0, 0, 0, 2, 1, 2, 2, 0],\n", " [0, 0, 0, 2, 2, 1, 1, 0],\n", " [2, 2, 2, 1, 1, 1, 1, 0],\n", " [0, 2, 0, 1, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 1, 0, 0],\n", " [0, 0, 0, 2, 1, 2, 2, 0],\n", " [0, 0, 0, 2, 2, 1, 2, 0],\n", " [2, 2, 2, 2, 2, 2, 2, 2],\n", " [0, 2, 0, 1, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array.append(\n", " np.array(\n", " [\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " [0, 0, 2, 1, 0, 1, 0, 0],\n", " [0, 0, 0, 2, 1, 2, 2, 0],\n", " [0, 0, 0, 2, 1, 1, 2, 0],\n", " [2, 2, 2, 2, 1, 2, 2, 2],\n", " [0, 2, 0, 1, 1, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 2, 0, 0],\n", " [0, 0, 0, 0, 0, 0, 0, 0],\n", " ]\n", " )\n", " )\n", " test_array = np.array(test_array)\n", " test_array[test_array == 2] = -1\n", " assert np.all(np.diff(np.count_nonzero(create_test_game(), axis=(1, 2))) == 1)\n", " return test_array\n", "\n", "\n", "plot_othello_boards(create_test_game()[-3:])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "np.diff(create_test_game(), axis=0).shape" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.8" } }, "nbformat": 4, "nbformat_minor": 1 }