{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8d1b30ea",
   "metadata": {},
   "source": [
    "# 19-22 · Pause / Resume\n",
    "\n",
    "Praktyka do sekcji [„Pause / Resume”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2cbae2a",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Tick nie powinien zmieniać modelu podczas PAUSED."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28a89f5d",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0a82e9ef",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:54:09.819598Z",
     "iopub.status.busy": "2026-09-03T00:54:09.819380Z",
     "iopub.status.idle": "2026-09-03T00:54:09.843265Z",
     "shell.execute_reply": "2026-09-03T00:54:09.842524Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(0, 0), (-20, 0)] paused\n"
     ]
    }
   ],
   "source": [
    "STEP = 20\n",
    "DIRECTION_VECTORS = {\n",
    "    \"up\": (0, STEP), \"down\": (0, -STEP),\n",
    "    \"left\": (-STEP, 0), \"right\": (STEP, 0),\n",
    "}\n",
    "\n",
    "def game_tick(snake, status, direction):\n",
    "    if status != \"running\":\n",
    "        return snake, status   # ничего не меняется\n",
    "    dx, dy = DIRECTION_VECTORS[direction]\n",
    "    new_head = (snake[0][0] + dx, snake[0][1] + dy)\n",
    "    new_snake = [new_head, *snake[:-1]]\n",
    "    return new_snake, status\n",
    "\n",
    "snake = [(0, 0), (-20, 0)]\n",
    "snake, status = game_tick(snake, \"paused\", \"right\")\n",
    "print(snake, status)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df53dd1f",
   "metadata": {},
   "source": [
    "## Podstawowa praktyka zadań ★"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b7c324d9",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:54:09.845322Z",
     "iopub.status.busy": "2026-09-03T00:54:09.845154Z",
     "iopub.status.idle": "2026-09-03T00:54:09.848790Z",
     "shell.execute_reply": "2026-09-03T00:54:09.848186Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "PAUSED действительно замораживает модель — RUNNING продолжает её двигать.\n"
     ]
    }
   ],
   "source": [
    "before = [(0, 0), (-20, 0)]\n",
    "after, status = game_tick(list(before), \"paused\", \"right\")\n",
    "assert after == before\n",
    "running_after, _ = game_tick(list(before), \"running\", \"right\")\n",
    "assert running_after != before\n",
    "print(\"PAUSED действительно замораживает модель — RUNNING продолжает её двигать.\")"
   ]
  }
 ],
 "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
}
