{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "82b46bcb",
   "metadata": {},
   "source": [
    "# 19-15 · Stan gry\n",
    "\n",
    "Praktyka do sekcji [„Game State”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5cf41fe",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Określić, które przejścia między stanami gry są legalne."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b699e168",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "089795bb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:53:52.713310Z",
     "iopub.status.busy": "2026-09-03T00:53:52.713152Z",
     "iopub.status.idle": "2026-09-03T00:53:52.738737Z",
     "shell.execute_reply": "2026-09-03T00:53:52.738165Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "LEGAL_TRANSITIONS = {\n",
    "    \"ready\": {\"running\"},\n",
    "    \"running\": {\"paused\", \"game_over\"},\n",
    "    \"paused\": {\"running\"},\n",
    "    \"game_over\": {\"ready\"},\n",
    "}\n",
    "\n",
    "def can_transition(current, target):\n",
    "    return target in LEGAL_TRANSITIONS[current]\n",
    "\n",
    "print(can_transition(\"running\", \"paused\"))\n",
    "print(can_transition(\"paused\", \"game_over\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dbaeb39d",
   "metadata": {},
   "source": [
    "## Podstawowa praktyka zadań ★"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4fb15969",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:53:52.740229Z",
     "iopub.status.busy": "2026-09-03T00:53:52.740083Z",
     "iopub.status.idle": "2026-09-03T00:53:52.743552Z",
     "shell.execute_reply": "2026-09-03T00:53:52.742800Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Только явно разрешённые переходы состояния считаются легальными.\n"
     ]
    }
   ],
   "source": [
    "assert can_transition(\"ready\", \"running\") is True\n",
    "assert can_transition(\"running\", \"paused\") is True\n",
    "assert can_transition(\"paused\", \"running\") is True\n",
    "assert can_transition(\"game_over\", \"ready\") is True\n",
    "assert can_transition(\"paused\", \"game_over\") is False\n",
    "assert can_transition(\"ready\", \"paused\") 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
}
