{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "42e02ad3",
   "metadata": {},
   "source": [
    "# 19-26 · Чистая игровая логика без Turtle\n",
    "\n",
    "Практика к разделу [«Чистая игровая логика без Turtle»](../../site/chapters/glava-19/19-26-chistaya-logika.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "381c7231",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Отличить функции правил (чистая логика) от кода, которому нужен реальный экран."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21a76e51",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "611e7a5c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:54:22.651711Z",
     "iopub.status.busy": "2026-09-03T00:54:22.651528Z",
     "iopub.status.idle": "2026-09-03T00:54:22.675621Z",
     "shell.execute_reply": "2026-09-03T00:54:22.675075Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True False\n"
     ]
    }
   ],
   "source": [
    "PURE_LOGIC_NAMES = {\n",
    "    \"next_head\", \"move_snake\", \"is_wall_collision\",\n",
    "    \"is_self_collision\", \"choose_food\", \"calculate_delay\",\n",
    "}\n",
    "NEEDS_SCREEN_NAMES = {\"render\", \"bind_keys\", \"game_tick_ontimer_wrapper\"}\n",
    "\n",
    "def is_pure_logic(name):\n",
    "    return name in PURE_LOGIC_NAMES\n",
    "\n",
    "print(is_pure_logic(\"next_head\"), is_pure_logic(\"render\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6f30aa0",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5bb499da",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:54:22.676941Z",
     "iopub.status.busy": "2026-09-03T00:54:22.676804Z",
     "iopub.status.idle": "2026-09-03T00:54:22.679638Z",
     "shell.execute_reply": "2026-09-03T00:54:22.679121Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Правила игры не зависят от экрана — отображение зависит.\n"
     ]
    }
   ],
   "source": [
    "assert is_pure_logic(\"move_snake\") is True\n",
    "assert is_pure_logic(\"is_wall_collision\") is True\n",
    "assert is_pure_logic(\"render\") is False\n",
    "assert is_pure_logic(\"bind_keys\") is False\n",
    "print(\"Правила игры не зависят от экрана — отображение зависит.\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "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.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
