{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e8e6d2dc",
   "metadata": {},
   "source": [
    "# 12-06 · Wyścig Turtle\n",
    "\n",
    "Praktyka do sekcji [„Projekt 12-6”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ca1105b",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Wielu żółwi na tym samym ekranie jednocześnie."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "769be62b",
   "metadata": {},
   "source": [
    "## O losowości w tym laptopie\n",
    "\n",
    "Wyścig używa `random.randint()` dla każdego kroku żółwia – wynik może się różnić\n",
    "przy każdym starcie. Aby laptop działał przewidywalnie, tutaj również naprawiamy\n",
    "losowość przez `random.seed()`."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "769de055",
   "metadata": {},
   "source": [
    "## Ustawienie (wykonać raz)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "03e43b60",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:41:38.285900Z",
     "iopub.status.busy": "2026-08-17T16:41:38.285765Z",
     "iopub.status.idle": "2026-08-17T16:41:38.448225Z",
     "shell.execute_reply": "2026-08-17T16:41:38.447721Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Окно Turtle готово.\n"
     ]
    }
   ],
   "source": [
    "import turtle\n",
    "\n",
    "screen = turtle.Screen()\n",
    "artist = turtle.Turtle()\n",
    "artist.speed(0)\n",
    "print(\"Окно Turtle готово.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a0b1f5f",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "08e875e5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:41:38.449253Z",
     "iopub.status.busy": "2026-08-17T16:41:38.449071Z",
     "iopub.status.idle": "2026-08-17T16:41:41.846915Z",
     "shell.execute_reply": "2026-08-17T16:41:41.846347Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Победила черепашка цвета blue!\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "random.seed(3)\n",
    "screen.setup(500, 400)\n",
    "\n",
    "cveta = [\"red\", \"blue\", \"green\", \"orange\"]\n",
    "uchastniki = []\n",
    "\n",
    "for i, cvet in enumerate(cveta):\n",
    "    t = turtle.Turtle()\n",
    "    t.shape(\"turtle\")\n",
    "    t.color(cvet)\n",
    "    t.penup()\n",
    "    t.goto(-200, i * 40 - 60)\n",
    "    uchastniki.append(t)\n",
    "\n",
    "finish_line = 200\n",
    "pobeditel = None\n",
    "\n",
    "while pobeditel is None:\n",
    "    for t in uchastniki:\n",
    "        t.forward(random.randint(1, 10))\n",
    "        if t.xcor() >= finish_line:\n",
    "            pobeditel = t.pencolor()\n",
    "            break\n",
    "\n",
    "print(f\"Победила черепашка цвета {pobeditel}!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "36e0e7b3",
   "metadata": {},
   "source": [
    "## Ukończenie (wykonaj raz, na samym końcu)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bd989711",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:41:41.847887Z",
     "iopub.status.busy": "2026-08-17T16:41:41.847781Z",
     "iopub.status.idle": "2026-08-17T16:41:41.850788Z",
     "shell.execute_reply": "2026-08-17T16:41:41.850345Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Окно Turtle закрыто.\n"
     ]
    }
   ],
   "source": [
    "screen.bye()\n",
    "print(\"Окно Turtle закрыто.\")"
   ]
  }
 ],
 "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
}
