Created
November 6, 2023 20:44
-
-
Save tae898/058eb5c7734024cfc1b14f2f6f6530b8 to your computer and use it in GitHub Desktop.
running-schnapsen.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"provenance": [], | |
"authorship_tag": "ABX9TyPJH8IbwZM7Ntg2UNmRKUtz", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/tae898/058eb5c7734024cfc1b14f2f6f6530b8/running-schnapsen.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"# Running schnapsen on Google Colab\n", | |
"\n", | |
"Although the proper way of cloning & installing repos and coding them is to do on your local machine, we have also provided this Jupyter Notebook for those who can't. Everything you run here is running on a Google server, not your machine. So the changes you make here will not stay forever. " | |
], | |
"metadata": { | |
"id": "Vie3UDqiJ3BY" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# Run this cell to clone and install the repo.\n", | |
"!rm -rf schnapsen && git clone https://github.com/intelligent-systems-course/schnapsen.git && cd schnapsen && pip install -e ." | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "1LX1rvQHK3Sa", | |
"outputId": "93738851-59e7-4ed5-a2bb-db5ec944ac1c" | |
}, | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Cloning into 'schnapsen'...\n", | |
"remote: Enumerating objects: 1446, done.\u001b[K\n", | |
"remote: Counting objects: 100% (572/572), done.\u001b[K\n", | |
"remote: Compressing objects: 100% (233/233), done.\u001b[K\n", | |
"remote: Total 1446 (delta 382), reused 390 (delta 323), pack-reused 874\u001b[K\n", | |
"Receiving objects: 100% (1446/1446), 2.09 MiB | 15.41 MiB/s, done.\n", | |
"Resolving deltas: 100% (767/767), done.\n", | |
"Obtaining file:///content/schnapsen\n", | |
" Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", | |
" Checking if build backend supports build_editable ... \u001b[?25l\u001b[?25hdone\n", | |
" Getting requirements to build editable ... \u001b[?25l\u001b[?25hdone\n", | |
" Preparing editable metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", | |
"Collecting class-resolver>=0.0.10 (from schnapsen==0.0.2)\n", | |
" Downloading class_resolver-0.4.2-py3-none-any.whl (24 kB)\n", | |
"Collecting click==8.0.1 (from schnapsen==0.0.2)\n", | |
" Downloading click-8.0.1-py3-none-any.whl (97 kB)\n", | |
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m97.4/97.4 kB\u001b[0m \u001b[31m3.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
"\u001b[?25hCollecting flask==2.2.2 (from schnapsen==0.0.2)\n", | |
" Downloading Flask-2.2.2-py3-none-any.whl (101 kB)\n", | |
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m101.5/101.5 kB\u001b[0m \u001b[31m11.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
"\u001b[?25hCollecting scikit-learn==1.2.0 (from schnapsen==0.0.2)\n", | |
" Downloading scikit_learn-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.5 MB)\n", | |
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m9.5/9.5 MB\u001b[0m \u001b[31m57.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
"\u001b[?25hCollecting joblib==1.1.1 (from schnapsen==0.0.2)\n", | |
" Downloading joblib-1.1.1-py2.py3-none-any.whl (309 kB)\n", | |
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m309.8/309.8 kB\u001b[0m \u001b[31m27.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
"\u001b[?25hCollecting Werkzeug==2.2.2 (from schnapsen==0.0.2)\n", | |
" Downloading Werkzeug-2.2.2-py3-none-any.whl (232 kB)\n", | |
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m232.7/232.7 kB\u001b[0m \u001b[31m23.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
"\u001b[?25hRequirement already satisfied: Jinja2>=3.0 in /usr/local/lib/python3.10/dist-packages (from flask==2.2.2->schnapsen==0.0.2) (3.1.2)\n", | |
"Requirement already satisfied: itsdangerous>=2.0 in /usr/local/lib/python3.10/dist-packages (from flask==2.2.2->schnapsen==0.0.2) (2.1.2)\n", | |
"Requirement already satisfied: numpy>=1.17.3 in /usr/local/lib/python3.10/dist-packages (from scikit-learn==1.2.0->schnapsen==0.0.2) (1.23.5)\n", | |
"Requirement already satisfied: scipy>=1.3.2 in /usr/local/lib/python3.10/dist-packages (from scikit-learn==1.2.0->schnapsen==0.0.2) (1.11.3)\n", | |
"Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn==1.2.0->schnapsen==0.0.2) (3.2.0)\n", | |
"Requirement already satisfied: MarkupSafe>=2.1.1 in /usr/local/lib/python3.10/dist-packages (from Werkzeug==2.2.2->schnapsen==0.0.2) (2.1.3)\n", | |
"Building wheels for collected packages: schnapsen\n", | |
" Building editable for schnapsen (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for schnapsen: filename=schnapsen-0.0.2-0.editable-py3-none-any.whl size=16184 sha256=4ba6fb4a0b2f2902fbea87c392318ebc7833f26d2a00edfd5f5b1f0821ec0584\n", | |
" Stored in directory: /tmp/pip-ephem-wheel-cache-7ebpdspb/wheels/da/6c/00/571695754102aa9379b491cead8d80ec69619f0fcd1dea6134\n", | |
"Successfully built schnapsen\n", | |
"Installing collected packages: Werkzeug, joblib, click, class-resolver, scikit-learn, flask, schnapsen\n", | |
" Attempting uninstall: Werkzeug\n", | |
" Found existing installation: Werkzeug 3.0.1\n", | |
" Uninstalling Werkzeug-3.0.1:\n", | |
" Successfully uninstalled Werkzeug-3.0.1\n", | |
" Attempting uninstall: joblib\n", | |
" Found existing installation: joblib 1.3.2\n", | |
" Uninstalling joblib-1.3.2:\n", | |
" Successfully uninstalled joblib-1.3.2\n", | |
" Attempting uninstall: click\n", | |
" Found existing installation: click 8.1.7\n", | |
" Uninstalling click-8.1.7:\n", | |
" Successfully uninstalled click-8.1.7\n", | |
" Attempting uninstall: scikit-learn\n", | |
" Found existing installation: scikit-learn 1.2.2\n", | |
" Uninstalling scikit-learn-1.2.2:\n", | |
" Successfully uninstalled scikit-learn-1.2.2\n", | |
" Attempting uninstall: flask\n", | |
" Found existing installation: Flask 2.2.5\n", | |
" Uninstalling Flask-2.2.5:\n", | |
" Successfully uninstalled Flask-2.2.5\n", | |
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", | |
"lida 0.0.10 requires fastapi, which is not installed.\n", | |
"lida 0.0.10 requires kaleido, which is not installed.\n", | |
"lida 0.0.10 requires python-multipart, which is not installed.\n", | |
"lida 0.0.10 requires uvicorn, which is not installed.\n", | |
"bigframes 0.10.0 requires scikit-learn>=1.2.2, but you have scikit-learn 1.2.0 which is incompatible.\u001b[0m\u001b[31m\n", | |
"\u001b[0mSuccessfully installed Werkzeug-2.2.2 class-resolver-0.4.2 click-8.0.1 flask-2.2.2 joblib-1.1.1 schnapsen-0.0.2 scikit-learn-1.2.0\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"## **Be sure to Restart runtime!!!! Otherwise the machine doesn't know that the schnapsen package is installed.**\n", | |
"\n", | |
"" | |
], | |
"metadata": { | |
"id": "xSGbjF7rMuyv" | |
} | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"Below is an example code. You can see that the schnapsen package has been installed and we can import it." | |
], | |
"metadata": { | |
"id": "eaderi2wNgQu" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"from schnapsen.bots import RandBot, RdeepBot\n", | |
"from schnapsen.game import SchnapsenGamePlayEngine\n", | |
"import random\n", | |
"\n", | |
"\n", | |
"engine = SchnapsenGamePlayEngine()\n", | |
"# choose the players\n", | |
"bot1 = RandBot(seed=random.randint(0, 100))\n", | |
"bot2 = RdeepBot(16, 4, random.Random(43))\n", | |
"winner_id, game_points, score = engine.play_game(\n", | |
" bot1, bot2, random.Random(random.randint(0, 100))\n", | |
")\n", | |
"print(f\"Game ended. Winner is {winner_id} with {game_points} points and {score}\")" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "Yf4iGlSmLOMi", | |
"outputId": "3f6e70a6-5253-4dff-d1f9-bbe4db41044d" | |
}, | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Game ended. Winner is <schnapsen.bots.rdeep.RdeepBot object at 0x7d964fb5a0b0> with 3 points and Score(direct_points=90, pending_points=0)\n" | |
] | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment