{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "61e5eb71",
   "metadata": {},
   "source": [
    "# 19-19 · Столкновение со стеной\n",
    "\n",
    "Практика к разделу [«Столкновение со стеной»](../../site/chapters/glava-19/19-19-stolknovenie-so-stenoj.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34454da8",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "is_wall_collision() — граница включена в легальную область."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "826e53ac",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a6df170f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:54:02.404873Z",
     "iopub.status.busy": "2026-09-03T00:54:02.404696Z",
     "iopub.status.idle": "2026-09-03T00:54:02.430841Z",
     "shell.execute_reply": "2026-09-03T00:54:02.430325Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "def is_wall_collision(head, half=280):\n",
    "    x, y = head\n",
    "    return abs(x) > half or abs(y) > half\n",
    "\n",
    "print(is_wall_collision((280, 0)))\n",
    "print(is_wall_collision((300, 0)))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "306c46f1",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "12da21ea",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:54:02.432231Z",
     "iopub.status.busy": "2026-09-03T00:54:02.432106Z",
     "iopub.status.idle": "2026-09-03T00:54:02.434759Z",
     "shell.execute_reply": "2026-09-03T00:54:02.434295Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Граница входит в легальную область; шаг за неё — столкновение.\n"
     ]
    }
   ],
   "source": [
    "assert is_wall_collision((280, 280)) is False\n",
    "assert is_wall_collision((-280, -280)) is False\n",
    "assert is_wall_collision((300, 0)) is True\n",
    "assert is_wall_collision((0, -281)) is True\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
}
