Screencast little changes

This commit is contained in:
2025-06-01 21:33:24 +02:00
parent 9acb871d9a
commit a742511152
2 changed files with 63 additions and 60 deletions

View File

@@ -16,9 +16,22 @@
"## Install requirements" "## Install requirements"
] ]
}, },
{
"cell_type": "markdown",
"id": "0e82420f",
"metadata": {},
"source": [
"create a virtual environment in current directory by \n",
"\n",
"```\n",
"python3 -m venv .env # macos\n",
"python -m venv .env # linux\n",
"```"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 7,
"id": "4a0d404f-b3bf-4984-99ae-e66168289ece", "id": "4a0d404f-b3bf-4984-99ae-e66168289ece",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@@ -26,25 +39,25 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Requirement already satisfied: prettytable in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (3.16.0)\n", "Requirement already satisfied: prettytable in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (3.16.0)\n",
"Requirement already satisfied: wcwidth in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from prettytable) (0.2.13)\n", "Requirement already satisfied: wcwidth in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from prettytable) (0.2.13)\n",
"Note: you may need to restart the kernel to use updated packages.\n", "Note: you may need to restart the kernel to use updated packages.\n",
"Requirement already satisfied: IPython in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (9.2.0)\n", "Requirement already satisfied: IPython in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (9.3.0)\n",
"Requirement already satisfied: decorator in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from IPython) (5.2.1)\n", "Requirement already satisfied: decorator in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from IPython) (5.2.1)\n",
"Requirement already satisfied: ipython-pygments-lexers in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from IPython) (1.1.1)\n", "Requirement already satisfied: ipython-pygments-lexers in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from IPython) (1.1.1)\n",
"Requirement already satisfied: jedi>=0.16 in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from IPython) (0.19.2)\n", "Requirement already satisfied: jedi>=0.16 in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from IPython) (0.19.2)\n",
"Requirement already satisfied: matplotlib-inline in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from IPython) (0.1.7)\n", "Requirement already satisfied: matplotlib-inline in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from IPython) (0.1.7)\n",
"Requirement already satisfied: pexpect>4.3 in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from IPython) (4.9.0)\n", "Requirement already satisfied: pexpect>4.3 in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from IPython) (4.9.0)\n",
"Requirement already satisfied: prompt_toolkit<3.1.0,>=3.0.41 in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from IPython) (3.0.51)\n", "Requirement already satisfied: prompt_toolkit<3.1.0,>=3.0.41 in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from IPython) (3.0.51)\n",
"Requirement already satisfied: pygments>=2.4.0 in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from IPython) (2.19.1)\n", "Requirement already satisfied: pygments>=2.4.0 in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from IPython) (2.19.1)\n",
"Requirement already satisfied: stack_data in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from IPython) (0.6.3)\n", "Requirement already satisfied: stack_data in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from IPython) (0.6.3)\n",
"Requirement already satisfied: traitlets>=5.13.0 in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from IPython) (5.14.3)\n", "Requirement already satisfied: traitlets>=5.13.0 in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from IPython) (5.14.3)\n",
"Requirement already satisfied: wcwidth in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from prompt_toolkit<3.1.0,>=3.0.41->IPython) (0.2.13)\n", "Requirement already satisfied: wcwidth in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from prompt_toolkit<3.1.0,>=3.0.41->IPython) (0.2.13)\n",
"Requirement already satisfied: parso<0.9.0,>=0.8.4 in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from jedi>=0.16->IPython) (0.8.4)\n", "Requirement already satisfied: parso<0.9.0,>=0.8.4 in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from jedi>=0.16->IPython) (0.8.4)\n",
"Requirement already satisfied: ptyprocess>=0.5 in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from pexpect>4.3->IPython) (0.7.0)\n", "Requirement already satisfied: ptyprocess>=0.5 in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from pexpect>4.3->IPython) (0.7.0)\n",
"Requirement already satisfied: executing>=1.2.0 in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from stack_data->IPython) (2.2.0)\n", "Requirement already satisfied: executing>=1.2.0 in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from stack_data->IPython) (2.2.0)\n",
"Requirement already satisfied: asttokens>=2.1.0 in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from stack_data->IPython) (3.0.0)\n", "Requirement already satisfied: asttokens>=2.1.0 in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from stack_data->IPython) (3.0.0)\n",
"Requirement already satisfied: pure-eval in /Users/safak/Documents/UNI/KI/.env/lib/python3.13/site-packages (from stack_data->IPython) (0.2.3)\n", "Requirement already satisfied: pure-eval in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (from stack_data->IPython) (0.2.3)\n",
"Note: you may need to restart the kernel to use updated packages.\n" "Note: you may need to restart the kernel to use updated packages.\n"
] ]
} }
@@ -64,7 +77,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 8,
"id": "feb2b662", "id": "feb2b662",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -83,7 +96,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 9,
"id": "e6feb484-d124-4d78-96fb-2fc3f9e1f22e", "id": "e6feb484-d124-4d78-96fb-2fc3f9e1f22e",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -102,7 +115,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 10,
"id": "ec176f38-2d91-47c3-ba8b-c9cce72f0c64", "id": "ec176f38-2d91-47c3-ba8b-c9cce72f0c64",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -202,7 +215,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 11,
"id": "214c239d-c8dc-473d-9bc9-cfcd64f40968", "id": "214c239d-c8dc-473d-9bc9-cfcd64f40968",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -280,7 +293,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 12,
"id": "06db06a3-ade5-47b6-8f69-aded023a89f7", "id": "06db06a3-ade5-47b6-8f69-aded023a89f7",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [

View File

@@ -31,7 +31,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 12,
"id": "55fa613b", "id": "55fa613b",
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
@@ -44,10 +44,7 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Requirement already satisfied: pygame in /home/safak/Dokumente/KI/KI/.env/lib64/python3.13/site-packages (2.6.1)\n", "Requirement already satisfied: pygame in /home/safak/Dokumente/Uni/KI/.env/lib64/python3.13/site-packages (2.6.1)\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.1.1\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n" "Note: you may need to restart the kernel to use updated packages.\n"
] ]
} }
@@ -66,7 +63,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 13,
"id": "e7034eee", "id": "e7034eee",
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
@@ -74,16 +71,7 @@
"start_time": "2025-05-07T21:40:23.718944Z" "start_time": "2025-05-07T21:40:23.718944Z"
} }
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"pygame 2.6.1 (SDL 2.28.4, Python 3.13.0)\n",
"Hello from the pygame community. https://www.pygame.org/contribute.html\n"
]
}
],
"source": [ "source": [
"import pygame\n", "import pygame\n",
"import math" "import math"
@@ -99,7 +87,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 14,
"id": "60b63344", "id": "60b63344",
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
@@ -119,7 +107,8 @@
"\n", "\n",
"WIDTH = 25\n", "WIDTH = 25\n",
"HEIGHT = 25\n", "HEIGHT = 25\n",
"MARGIN = 3\n" "MARGIN = 3\n",
"GRID_SIZE= 20"
] ]
}, },
{ {
@@ -127,12 +116,14 @@
"id": "87a05a3b", "id": "87a05a3b",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Classes " "## Classes \n",
"\n",
"The Queue Class is the same from Task 1"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 15,
"id": "84ad596c", "id": "84ad596c",
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
@@ -191,7 +182,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 16,
"id": "d3b77c0a", "id": "d3b77c0a",
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
@@ -229,7 +220,7 @@
" color = GREY\n", " color = GREY\n",
"\n", "\n",
" x_calc = (MARGIN + WIDTH) * self.x + MARGIN\n", " x_calc = (MARGIN + WIDTH) * self.x + MARGIN\n",
" y_calc = (MARGIN + HEIGHT) * (grid_size - 1 - self.y) + MARGIN # flipping\n", " y_calc = (MARGIN + HEIGHT) * (GRID_SIZE - 1 - self.y) + MARGIN # flipping\n",
"\n", "\n",
" pygame.draw.rect(\n", " pygame.draw.rect(\n",
" screen,\n", " screen,\n",
@@ -240,7 +231,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 17,
"id": "b3d9f04f", "id": "b3d9f04f",
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
@@ -332,7 +323,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 18,
"id": "53c20ed6", "id": "53c20ed6",
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
@@ -342,14 +333,14 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"grid_size = 20\n", "\n",
"window_width = grid_size * (WIDTH + MARGIN) + MARGIN\n", "window_width = GRID_SIZE * (WIDTH + MARGIN) + MARGIN\n",
"window_height = grid_size * (HEIGHT + MARGIN) + MARGIN\n", "window_height = GRID_SIZE * (HEIGHT + MARGIN) + MARGIN\n",
"size = (window_width, window_height) # made size variable\n", "size = (window_width, window_height) # made size variable\n",
"\n", "\n",
"start = (0, 0)\n", "start = (0, 0)\n",
"target = (19, 19)\n", "target = (19, 19)\n",
"grid = Grid(grid_size, grid_size)\n", "grid = Grid(GRID_SIZE, GRID_SIZE)\n",
"\n", "\n",
"# check if start an target are valid\n", "# check if start an target are valid\n",
"if 0 <= start[0] < grid.cols and 0 <= target[0] < grid.cols and 0 <= start[1] < grid.cols and 0 <= target[\n", "if 0 <= start[0] < grid.cols and 0 <= target[0] < grid.cols and 0 <= start[1] < grid.cols and 0 <= target[\n",
@@ -368,7 +359,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 19,
"id": "d01d53b0", "id": "d01d53b0",
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
@@ -398,7 +389,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 20,
"id": "d480bcf1", "id": "d480bcf1",
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
@@ -426,7 +417,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 21,
"id": "a8c78a46", "id": "a8c78a46",
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
@@ -445,7 +436,7 @@
" screen.fill(BLACK)\n", " screen.fill(BLACK)\n",
" grid.draw(screen)\n", " grid.draw(screen)\n",
" pygame.display.flip()\n", " pygame.display.flip()\n",
" clock.tick(30)" " clock.tick(60)"
] ]
}, },
{ {
@@ -458,7 +449,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 22,
"id": "4c138642", "id": "4c138642",
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
@@ -499,8 +490,7 @@
" update_screen()\n", " update_screen()\n",
"\n", "\n",
" open.clear()\n", " open.clear()\n",
" done = True\n", " # done = True\n",
"\n",
"\n", "\n",
" closed.push(current_field)\n", " closed.push(current_field)\n",
" grid.set_visited(current_field.x, current_field.y)\n", " grid.set_visited(current_field.x, current_field.y)\n",
@@ -556,7 +546,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.13.0" "version": "3.13.3"
} }
}, },
"nbformat": 4, "nbformat": 4,