Created
July 28, 2020 09:14
-
-
Save faizankshaikh/e23db80bdcdcb14176d492d505ee46b4 to your computer and use it in GitHub Desktop.
play2048.ipynb
This file contains 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": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"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.7.1" | |
}, | |
"colab": { | |
"name": "play2048.ipynb", | |
"provenance": [], | |
"include_colab_link": true | |
}, | |
"widgets": { | |
"application/vnd.jupyter.widget-state+json": { | |
"aec7052b113045bb9d5a4653da539160": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "GridBoxModel", | |
"state": { | |
"_view_name": "GridBoxView", | |
"_dom_classes": [], | |
"_model_name": "GridBoxModel", | |
"_view_module": "@jupyter-widgets/controls", | |
"_model_module_version": "1.5.0", | |
"_view_count": null, | |
"_view_module_version": "1.5.0", | |
"box_style": "", | |
"layout": "IPY_MODEL_80215633877d4f61bb7a6cbd486b86a8", | |
"_model_module": "@jupyter-widgets/controls", | |
"children": [ | |
"IPY_MODEL_ff452046f6c047c1bef8eac1a680260f", | |
"IPY_MODEL_2fea5b881dc94046a2212eb98b79db76", | |
"IPY_MODEL_7252e2bace0c4523a8cfab97d5ab7e59", | |
"IPY_MODEL_ca36d56a41ea4e5aa6294aa100d07f9b" | |
] | |
} | |
}, | |
"80215633877d4f61bb7a6cbd486b86a8": { | |
"model_module": "@jupyter-widgets/base", | |
"model_name": "LayoutModel", | |
"state": { | |
"_view_name": "LayoutView", | |
"grid_template_rows": "auto", | |
"right": null, | |
"justify_content": null, | |
"_view_module": "@jupyter-widgets/base", | |
"overflow": null, | |
"_model_module_version": "1.2.0", | |
"_view_count": null, | |
"flex_flow": null, | |
"width": "25%", | |
"min_width": null, | |
"border": null, | |
"align_items": null, | |
"bottom": null, | |
"_model_module": "@jupyter-widgets/base", | |
"top": null, | |
"grid_column": null, | |
"overflow_y": null, | |
"overflow_x": null, | |
"grid_auto_flow": null, | |
"grid_area": null, | |
"grid_template_columns": "auto", | |
"flex": null, | |
"_model_name": "LayoutModel", | |
"justify_items": null, | |
"grid_row": null, | |
"max_height": null, | |
"align_content": null, | |
"visibility": null, | |
"align_self": null, | |
"height": null, | |
"min_height": null, | |
"padding": null, | |
"grid_auto_rows": null, | |
"grid_gap": null, | |
"max_width": null, | |
"order": null, | |
"_view_module_version": "1.2.0", | |
"grid_template_areas": "\n \". btn_up btn_up .\"\n \"btn_left btn_left btn_right btn_right\"\n \". btn_down btn_down .\"\n ", | |
"object_position": null, | |
"object_fit": null, | |
"grid_auto_columns": null, | |
"margin": null, | |
"display": null, | |
"left": null | |
} | |
}, | |
"ff452046f6c047c1bef8eac1a680260f": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "ButtonModel", | |
"state": { | |
"_view_name": "ButtonView", | |
"style": "IPY_MODEL_44572c445fc541818f129e21e1d6fab7", | |
"_dom_classes": [], | |
"description": "Up", | |
"_model_name": "ButtonModel", | |
"button_style": "", | |
"_view_module": "@jupyter-widgets/controls", | |
"_model_module_version": "1.5.0", | |
"tooltip": "", | |
"_view_count": null, | |
"disabled": false, | |
"_view_module_version": "1.5.0", | |
"layout": "IPY_MODEL_35040a876526427a9ce40610bd0e21ae", | |
"_model_module": "@jupyter-widgets/controls", | |
"icon": "" | |
} | |
}, | |
"2fea5b881dc94046a2212eb98b79db76": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "ButtonModel", | |
"state": { | |
"_view_name": "ButtonView", | |
"style": "IPY_MODEL_e56924ff06da46a1b1085832db843f9d", | |
"_dom_classes": [], | |
"description": "Left", | |
"_model_name": "ButtonModel", | |
"button_style": "", | |
"_view_module": "@jupyter-widgets/controls", | |
"_model_module_version": "1.5.0", | |
"tooltip": "", | |
"_view_count": null, | |
"disabled": false, | |
"_view_module_version": "1.5.0", | |
"layout": "IPY_MODEL_c635c7693e6240c8b206488b1a9024a1", | |
"_model_module": "@jupyter-widgets/controls", | |
"icon": "" | |
} | |
}, | |
"7252e2bace0c4523a8cfab97d5ab7e59": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "ButtonModel", | |
"state": { | |
"_view_name": "ButtonView", | |
"style": "IPY_MODEL_c57d739c42724941aa8f35e5b92ea51e", | |
"_dom_classes": [], | |
"description": "Right", | |
"_model_name": "ButtonModel", | |
"button_style": "", | |
"_view_module": "@jupyter-widgets/controls", | |
"_model_module_version": "1.5.0", | |
"tooltip": "", | |
"_view_count": null, | |
"disabled": false, | |
"_view_module_version": "1.5.0", | |
"layout": "IPY_MODEL_f61d8ce574f44114b9f4effd7d3c8084", | |
"_model_module": "@jupyter-widgets/controls", | |
"icon": "" | |
} | |
}, | |
"ca36d56a41ea4e5aa6294aa100d07f9b": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "ButtonModel", | |
"state": { | |
"_view_name": "ButtonView", | |
"style": "IPY_MODEL_667745526f9c4038bbf229074dc714e7", | |
"_dom_classes": [], | |
"description": "Down", | |
"_model_name": "ButtonModel", | |
"button_style": "", | |
"_view_module": "@jupyter-widgets/controls", | |
"_model_module_version": "1.5.0", | |
"tooltip": "", | |
"_view_count": null, | |
"disabled": false, | |
"_view_module_version": "1.5.0", | |
"layout": "IPY_MODEL_f766ef39967e4b09a20a7914b8102586", | |
"_model_module": "@jupyter-widgets/controls", | |
"icon": "" | |
} | |
}, | |
"44572c445fc541818f129e21e1d6fab7": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "ButtonStyleModel", | |
"state": { | |
"_view_name": "StyleView", | |
"_model_name": "ButtonStyleModel", | |
"_view_module": "@jupyter-widgets/base", | |
"_model_module_version": "1.5.0", | |
"_view_count": null, | |
"button_color": null, | |
"font_weight": "", | |
"_view_module_version": "1.2.0", | |
"_model_module": "@jupyter-widgets/controls" | |
} | |
}, | |
"35040a876526427a9ce40610bd0e21ae": { | |
"model_module": "@jupyter-widgets/base", | |
"model_name": "LayoutModel", | |
"state": { | |
"_view_name": "LayoutView", | |
"grid_template_rows": null, | |
"right": null, | |
"justify_content": null, | |
"_view_module": "@jupyter-widgets/base", | |
"overflow": null, | |
"_model_module_version": "1.2.0", | |
"_view_count": null, | |
"flex_flow": null, | |
"width": "auto", | |
"min_width": null, | |
"border": null, | |
"align_items": null, | |
"bottom": null, | |
"_model_module": "@jupyter-widgets/base", | |
"top": null, | |
"grid_column": null, | |
"overflow_y": null, | |
"overflow_x": null, | |
"grid_auto_flow": null, | |
"grid_area": "btn_up", | |
"grid_template_columns": null, | |
"flex": null, | |
"_model_name": "LayoutModel", | |
"justify_items": null, | |
"grid_row": null, | |
"max_height": null, | |
"align_content": null, | |
"visibility": null, | |
"align_self": null, | |
"height": null, | |
"min_height": null, | |
"padding": null, | |
"grid_auto_rows": null, | |
"grid_gap": null, | |
"max_width": null, | |
"order": null, | |
"_view_module_version": "1.2.0", | |
"grid_template_areas": null, | |
"object_position": null, | |
"object_fit": null, | |
"grid_auto_columns": null, | |
"margin": null, | |
"display": null, | |
"left": null | |
} | |
}, | |
"e56924ff06da46a1b1085832db843f9d": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "ButtonStyleModel", | |
"state": { | |
"_view_name": "StyleView", | |
"_model_name": "ButtonStyleModel", | |
"_view_module": "@jupyter-widgets/base", | |
"_model_module_version": "1.5.0", | |
"_view_count": null, | |
"button_color": null, | |
"font_weight": "", | |
"_view_module_version": "1.2.0", | |
"_model_module": "@jupyter-widgets/controls" | |
} | |
}, | |
"c635c7693e6240c8b206488b1a9024a1": { | |
"model_module": "@jupyter-widgets/base", | |
"model_name": "LayoutModel", | |
"state": { | |
"_view_name": "LayoutView", | |
"grid_template_rows": null, | |
"right": null, | |
"justify_content": null, | |
"_view_module": "@jupyter-widgets/base", | |
"overflow": null, | |
"_model_module_version": "1.2.0", | |
"_view_count": null, | |
"flex_flow": null, | |
"width": "auto", | |
"min_width": null, | |
"border": null, | |
"align_items": null, | |
"bottom": null, | |
"_model_module": "@jupyter-widgets/base", | |
"top": null, | |
"grid_column": null, | |
"overflow_y": null, | |
"overflow_x": null, | |
"grid_auto_flow": null, | |
"grid_area": "btn_left", | |
"grid_template_columns": null, | |
"flex": null, | |
"_model_name": "LayoutModel", | |
"justify_items": null, | |
"grid_row": null, | |
"max_height": null, | |
"align_content": null, | |
"visibility": null, | |
"align_self": null, | |
"height": null, | |
"min_height": null, | |
"padding": null, | |
"grid_auto_rows": null, | |
"grid_gap": null, | |
"max_width": null, | |
"order": null, | |
"_view_module_version": "1.2.0", | |
"grid_template_areas": null, | |
"object_position": null, | |
"object_fit": null, | |
"grid_auto_columns": null, | |
"margin": null, | |
"display": null, | |
"left": null | |
} | |
}, | |
"c57d739c42724941aa8f35e5b92ea51e": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "ButtonStyleModel", | |
"state": { | |
"_view_name": "StyleView", | |
"_model_name": "ButtonStyleModel", | |
"_view_module": "@jupyter-widgets/base", | |
"_model_module_version": "1.5.0", | |
"_view_count": null, | |
"button_color": null, | |
"font_weight": "", | |
"_view_module_version": "1.2.0", | |
"_model_module": "@jupyter-widgets/controls" | |
} | |
}, | |
"f61d8ce574f44114b9f4effd7d3c8084": { | |
"model_module": "@jupyter-widgets/base", | |
"model_name": "LayoutModel", | |
"state": { | |
"_view_name": "LayoutView", | |
"grid_template_rows": null, | |
"right": null, | |
"justify_content": null, | |
"_view_module": "@jupyter-widgets/base", | |
"overflow": null, | |
"_model_module_version": "1.2.0", | |
"_view_count": null, | |
"flex_flow": null, | |
"width": "auto", | |
"min_width": null, | |
"border": null, | |
"align_items": null, | |
"bottom": null, | |
"_model_module": "@jupyter-widgets/base", | |
"top": null, | |
"grid_column": null, | |
"overflow_y": null, | |
"overflow_x": null, | |
"grid_auto_flow": null, | |
"grid_area": "btn_right", | |
"grid_template_columns": null, | |
"flex": null, | |
"_model_name": "LayoutModel", | |
"justify_items": null, | |
"grid_row": null, | |
"max_height": null, | |
"align_content": null, | |
"visibility": null, | |
"align_self": null, | |
"height": null, | |
"min_height": null, | |
"padding": null, | |
"grid_auto_rows": null, | |
"grid_gap": null, | |
"max_width": null, | |
"order": null, | |
"_view_module_version": "1.2.0", | |
"grid_template_areas": null, | |
"object_position": null, | |
"object_fit": null, | |
"grid_auto_columns": null, | |
"margin": null, | |
"display": null, | |
"left": null | |
} | |
}, | |
"667745526f9c4038bbf229074dc714e7": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "ButtonStyleModel", | |
"state": { | |
"_view_name": "StyleView", | |
"_model_name": "ButtonStyleModel", | |
"_view_module": "@jupyter-widgets/base", | |
"_model_module_version": "1.5.0", | |
"_view_count": null, | |
"button_color": null, | |
"font_weight": "", | |
"_view_module_version": "1.2.0", | |
"_model_module": "@jupyter-widgets/controls" | |
} | |
}, | |
"f766ef39967e4b09a20a7914b8102586": { | |
"model_module": "@jupyter-widgets/base", | |
"model_name": "LayoutModel", | |
"state": { | |
"_view_name": "LayoutView", | |
"grid_template_rows": null, | |
"right": null, | |
"justify_content": null, | |
"_view_module": "@jupyter-widgets/base", | |
"overflow": null, | |
"_model_module_version": "1.2.0", | |
"_view_count": null, | |
"flex_flow": null, | |
"width": "auto", | |
"min_width": null, | |
"border": null, | |
"align_items": null, | |
"bottom": null, | |
"_model_module": "@jupyter-widgets/base", | |
"top": null, | |
"grid_column": null, | |
"overflow_y": null, | |
"overflow_x": null, | |
"grid_auto_flow": null, | |
"grid_area": "btn_down", | |
"grid_template_columns": null, | |
"flex": null, | |
"_model_name": "LayoutModel", | |
"justify_items": null, | |
"grid_row": null, | |
"max_height": null, | |
"align_content": null, | |
"visibility": null, | |
"align_self": null, | |
"height": null, | |
"min_height": null, | |
"padding": null, | |
"grid_auto_rows": null, | |
"grid_gap": null, | |
"max_width": null, | |
"order": null, | |
"_view_module_version": "1.2.0", | |
"grid_template_areas": null, | |
"object_position": null, | |
"object_fit": null, | |
"grid_auto_columns": null, | |
"margin": null, | |
"display": null, | |
"left": null | |
} | |
} | |
} | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/faizankshaikh/e23db80bdcdcb14176d492d505ee46b4/play2048.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "lhmFeDH1hCfK", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 54 | |
}, | |
"outputId": "1617ea4f-033b-4fd8-ae64-72339a13426e" | |
}, | |
"source": [ | |
"!git clone https://github.com/zvapa/2048-game-python-jupyter.git" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"fatal: destination path '2048-game-python-jupyter' already exists and is not an empty directory.\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "LDH-wIDmhB2j", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "19cd0980-76fd-49e5-d6e3-14cbe1e35270" | |
}, | |
"source": [ | |
"%cd 2048-game-python-jupyter" | |
], | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"/content/2048-game-python-jupyter\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "NZhjhxUGhByP", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 784 | |
}, | |
"outputId": "9e51f976-1f91-4bd4-da34-82122b2d86dc" | |
}, | |
"source": [ | |
"!pip install -r requirements.txt" | |
], | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from -r requirements.txt (line 1)) (1.18.5)\n", | |
"Requirement already satisfied: bokeh in /usr/local/lib/python3.6/dist-packages (from -r requirements.txt (line 2)) (2.2.0.dev4)\n", | |
"Requirement already satisfied: ipywidgets in /usr/local/lib/python3.6/dist-packages (from -r requirements.txt (line 3)) (7.5.1)\n", | |
"Requirement already satisfied: typing-extensions>=3.7.4 in /usr/local/lib/python3.6/dist-packages (from bokeh->-r requirements.txt (line 2)) (3.7.4.2)\n", | |
"Requirement already satisfied: Jinja2>=2.7 in /usr/local/lib/python3.6/dist-packages (from bokeh->-r requirements.txt (line 2)) (2.11.2)\n", | |
"Requirement already satisfied: tornado>=5.1 in /usr/local/lib/python3.6/dist-packages (from bokeh->-r requirements.txt (line 2)) (5.1.1)\n", | |
"Requirement already satisfied: packaging>=16.8 in /usr/local/lib/python3.6/dist-packages (from bokeh->-r requirements.txt (line 2)) (20.4)\n", | |
"Requirement already satisfied: PyYAML>=3.10 in /usr/local/lib/python3.6/dist-packages (from bokeh->-r requirements.txt (line 2)) (3.13)\n", | |
"Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from bokeh->-r requirements.txt (line 2)) (2.8.1)\n", | |
"Requirement already satisfied: pillow>=4.0 in /usr/local/lib/python3.6/dist-packages (from bokeh->-r requirements.txt (line 2)) (7.0.0)\n", | |
"Requirement already satisfied: ipykernel>=4.5.1 in /usr/local/lib/python3.6/dist-packages (from ipywidgets->-r requirements.txt (line 3)) (4.10.1)\n", | |
"Requirement already satisfied: nbformat>=4.2.0 in /usr/local/lib/python3.6/dist-packages (from ipywidgets->-r requirements.txt (line 3)) (5.0.7)\n", | |
"Requirement already satisfied: traitlets>=4.3.1 in /usr/local/lib/python3.6/dist-packages (from ipywidgets->-r requirements.txt (line 3)) (4.3.3)\n", | |
"Requirement already satisfied: widgetsnbextension~=3.5.0 in /usr/local/lib/python3.6/dist-packages (from ipywidgets->-r requirements.txt (line 3)) (3.5.1)\n", | |
"Requirement already satisfied: ipython>=4.0.0; python_version >= \"3.3\" in /usr/local/lib/python3.6/dist-packages (from ipywidgets->-r requirements.txt (line 3)) (5.5.0)\n", | |
"Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.6/dist-packages (from Jinja2>=2.7->bokeh->-r requirements.txt (line 2)) (1.1.1)\n", | |
"Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from packaging>=16.8->bokeh->-r requirements.txt (line 2)) (1.15.0)\n", | |
"Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.6/dist-packages (from packaging>=16.8->bokeh->-r requirements.txt (line 2)) (2.4.7)\n", | |
"Requirement already satisfied: jupyter-client in /usr/local/lib/python3.6/dist-packages (from ipykernel>=4.5.1->ipywidgets->-r requirements.txt (line 3)) (5.3.5)\n", | |
"Requirement already satisfied: ipython-genutils in /usr/local/lib/python3.6/dist-packages (from nbformat>=4.2.0->ipywidgets->-r requirements.txt (line 3)) (0.2.0)\n", | |
"Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /usr/local/lib/python3.6/dist-packages (from nbformat>=4.2.0->ipywidgets->-r requirements.txt (line 3)) (2.6.0)\n", | |
"Requirement already satisfied: jupyter-core in /usr/local/lib/python3.6/dist-packages (from nbformat>=4.2.0->ipywidgets->-r requirements.txt (line 3)) (4.6.3)\n", | |
"Requirement already satisfied: decorator in /usr/local/lib/python3.6/dist-packages (from traitlets>=4.3.1->ipywidgets->-r requirements.txt (line 3)) (4.4.2)\n", | |
"Requirement already satisfied: notebook>=4.4.1 in /usr/local/lib/python3.6/dist-packages (from widgetsnbextension~=3.5.0->ipywidgets->-r requirements.txt (line 3)) (5.3.1)\n", | |
"Requirement already satisfied: pickleshare in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets->-r requirements.txt (line 3)) (0.7.5)\n", | |
"Requirement already satisfied: simplegeneric>0.8 in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets->-r requirements.txt (line 3)) (0.8.1)\n", | |
"Requirement already satisfied: pygments in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets->-r requirements.txt (line 3)) (2.1.3)\n", | |
"Requirement already satisfied: prompt-toolkit<2.0.0,>=1.0.4 in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets->-r requirements.txt (line 3)) (1.0.18)\n", | |
"Requirement already satisfied: pexpect; sys_platform != \"win32\" in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets->-r requirements.txt (line 3)) (4.8.0)\n", | |
"Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets->-r requirements.txt (line 3)) (49.1.0)\n", | |
"Requirement already satisfied: pyzmq>=13 in /usr/local/lib/python3.6/dist-packages (from jupyter-client->ipykernel>=4.5.1->ipywidgets->-r requirements.txt (line 3)) (19.0.1)\n", | |
"Requirement already satisfied: Send2Trash in /usr/local/lib/python3.6/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->-r requirements.txt (line 3)) (1.5.0)\n", | |
"Requirement already satisfied: nbconvert in /usr/local/lib/python3.6/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->-r requirements.txt (line 3)) (5.6.1)\n", | |
"Requirement already satisfied: terminado>=0.8.1 in /usr/local/lib/python3.6/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->-r requirements.txt (line 3)) (0.8.3)\n", | |
"Requirement already satisfied: wcwidth in /usr/local/lib/python3.6/dist-packages (from prompt-toolkit<2.0.0,>=1.0.4->ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets->-r requirements.txt (line 3)) (0.2.5)\n", | |
"Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.6/dist-packages (from pexpect; sys_platform != \"win32\"->ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets->-r requirements.txt (line 3)) (0.6.0)\n", | |
"Requirement already satisfied: mistune<2,>=0.8.1 in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->-r requirements.txt (line 3)) (0.8.4)\n", | |
"Requirement already satisfied: pandocfilters>=1.4.1 in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->-r requirements.txt (line 3)) (1.4.2)\n", | |
"Requirement already satisfied: defusedxml in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->-r requirements.txt (line 3)) (0.6.0)\n", | |
"Requirement already satisfied: entrypoints>=0.2.2 in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->-r requirements.txt (line 3)) (0.3)\n", | |
"Requirement already satisfied: bleach in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->-r requirements.txt (line 3)) (3.1.5)\n", | |
"Requirement already satisfied: testpath in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->-r requirements.txt (line 3)) (0.4.4)\n", | |
"Requirement already satisfied: webencodings in /usr/local/lib/python3.6/dist-packages (from bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->-r requirements.txt (line 3)) (0.5.1)\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "isOCjlDtfm9M", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"import itertools\n", | |
"from ipywidgets import interact, Button, IntText, GridBox, Layout, VBox, HBox, HTML, Output, Label\n", | |
"from IPython.display import display\n", | |
"from bokeh.io import push_notebook, show, output_notebook\n", | |
"from bokeh.layouts import row, column, layout\n", | |
"from bokeh.models import CategoricalColorMapper, ColumnDataSource, Text\n", | |
"from bokeh.plotting import figure, output_file\n", | |
"from grid import Grid" | |
], | |
"execution_count": 4, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"scrolled": false, | |
"id": "PPYdnWjDfm9Y", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 513, | |
"referenced_widgets": [ | |
"aec7052b113045bb9d5a4653da539160", | |
"80215633877d4f61bb7a6cbd486b86a8", | |
"ff452046f6c047c1bef8eac1a680260f", | |
"2fea5b881dc94046a2212eb98b79db76", | |
"7252e2bace0c4523a8cfab97d5ab7e59", | |
"ca36d56a41ea4e5aa6294aa100d07f9b", | |
"44572c445fc541818f129e21e1d6fab7", | |
"35040a876526427a9ce40610bd0e21ae", | |
"e56924ff06da46a1b1085832db843f9d", | |
"c635c7693e6240c8b206488b1a9024a1", | |
"c57d739c42724941aa8f35e5b92ea51e", | |
"f61d8ce574f44114b9f4effd7d3c8084", | |
"667745526f9c4038bbf229074dc714e7", | |
"f766ef39967e4b09a20a7914b8102586" | |
] | |
}, | |
"outputId": "d50146f4-e6b0-4afd-9fe7-cf5a37097d46" | |
}, | |
"source": [ | |
"output_notebook()\n", | |
"\n", | |
"g = Grid(4, 4)\n", | |
"\n", | |
"line_width = 10\n", | |
"line_color = '#B8AD9A' # the same for plot outline and rectangles border\n", | |
"\n", | |
"p = figure(tools='', title=f\"Score: {g.score}\", plot_width=400, plot_height=400, \n", | |
" x_range=(-0.5, 3.5), y_range=(3.5, -0.5))\n", | |
"\n", | |
"# make the graph look more like a game board\n", | |
"line_width = 10\n", | |
"line_color = '#B8AD9A'\n", | |
"p.outline_line_width = line_width\n", | |
"p.outline_line_color = line_color\n", | |
"p.xgrid.grid_line_color = p.ygrid.grid_line_color = None\n", | |
"p.title.align = 'right'\n", | |
"p.title.text_font_size = '1.5em'\n", | |
"p.axis.visible = False\n", | |
"\n", | |
"\n", | |
"color_dict = {0: '#D7D7D7', 2: '#ECE3AF', 4: '#E0D1A1', 8: '#D3B486', 16: '#F0AB79', 32: '#F18231',\n", | |
" 64: '#F73B0C', 128: '#DAD083', 256: '#D6C01E', 512: '#D4E80F', 1024: '#A3D829',\n", | |
" 2048: '#30D55A', 4096: '#B356E5', 8192: '#37E5E7', 16384: '#5117EA', 32768: '#C13695',\n", | |
" 65536: '#468A9C', 131072: '#9C4657'}\n", | |
"coord_pairs = [i for i in itertools.product(range(4), range(4))]\n", | |
"x, y = zip(*coord_pairs)\n", | |
"\n", | |
"def update_source():\n", | |
" g.spawn()\n", | |
" vals = [g.to_numpy()[c] for c in coord_pairs]\n", | |
" tile_colors = [color_dict[v] for v in vals]\n", | |
" text_colors = ['black' if v != 0 else '#D7D7D7' for v in vals] # make zero values invisible\n", | |
" return dict(x=y, y=x, vals=vals, tile_colors=tile_colors, text_colors=text_colors)\n", | |
"\n", | |
"# initial state of the data source\n", | |
"source = ColumnDataSource(update_source())\n", | |
"\n", | |
"# draw tiles\n", | |
"p.rect(x='x', y='y', source=source, width=1, height=1, line_width=line_width,\n", | |
" line_color=line_color, fill_color='tile_colors')\n", | |
"\n", | |
"# add text\n", | |
"p.text(x='x', y='y', source=source, text='vals', text_align='center', \n", | |
" text_color='text_colors')\n", | |
"\n", | |
"# this updates the grid object based on the direction of the calling button, then recreates the datasource\n", | |
"def on_button_clicked(b):\n", | |
" direction = b.description.lower()\n", | |
" if g.slide(direction): # if the move generated any change on the grid -> update source\n", | |
" source.data = update_source()\n", | |
" p.title.text = f\"Score: {g.score}\"\n", | |
" push_notebook()\n", | |
" if g.game_over():\n", | |
" print(\"Game Over\")\n", | |
" print(\"Re-run this cell to start again.\")\n", | |
" \n", | |
"show(p, notebook_handle=True)\n", | |
"\n", | |
"# create action buttons\n", | |
"btn_up = Button(description='Up', layout=Layout(width='auto', grid_area='btn_up'))\n", | |
"btn_left = Button(description='Left', layout=Layout(width='auto', grid_area='btn_left'))\n", | |
"btn_right = Button(description='Right', layout=Layout(width='auto', grid_area='btn_right'))\n", | |
"btn_down = Button(description='Down', layout=Layout(width='auto', grid_area='btn_down'))\n", | |
"\n", | |
"# link buttons to function\n", | |
"for button in [btn_up, btn_right, btn_down, btn_left]:\n", | |
" button.on_click(on_button_clicked)\n", | |
"\n", | |
"# arrange controls in a grid box\n", | |
"gbox = GridBox(children=[btn_up, btn_left, btn_right, btn_down], layout=Layout(\n", | |
" width='25%',\n", | |
" grid_template_rows='auto',\n", | |
" grid_template_columns='auto',\n", | |
" grid_template_areas='''\n", | |
" \". btn_up btn_up .\"\n", | |
" \"btn_left btn_left btn_right btn_right\"\n", | |
" \". btn_down btn_down .\"\n", | |
" '''\n", | |
" ))\n", | |
"display(gbox)" | |
], | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/javascript": [ | |
"\n", | |
"(function(root) {\n", | |
" function now() {\n", | |
" return new Date();\n", | |
" }\n", | |
"\n", | |
" var force = true;\n", | |
"\n", | |
" if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n", | |
" root._bokeh_onload_callbacks = [];\n", | |
" root._bokeh_is_loading = undefined;\n", | |
" }\n", | |
"\n", | |
" var JS_MIME_TYPE = 'application/javascript';\n", | |
" var HTML_MIME_TYPE = 'text/html';\n", | |
" var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n", | |
" var CLASS_NAME = 'output_bokeh rendered_html';\n", | |
"\n", | |
" /**\n", | |
" * Render data to the DOM node\n", | |
" */\n", | |
" function render(props, node) {\n", | |
" var script = document.createElement(\"script\");\n", | |
" node.appendChild(script);\n", | |
" }\n", | |
"\n", | |
" /**\n", | |
" * Handle when an output is cleared or removed\n", | |
" */\n", | |
" function handleClearOutput(event, handle) {\n", | |
" var cell = handle.cell;\n", | |
"\n", | |
" var id = cell.output_area._bokeh_element_id;\n", | |
" var server_id = cell.output_area._bokeh_server_id;\n", | |
" // Clean up Bokeh references\n", | |
" if (id != null && id in Bokeh.index) {\n", | |
" Bokeh.index[id].model.document.clear();\n", | |
" delete Bokeh.index[id];\n", | |
" }\n", | |
"\n", | |
" if (server_id !== undefined) {\n", | |
" // Clean up Bokeh references\n", | |
" var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n", | |
" cell.notebook.kernel.execute(cmd, {\n", | |
" iopub: {\n", | |
" output: function(msg) {\n", | |
" var id = msg.content.text.trim();\n", | |
" if (id in Bokeh.index) {\n", | |
" Bokeh.index[id].model.document.clear();\n", | |
" delete Bokeh.index[id];\n", | |
" }\n", | |
" }\n", | |
" }\n", | |
" });\n", | |
" // Destroy server and session\n", | |
" var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n", | |
" cell.notebook.kernel.execute(cmd);\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" /**\n", | |
" * Handle when a new output is added\n", | |
" */\n", | |
" function handleAddOutput(event, handle) {\n", | |
" var output_area = handle.output_area;\n", | |
" var output = handle.output;\n", | |
"\n", | |
" // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n", | |
" if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n", | |
" return\n", | |
" }\n", | |
"\n", | |
" var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n", | |
"\n", | |
" if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n", | |
" toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n", | |
" // store reference to embed id on output_area\n", | |
" output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n", | |
" }\n", | |
" if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n", | |
" var bk_div = document.createElement(\"div\");\n", | |
" bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n", | |
" var script_attrs = bk_div.children[0].attributes;\n", | |
" for (var i = 0; i < script_attrs.length; i++) {\n", | |
" toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n", | |
" toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n", | |
" }\n", | |
" // store reference to server id on output_area\n", | |
" output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" function register_renderer(events, OutputArea) {\n", | |
"\n", | |
" function append_mime(data, metadata, element) {\n", | |
" // create a DOM node to render to\n", | |
" var toinsert = this.create_output_subarea(\n", | |
" metadata,\n", | |
" CLASS_NAME,\n", | |
" EXEC_MIME_TYPE\n", | |
" );\n", | |
" this.keyboard_manager.register_events(toinsert);\n", | |
" // Render to node\n", | |
" var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n", | |
" render(props, toinsert[toinsert.length - 1]);\n", | |
" element.append(toinsert);\n", | |
" return toinsert\n", | |
" }\n", | |
"\n", | |
" /* Handle when an output is cleared or removed */\n", | |
" events.on('clear_output.CodeCell', handleClearOutput);\n", | |
" events.on('delete.Cell', handleClearOutput);\n", | |
"\n", | |
" /* Handle when a new output is added */\n", | |
" events.on('output_added.OutputArea', handleAddOutput);\n", | |
"\n", | |
" /**\n", | |
" * Register the mime type and append_mime function with output_area\n", | |
" */\n", | |
" OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n", | |
" /* Is output safe? */\n", | |
" safe: true,\n", | |
" /* Index of renderer in `output_area.display_order` */\n", | |
" index: 0\n", | |
" });\n", | |
" }\n", | |
"\n", | |
" // register the mime type if in Jupyter Notebook environment and previously unregistered\n", | |
" if (root.Jupyter !== undefined) {\n", | |
" var events = require('base/js/events');\n", | |
" var OutputArea = require('notebook/js/outputarea').OutputArea;\n", | |
"\n", | |
" if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n", | |
" register_renderer(events, OutputArea);\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" \n", | |
" if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n", | |
" root._bokeh_timeout = Date.now() + 5000;\n", | |
" root._bokeh_failed_load = false;\n", | |
" }\n", | |
"\n", | |
" var NB_LOAD_WARNING = {'data': {'text/html':\n", | |
" \"<div style='background-color: #fdd'>\\n\"+\n", | |
" \"<p>\\n\"+\n", | |
" \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", | |
" \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", | |
" \"</p>\\n\"+\n", | |
" \"<ul>\\n\"+\n", | |
" \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n", | |
" \"<li>use INLINE resources instead, as so:</li>\\n\"+\n", | |
" \"</ul>\\n\"+\n", | |
" \"<code>\\n\"+\n", | |
" \"from bokeh.resources import INLINE\\n\"+\n", | |
" \"output_notebook(resources=INLINE)\\n\"+\n", | |
" \"</code>\\n\"+\n", | |
" \"</div>\"}};\n", | |
"\n", | |
" function display_loaded() {\n", | |
" var el = document.getElementById(null);\n", | |
" if (el != null) {\n", | |
" el.textContent = \"BokehJS is loading...\";\n", | |
" }\n", | |
" if (root.Bokeh !== undefined) {\n", | |
" if (el != null) {\n", | |
" el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n", | |
" }\n", | |
" } else if (Date.now() < root._bokeh_timeout) {\n", | |
" setTimeout(display_loaded, 100)\n", | |
" }\n", | |
" }\n", | |
"\n", | |
"\n", | |
" function run_callbacks() {\n", | |
" try {\n", | |
" root._bokeh_onload_callbacks.forEach(function(callback) {\n", | |
" if (callback != null)\n", | |
" callback();\n", | |
" });\n", | |
" } finally {\n", | |
" delete root._bokeh_onload_callbacks\n", | |
" }\n", | |
" console.debug(\"Bokeh: all callbacks have finished\");\n", | |
" }\n", | |
"\n", | |
" function load_libs(css_urls, js_urls, callback) {\n", | |
" if (css_urls == null) css_urls = [];\n", | |
" if (js_urls == null) js_urls = [];\n", | |
"\n", | |
" root._bokeh_onload_callbacks.push(callback);\n", | |
" if (root._bokeh_is_loading > 0) {\n", | |
" console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", | |
" return null;\n", | |
" }\n", | |
" if (js_urls == null || js_urls.length === 0) {\n", | |
" run_callbacks();\n", | |
" return null;\n", | |
" }\n", | |
" console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", | |
" root._bokeh_is_loading = css_urls.length + js_urls.length;\n", | |
"\n", | |
" function on_load() {\n", | |
" root._bokeh_is_loading--;\n", | |
" if (root._bokeh_is_loading === 0) {\n", | |
" console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n", | |
" run_callbacks()\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" function on_error() {\n", | |
" console.error(\"failed to load \" + url);\n", | |
" }\n", | |
"\n", | |
" for (var i = 0; i < css_urls.length; i++) {\n", | |
" var url = css_urls[i];\n", | |
" const element = document.createElement(\"link\");\n", | |
" element.onload = on_load;\n", | |
" element.onerror = on_error;\n", | |
" element.rel = \"stylesheet\";\n", | |
" element.type = \"text/css\";\n", | |
" element.href = url;\n", | |
" console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n", | |
" document.body.appendChild(element);\n", | |
" }\n", | |
"\n", | |
" const hashes = {};\n", | |
"\n", | |
" for (var i = 0; i < js_urls.length; i++) {\n", | |
" var url = js_urls[i];\n", | |
" var element = document.createElement('script');\n", | |
" element.onload = on_load;\n", | |
" element.onerror = on_error;\n", | |
" element.async = false;\n", | |
" element.src = url;\n", | |
" if (url in hashes) {\n", | |
" element.crossOrigin = \"anonymous\";\n", | |
" element.integrity = \"sha384-\" + hashes[url];\n", | |
" }\n", | |
" console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", | |
" document.head.appendChild(element);\n", | |
" }\n", | |
" };\n", | |
"\n", | |
" function inject_raw_css(css) {\n", | |
" const element = document.createElement(\"style\");\n", | |
" element.appendChild(document.createTextNode(css));\n", | |
" document.body.appendChild(element);\n", | |
" }\n", | |
"\n", | |
" \n", | |
" var js_urls = [\"https://cdn.bokeh.org/bokeh/dev/bokeh-2.2.0dev4.min.js\", \"https://cdn.bokeh.org/bokeh/dev/bokeh-widgets-2.2.0dev4.min.js\", \"https://cdn.bokeh.org/bokeh/dev/bokeh-tables-2.2.0dev4.min.js\", \"https://cdn.bokeh.org/bokeh/dev/bokeh-gl-2.2.0dev4.min.js\"];\n", | |
" var css_urls = [];\n", | |
" \n", | |
"\n", | |
" var inline_js = [\n", | |
" function(Bokeh) {\n", | |
" Bokeh.set_log_level(\"info\");\n", | |
" },\n", | |
" function(Bokeh) {\n", | |
" \n", | |
" \n", | |
" }\n", | |
" ];\n", | |
"\n", | |
" function run_inline_js() {\n", | |
" \n", | |
" if (root.Bokeh !== undefined || force === true) {\n", | |
" \n", | |
" for (var i = 0; i < inline_js.length; i++) {\n", | |
" inline_js[i].call(root, root.Bokeh);\n", | |
" }\n", | |
" } else if (Date.now() < root._bokeh_timeout) {\n", | |
" setTimeout(run_inline_js, 100);\n", | |
" } else if (!root._bokeh_failed_load) {\n", | |
" console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n", | |
" root._bokeh_failed_load = true;\n", | |
" } else if (force !== true) {\n", | |
" var cell = $(document.getElementById(null)).parents('.cell').data().cell;\n", | |
" cell.output_area.append_execute_result(NB_LOAD_WARNING)\n", | |
" }\n", | |
"\n", | |
" }\n", | |
"\n", | |
" if (root._bokeh_is_loading === 0) {\n", | |
" console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", | |
" run_inline_js();\n", | |
" } else {\n", | |
" load_libs(css_urls, js_urls, function() {\n", | |
" console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n", | |
" run_inline_js();\n", | |
" });\n", | |
" }\n", | |
"}(window));" | |
], | |
"application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n function now() {\n return new Date();\n }\n\n var force = true;\n\n if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n \n\n \n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n var NB_LOAD_WARNING = {'data': {'text/html':\n \"<div style='background-color: #fdd'>\\n\"+\n \"<p>\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"</p>\\n\"+\n \"<ul>\\n\"+\n \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n \"<li>use INLINE resources instead, as so:</li>\\n\"+\n \"</ul>\\n\"+\n \"<code>\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"</code>\\n\"+\n \"</div>\"}};\n\n function display_loaded() {\n var el = document.getElementById(null);\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n\n function on_error() {\n console.error(\"failed to load \" + url);\n }\n\n for (var i = 0; i < css_urls.length; i++) {\n var url = css_urls[i];\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n }\n\n const hashes = {};\n\n for (var i = 0; i < js_urls.length; i++) {\n var url = js_urls[i];\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n if (url in hashes) {\n element.crossOrigin = \"anonymous\";\n element.integrity = \"sha384-\" + hashes[url];\n }\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n \n var js_urls = [\"https://cdn.bokeh.org/bokeh/dev/bokeh-2.2.0dev4.min.js\", \"https://cdn.bokeh.org/bokeh/dev/bokeh-widgets-2.2.0dev4.min.js\", \"https://cdn.bokeh.org/bokeh/dev/bokeh-tables-2.2.0dev4.min.js\", \"https://cdn.bokeh.org/bokeh/dev/bokeh-gl-2.2.0dev4.min.js\"];\n var css_urls = [];\n \n\n var inline_js = [\n function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\n function(Bokeh) {\n \n \n }\n ];\n\n function run_inline_js() {\n \n if (root.Bokeh !== undefined || force === true) {\n \n for (var i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n var cell = $(document.getElementById(null)).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n\n }\n\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(css_urls, js_urls, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));" | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"text/html": [ | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
" <div class=\"bk-root\" id=\"7886ef60-7c77-4ccb-886d-a8cfa899a321\" data-root-id=\"1084\"></div>\n" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/javascript": [ | |
"(function(root) {\n", | |
" function embed_document(root) {\n", | |
" \n", | |
" var docs_json = {\"ba0d2f0a-f4bb-4fb8-9330-b12f40c1c2f6\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1095\"}],\"center\":[{\"id\":\"1098\"},{\"id\":\"1102\"}],\"left\":[{\"id\":\"1099\"}],\"outline_line_color\":\"#B8AD9A\",\"outline_line_width\":10,\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"1108\"},{\"id\":\"1113\"}],\"title\":{\"id\":\"1085\"},\"toolbar\":{\"id\":\"1103\"},\"x_range\":{\"id\":\"1087\"},\"x_scale\":{\"id\":\"1091\"},\"y_range\":{\"id\":\"1089\"},\"y_scale\":{\"id\":\"1093\"}},\"id\":\"1084\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"data\":{\"text_colors\":[\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"black\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\"],\"tile_colors\":[\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#ECE3AF\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\",\"#D7D7D7\"],\"vals\":[0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0],\"x\":[0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3],\"y\":[0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3]},\"selected\":{\"id\":\"1127\"},\"selection_policy\":{\"id\":\"1128\"}},\"id\":\"1104\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"data_source\":{\"id\":\"1104\"},\"glyph\":{\"id\":\"1111\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1112\"},\"selection_glyph\":null,\"view\":{\"id\":\"1114\"}},\"id\":\"1113\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"1104\"}},\"id\":\"1114\",\"type\":\"CDSView\"},{\"attributes\":{\"text\":{\"field\":\"vals\"},\"text_align\":\"center\",\"text_color\":{\"field\":\"text_colors\"},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1111\",\"type\":\"Text\"},{\"attributes\":{\"text\":{\"field\":\"vals\"},\"text_align\":\"center\",\"text_alpha\":{\"value\":0.1},\"text_color\":{\"field\":\"text_colors\"},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1112\",\"type\":\"Text\"},{\"attributes\":{\"align\":\"right\",\"text\":\"Score: 0\",\"text_font_size\":{\"value\":\"1.5em\"}},\"id\":\"1085\",\"type\":\"Title\"},{\"attributes\":{\"end\":3.5,\"start\":-0.5},\"id\":\"1087\",\"type\":\"Range1d\"},{\"attributes\":{\"source\":{\"id\":\"1104\"}},\"id\":\"1109\",\"type\":\"CDSView\"},{\"attributes\":{\"end\":-0.5,\"start\":3.5},\"id\":\"1089\",\"type\":\"Range1d\"},{\"attributes\":{},\"id\":\"1091\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1123\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1093\",\"type\":\"LinearScale\"},{\"attributes\":{\"formatter\":{\"id\":\"1125\"},\"ticker\":{\"id\":\"1096\"},\"visible\":false},\"id\":\"1095\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"tile_colors\"},\"height\":{\"units\":\"data\",\"value\":1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#B8AD9A\"},\"line_width\":{\"value\":10},\"width\":{\"units\":\"data\",\"value\":1},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1107\",\"type\":\"Rect\"},{\"attributes\":{},\"id\":\"1127\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1096\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1128\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"axis\":{\"id\":\"1095\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1098\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1125\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"1123\"},\"ticker\":{\"id\":\"1100\"},\"visible\":false},\"id\":\"1099\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1100\",\"type\":\"BasicTicker\"},{\"attributes\":{\"data_source\":{\"id\":\"1104\"},\"glyph\":{\"id\":\"1106\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1107\"},\"selection_glyph\":null,\"view\":{\"id\":\"1109\"}},\"id\":\"1108\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"1099\"},\"dimension\":1,\"grid_line_color\":null,\"ticker\":null},\"id\":\"1102\",\"type\":\"Grid\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\"},\"id\":\"1103\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_color\":{\"field\":\"tile_colors\"},\"height\":{\"units\":\"data\",\"value\":1},\"line_color\":{\"value\":\"#B8AD9A\"},\"line_width\":{\"value\":10},\"width\":{\"units\":\"data\",\"value\":1},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1106\",\"type\":\"Rect\"}],\"root_ids\":[\"1084\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.0dev4\"}};\n", | |
" var render_items = [{\"docid\":\"ba0d2f0a-f4bb-4fb8-9330-b12f40c1c2f6\",\"notebook_comms_target\":\"1129\",\"root_ids\":[\"1084\"],\"roots\":{\"1084\":\"7886ef60-7c77-4ccb-886d-a8cfa899a321\"}}];\n", | |
" root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n", | |
"\n", | |
" }\n", | |
" if (root.Bokeh !== undefined) {\n", | |
" embed_document(root);\n", | |
" } else {\n", | |
" var attempts = 0;\n", | |
" var timer = setInterval(function(root) {\n", | |
" if (root.Bokeh !== undefined) {\n", | |
" clearInterval(timer);\n", | |
" embed_document(root);\n", | |
" } else {\n", | |
" attempts++;\n", | |
" if (attempts > 100) {\n", | |
" clearInterval(timer);\n", | |
" console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n", | |
" }\n", | |
" }\n", | |
" }, 10, root)\n", | |
" }\n", | |
"})(window);" | |
], | |
"application/vnd.bokehjs_exec.v0+json": "" | |
}, | |
"metadata": { | |
"tags": [], | |
"application/vnd.bokehjs_exec.v0+json": { | |
"id": "1084" | |
} | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "aec7052b113045bb9d5a4653da539160", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"GridBox(children=(Button(description='Up', layout=Layout(grid_area='btn_up', width='auto'), style=ButtonStyle(…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "vJfPjNYZg8Z0", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": 5, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment