{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5938683d",
   "metadata": {},
   "source": [
    "# 19-12 · Один игровой тик\n",
    "\n",
    "Практика к разделу [«Один игровой тик»](../../site/chapters/glava-19/19-12-odin-igrovoj-tik.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7074296a",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Проверить еду ДО применения нового тела — порядок шагов тика имеет значение."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6e56c6e",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8a0c9fd4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:53:44.598389Z",
     "iopub.status.busy": "2026-09-03T00:53:44.598263Z",
     "iopub.status.idle": "2026-09-03T00:53:44.615265Z",
     "shell.execute_reply": "2026-09-03T00:53:44.614674Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(20, 0), (0, 0), (-20, 0)] True\n"
     ]
    }
   ],
   "source": [
    "def tick_order(head, food, snake_without_head):\n",
    "    grow = head == food\n",
    "    if grow:\n",
    "        new_snake = [head, *snake_without_head]\n",
    "    else:\n",
    "        new_snake = [head, *snake_without_head[:-1]]\n",
    "    return new_snake, grow\n",
    "\n",
    "new_snake, grow = tick_order((20, 0), (20, 0), [(0, 0), (-20, 0)])\n",
    "print(new_snake, grow)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c8e98fe",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "16d5a755",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:53:44.616876Z",
     "iopub.status.busy": "2026-09-03T00:53:44.616735Z",
     "iopub.status.idle": "2026-09-03T00:53:44.619856Z",
     "shell.execute_reply": "2026-09-03T00:53:44.619310Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Еда проверяется раньше сборки нового тела — рост считается верно.\n"
     ]
    }
   ],
   "source": [
    "snake_no_food, grow_no_food = tick_order((20, 0), (100, 100), [(0, 0), (-20, 0)])\n",
    "assert grow_no_food is False\n",
    "assert len(snake_no_food) == 2\n",
    "\n",
    "snake_food, grow_food = tick_order((20, 0), (20, 0), [(0, 0), (-20, 0)])\n",
    "assert grow_food is True\n",
    "assert len(snake_food) == 3\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
}
