From 5472d52466dfebfb9414dae5fbd78459a17008e2 Mon Sep 17 00:00:00 2001 From: Theo Alves Da Costa Date: Sun, 7 Jun 2020 19:39:25 +0200 Subject: [PATCH] Made library work with non-grid envs --- ...0200607 - Dev spatial env (not grid).ipynb | 269 ++ dev/Untitled.ipynb | 465 --- dev/dev_js/test_threejs.html | 9 +- dev/sprites/sprite_arrow.png | Bin 0 -> 394 bytes westworld/agents/grid_agent.py | 47 +- westworld/assets/__init__.py | 3 +- westworld/assets/sprites/arrow.py | 2508 +++++++++++++++++ westworld/assets/sprites/utils.py | 40 + westworld/environment/grid.py | 56 +- westworld/environment/spatial.py | 17 +- westworld/objects/base_object.py | 3 + 11 files changed, 2902 insertions(+), 515 deletions(-) create mode 100644 dev/20200607 - Dev spatial env (not grid).ipynb delete mode 100644 dev/Untitled.ipynb create mode 100644 dev/sprites/sprite_arrow.png create mode 100644 westworld/assets/sprites/arrow.py create mode 100644 westworld/assets/sprites/utils.py diff --git a/dev/20200607 - Dev spatial env (not grid).ipynb b/dev/20200607 - Dev spatial env (not grid).ipynb new file mode 100644 index 0000000..b76b834 --- /dev/null +++ b/dev/20200607 - Dev spatial env (not grid).ipynb @@ -0,0 +1,269 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "ExecuteTime": { + "end_time": "2020-06-07T17:33:03.007288Z", + "start_time": "2020-06-07T17:33:02.281226Z" + } + }, + "outputs": [], + "source": [ + "# Base Data Science snippet\n", + "import pandas as pd\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import os\n", + "import time\n", + "from tqdm import tqdm_notebook\n", + "\n", + "%matplotlib inline\n", + "%load_ext autoreload\n", + "%autoreload 2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Sprite utils" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "ExecuteTime": { + "end_time": "2020-06-07T17:33:04.781302Z", + "start_time": "2020-06-07T17:33:03.010276Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "pygame 1.9.6\n", + "Hello from the pygame community. https://www.pygame.org/contribute.html\n" + ] + } + ], + "source": [ + "import sys\n", + "sys.path.append(\"../\")\n", + "\n", + "import westworld\n", + "from westworld.assets.sprites.utils import *\n", + "from westworld.assets import make_arrow\n", + "from westworld.colors import *\n", + "from westworld.environment import GridEnvironment\n", + "from westworld.agents.sir_agent import SIRAgent\n", + "from westworld.environment.spatial import SpatialEnvironment\n", + "from westworld.agents import BaseGridAgent\n", + "from westworld.agents.collectible_finder import CollectibleFinderAgent\n", + "from westworld.objects import BaseObstacle,BaseTrigger,BaseCollectible,BaseRectangle\n", + "from westworld.simulation import Simulation\n", + "from westworld.colors import *\n", + "from westworld.logger import Logger" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "ExecuteTime": { + "end_time": "2020-06-07T17:36:32.156307Z", + "start_time": "2020-06-07T17:36:31.196357Z" + } + }, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAA+gAAAJYCAIAAAB+fFtyAAAsbUlEQVR4nO3dUbKjuJYFUOioGXkALz8rR3x/7wRyTPSH09Q1YIxtBOdIa0VGdOGuV4kNiI04kroOAAAAAAAAAACa0J+9A3kNt3/wGwIAUJzQ+arhwed+SQAACvq/s3egGo8CPQAA7EA/8XZbornfEwCAIvS4v2wYumF4uAkAACUI7q8ZM/okrN82RXgAAIoQ3DdaTuT62gEAOMY/Z+9ASr9+/+m6rusuS5uDSncAAHanx/1Tt9QOAAAFCe4f6fWtAwBwCMH9NfOk/v11OWNHAABoix7jjbaPQvWTAgCwP4NTAQDgSGOP8GsdvrqHt9vY6e4nBQBg7lGY3Joe1bjvS2oHAOAlW0uyBffthHIAAN4wPEvnm7K74P6S9ewu2QMA8NAwdMPwcPMpwf1V/VJAX/wQAHYxbOiuA6IbM/okrN82n1/jZpV5j5gOQGnzu/j1E/cgQnlzgpSWLCfyl/rarwR3AMhlkJAIwIPlm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EFeW5ngXvI+qUDuvghVUq54EDtKqu4I6mhMx0k5HHNbcPShzyXbT5NR5aJ00u5+Ct2xR2VE9whF7eE95kfndiSLTiwn8Rzogd++KdOSmUAIJBhuHs7NNmsSPqioMAVd1RLcAfq5tZKJoY/Rv6O86T+/XVZ+hehFLc0oHpbcoDGkHPdre97NRmYEWaV38+luyQtbEwEBqcCTTA/Osk0MvzRnOjwKqUyQAvMp0lWtQ5/TFUUlL2JsCZAHfpOcAeaYX508qmx+7niOdGjHa30w3+ZUyoDNCXanRXuZFtw4FN5ioJqqrgL9cPykl5wB4BAml1wIPzzyXp2D3Vcml0ToH5KZQCAkyUpCkpWcdfMmgANEdwB4HRBk185medE7+//BJVq+C9bxT3hAKAl6WY3f4850Utrak2A5qhx56nxWneFA5RT0/BHosgz/JdNBHcemd8/rp9UeZF7OAEiSDT88W2eT04Tfvgvz6lx51U1NbjmuAWiSTb8sZjWvm9xSYb/8oTgztzT8Fp9tK3+CwLB5Rj++K76vlFEmYf/8tD/AzR4z1fNJOPDAAAAAElFTkSuQmCC\n", + "text/plain": [ + "" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "class Agent(SIRAgent):\n", + " \n", + " @property\n", + " def blocking(self):\n", + " return True\n", + " \n", + "# def step(self):\n", + " \n", + " \n", + " \n", + "# def step(self):\n", + " \n", + "# if self.state == \"S\":\n", + " \n", + "# n_infected = len(self.find_in_range({\"state\":\"I\"}))\n", + " \n", + "# if n_infected > 0:\n", + "# proba_infection = norm.cdf(n_infected,loc = self.contact_risk,scale = 3)\n", + "\n", + "# if random.random() < proba_infection:\n", + "\n", + "# self.set_state(\"I\")\n", + "# self.infected_date = self.clock\n", + " \n", + " \n", + "# elif self.state == \"I\":\n", + " \n", + "# if self.clock - self.infected_date >= self.recovery_duration:\n", + "# self.set_state(\"R\")\n", + " \n", + "# # self.wander()\n", + " \n", + " \n", + " \n", + "# # self.wander()\n", + "# self.move(speed = self.speed)\n", + "# self.turn(5)\n", + " \n", + "# self.wander()\n", + " \n", + "# self.move(speed = 10,angle = 45)\n", + "\n", + "CONTACT_RISK = 6\n", + "RECOVERY_DURATION_RANGE = [50,150]\n", + "\n", + "obstacle = BaseObstacle(300,300,200,200,color = RED)\n", + "\n", + "# agent = lambda x,y : Agent(x,y,width = 5,height = 5,circle = True,speed = 5)\n", + "spawner = lambda state : lambda x,y : Agent(x,y,\n", + " width = 20,\n", + " height = 20,\n", + " state = state,\n", + " contact_risk = CONTACT_RISK,\n", + " recovery_duration_range = RECOVERY_DURATION_RANGE)\n", + "\n", + "\n", + "WIDTH = 1000\n", + "HEIGHT = 600\n", + "env = SpatialEnvironment(width = WIDTH,height = HEIGHT)#,objects = [obstacle])\n", + "env.spawn(spawner(\"I\"),1,allow_overlap = True)\n", + "env.spawn(spawner(\"S\"),100,allow_overlap = False)\n", + "\n", + "env.render()\n", + "env.get_img()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "ExecuteTime": { + "end_time": "2020-06-07T17:36:49.225550Z", + "start_time": "2020-06-07T17:36:36.156976Z" + } + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "e3630869ddbb4a52b730c39ea4393fa8", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=300.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "c299b667741a4500a31ff11f9f490f40", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(Play(value=0, description='Press play', interval=40, max=300), Output()), _dom_classes=(…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "a6baa4dcd3284cf4ae32988ca5c6f2d2", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "IntSlider(value=0, max=300)" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "sim = Simulation(env,fps = 25)\n", + "sim.run_episode(n_steps = 300,save = False,replay=True,fps_replay = 25)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.4" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/dev/Untitled.ipynb b/dev/Untitled.ipynb deleted file mode 100644 index 6728884..0000000 --- a/dev/Untitled.ipynb +++ /dev/null @@ -1,465 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T14:53:05.155491Z", - "start_time": "2020-05-25T14:53:04.393980Z" - } - }, - "outputs": [], - "source": [ - "# Base Data Science snippet\n", - "import pandas as pd\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "import os\n", - "import time\n", - "from tqdm import tqdm_notebook\n", - "\n", - "%matplotlib inline\n", - "%load_ext autoreload\n", - "%autoreload 2" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T14:53:05.930143Z", - "start_time": "2020-05-25T14:53:05.639884Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "pygame 1.9.6\n", - "Hello from the pygame community. https://www.pygame.org/contribute.html\n" - ] - } - ], - "source": [ - "import sys\n", - "sys.path.append(\"../../\")\n", - "\n", - "from westworld.environment.grid import GridEnvironment\n", - "from westworld.agents.grid import BaseAgent,BaseObstacle,BaseTrigger,BaseCollectible\n", - "from westworld.simulation.simulation import Simulation\n", - "from westworld.colors import *" - ] - }, - { - "cell_type": "code", - "execution_count": 168, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T20:34:52.259439Z", - "start_time": "2020-05-25T20:34:50.546273Z" - } - }, - "outputs": [], - "source": [ - "from westworld.utils.maze import MazeGenerator" - ] - }, - { - "cell_type": "code", - "execution_count": 179, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T20:41:50.725149Z", - "start_time": "2020-05-25T20:41:50.336813Z" - } - }, - "outputs": [], - "source": [ - "mazegen = MazeGenerator(cell_size = 20)" - ] - }, - { - "cell_type": "code", - "execution_count": 180, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T20:41:51.856919Z", - "start_time": "2020-05-25T20:41:51.258895Z" - } - }, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "5a28cb593b6c4fc4b381a7c54997a580", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(Dropdown(description='method', options=('dungeon', 'prims'), value='dungeon'), IntSlider…" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "mazegen.explore(rooms = [[(3,3),(7,7)],[(10,10),(17,17)]])" - ] - }, - { - "cell_type": "code", - "execution_count": 181, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T20:41:53.964497Z", - "start_time": "2020-05-25T20:41:53.516395Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "... Saved maze in .\\GeneratedMaze_cellsize=20.png\n" - ] - } - ], - "source": [ - "mazegen.save()" - ] - }, - { - "cell_type": "code", - "execution_count": 177, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T20:38:51.130746Z", - "start_time": "2020-05-25T20:38:50.583327Z" - } - }, - "outputs": [], - "source": [ - "! start ." - ] - }, - { - "cell_type": "code", - "execution_count": 154, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T20:29:14.517427Z", - "start_time": "2020-05-25T20:29:13.993762Z" - } - }, - "outputs": [], - "source": [ - "mask = mazegen.make_mask()" - ] - }, - { - "cell_type": "code", - "execution_count": 155, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T20:29:15.419833Z", - "start_time": "2020-05-25T20:29:14.959426Z" - } - }, - "outputs": [], - "source": [ - "from PIL import Image" - ] - }, - { - "cell_type": "code", - "execution_count": 156, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T20:29:16.186233Z", - "start_time": "2020-05-25T20:29:15.757414Z" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "(210, 210, 3)" - ] - }, - "execution_count": 156, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mask.astype(np.int32).shape" - ] - }, - { - "cell_type": "code", - "execution_count": 157, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T20:29:25.178773Z", - "start_time": "2020-05-25T20:29:24.757573Z" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "10" - ] - }, - "execution_count": 157, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mazegen.cell_size" - ] - }, - { - "cell_type": "code", - "execution_count": 167, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T20:33:34.819196Z", - "start_time": "2020-05-25T20:33:34.411276Z" - } - }, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAANIAAADSCAIAAACw+wkVAAAC8klEQVR4nO3dQW4bMRAAQcnw/78s/4AXYtyktuoayCsljTl4QvH1AgAAAAAAKLzXf/z5fFYvfq9evn7tjuq5Nzrz3+hn6KmwIDsCsiMgOwKyIyA7ArIjIDsCsiPwWz14/VvsG5+7s9GZe+6OuQ2HaUdAdgRkR0B2BGRHQHYEZEdAdgRkRyDbUpx54mFu07DzeauNzhzTjoDsCMiOgOwIyI6A7AjIjoDsCMiOwOPOUsypdhiVnc9r2hGQHQHZEZAdAdkRkB0B2RGQHQHZEci2FGvVtxit3bhL2DF3/sO0IyA7ArIjIDsCsiMgOwKyIyA7ArIjcOiWYu3MG6Greyl2fnK1szHtCMiOgOwIyI6A7AjIjoDsCMiOgOwIPO5eiqc9d8fcZsW0IyA7ArIjIDsCsiMgOwKyIyA7ArIjMLilqG6eOPM7neb+NnbOcFS7E9OOgOwIyI6A7AjIjoDsCMiOgOwIyI7A4JbizG9eOtOZ73nuXZl2BGRHQHYEZEdAdgRkR0B2BGRHQHYEsm98OvNuCT/5f5h2BGRHQHYEZEdAdgRkR0B2BGRHQHYErrw9e26HceZ2pDppMXdbuGlHQHYEZEdAdgRkR0B2BGRHQHYEZEfgynspzrzxYmeXUH0i91LwILIjIDsCsiMgOwKyIyA7ArIjIDsCV95LceM+YO3MeynmmHYEZEdAdgRkR0B2BGRHQHYEZEdAdgSuvJfi+840rJ35rnaYdgRkR0B2BGRHQHYEZEdAdgRkR0B2BB53L8X3nVq48ROZdgRkR0B2BGRHQHYEZEdAdgRkR0B2BK7cUnzf2YI5Z55ZMe0IyI6A7AjIjoDsCMiOgOwIyI6A7AhcuaVYq37zvrazWbnxtMSaaUdAdgRkR0B2BGRHQHYEZEdAdgRkR+ALtxRznnYfxhzTjoDsCMiOgOwIyI6A7AjIjoDsCMiOwNaWovo//jfeS3HjeYi592zaEZAdAdkRkB0B2RGQHQHZEZAdAdkBAAAAAADwGH8wq6CX5AKIDQAAAABJRU5ErkJggg==\n", - "text/plain": [ - "" - ] - }, - "execution_count": 167, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "Image.fromarray(np.asarray(mask,dtype=np.uint8))" - ] - }, - { - "cell_type": "code", - "execution_count": 163, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T20:31:41.073414Z", - "start_time": "2020-05-25T20:31:40.649345Z" - } - }, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAABUAAAAVEAAAAADc7CYJAAAAhUlEQVR4nJVSWw7AIAyCpfe/cvejjr6yWGMUbRFR4CoIgKcphnZb6S5lGxMheJY8bVWc2PJc6Ey2CAdXNQsrrNclel1TGY7V0WXsNE3a2epS7MchBJsLe2GN1d0VE2vWnHQ/JSVybszP13BMWDuCsq+9Xk7g9w8wsA1uDD5mn61J6Z/3Jl42Pxti36kHKAAAAABJRU5ErkJggg==\n", - "text/plain": [ - "" - ] - }, - "execution_count": 163, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "Image.fromarray(1 - mesh)" - ] - }, - { - "cell_type": "code", - "execution_count": 86, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T18:53:45.889519Z", - "start_time": "2020-05-25T18:53:45.616234Z" - } - }, - "outputs": [], - "source": [ - "from westworld.utils.image import mask_to_image3d" - ] - }, - { - "cell_type": "code", - "execution_count": 89, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T18:53:59.571357Z", - "start_time": "2020-05-25T18:53:59.273155Z" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "255" - ] - }, - "execution_count": 89, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mask_to_image3d(mask).max()" - ] - }, - { - "cell_type": "code", - "execution_count": 69, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T18:49:16.973245Z", - "start_time": "2020-05-25T18:49:16.739873Z" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[[0, 0, 0],\n", - " [0, 0, 0],\n", - " [0, 0, 0],\n", - " ...,\n", - " [0, 0, 0],\n", - " [0, 0, 0],\n", - " [0, 0, 0]],\n", - "\n", - " [[0, 0, 0],\n", - " [0, 0, 0],\n", - " [0, 0, 0],\n", - " ...,\n", - " [0, 0, 0],\n", - " [0, 0, 0],\n", - " [0, 0, 0]],\n", - "\n", - " [[0, 0, 0],\n", - " [0, 0, 0],\n", - " [0, 0, 0],\n", - " ...,\n", - " [0, 0, 0],\n", - " [0, 0, 0],\n", - " [0, 0, 0]],\n", - "\n", - " ...,\n", - "\n", - " [[0, 0, 0],\n", - " [0, 0, 0],\n", - " [0, 0, 0],\n", - " ...,\n", - " [0, 0, 0],\n", - " [0, 0, 0],\n", - " [0, 0, 0]],\n", - "\n", - " [[0, 0, 0],\n", - " [0, 0, 0],\n", - " [0, 0, 0],\n", - " ...,\n", - " [0, 0, 0],\n", - " [0, 0, 0],\n", - " [0, 0, 0]],\n", - "\n", - " [[0, 0, 0],\n", - " [0, 0, 0],\n", - " [0, 0, 0],\n", - " ...,\n", - " [0, 0, 0],\n", - " [0, 0, 0],\n", - " [0, 0, 0]]], dtype=int8)" - ] - }, - "execution_count": 69, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mazegen.make_mask().astype(np.int8)" - ] - }, - { - "cell_type": "code", - "execution_count": 71, - "metadata": { - "ExecuteTime": { - "end_time": "2020-05-25T18:49:39.398553Z", - "start_time": "2020-05-25T18:49:38.838052Z" - } - }, - "outputs": [ - { - "ename": "TypeError", - "evalue": "Cannot handle this data type", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\PIL\\Image.py\u001b[0m in \u001b[0;36mfromarray\u001b[1;34m(obj, mode)\u001b[0m\n\u001b[0;32m 2644\u001b[0m \u001b[0mtypekey\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mshape\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0marr\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"typestr\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2645\u001b[1;33m \u001b[0mmode\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrawmode\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_fromarray_typemap\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mtypekey\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2646\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mKeyError\u001b[0m: ((1, 1, 3), '|i1')", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mmazegen\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msave\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32mc:\\git\\westworld\\westworld\\utils\\maze.py\u001b[0m in \u001b[0;36msave\u001b[1;34m(self, folder)\u001b[0m\n\u001b[0;32m 81\u001b[0m \u001b[0mmask\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmake_mask\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 82\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 83\u001b[1;33m \u001b[0mImage\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfromarray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmask\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msave\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 84\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\PIL\\Image.py\u001b[0m in \u001b[0;36mfromarray\u001b[1;34m(obj, mode)\u001b[0m\n\u001b[0;32m 2645\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrawmode\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_fromarray_typemap\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mtypekey\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2646\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2647\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Cannot handle this data type\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2648\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2649\u001b[0m \u001b[0mrawmode\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mTypeError\u001b[0m: Cannot handle this data type" - ] - } - ], - "source": [ - "mazegen.save()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "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.4" - }, - "toc": { - "base_numbering": 1, - "nav_menu": {}, - "number_sections": true, - "sideBar": true, - "skip_h1_title": false, - "title_cell": "Table of Contents", - "title_sidebar": "Contents", - "toc_cell": false, - "toc_position": {}, - "toc_section_display": true, - "toc_window_display": false - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/dev/dev_js/test_threejs.html b/dev/dev_js/test_threejs.html index d54ff29..57cbde9 100644 --- a/dev/dev_js/test_threejs.html +++ b/dev/dev_js/test_threejs.html @@ -24,7 +24,9 @@ var cube = new THREE.Mesh( geometry, material ); scene.add( cube ); - camera.position.z = 5; + camera.position.z = 20; + camera.position.x = 5; + camera.position.y = 6 var animate = function () { requestAnimationFrame( animate ); @@ -36,7 +38,10 @@ }; animate(); - + + var grid = new THREE.GridHelper(100, 10); + scene.add(grid); + // Our Javascript will go here. diff --git a/dev/sprites/sprite_arrow.png b/dev/sprites/sprite_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..2717828dc5a664c4ac8fe27ec9ae2da2bfb1701d GIT binary patch literal 394 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1SBWM%0B~AjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85o30K$!7fntTONgS@AUV@QPi+e-&I4;%0}T+F+c{rrv6&TkiN zFBxhXuzX&uF)1fQmgl{Q&dcDcYTeiJvmym+H@)lMe&D#6>?W_^`W=%(pSP(=1;sTdjb=FxdavVAzGfp{OU^~CzNb(;Y8Q~QxAF77UJ(a$Y z`Gdr2Ki+w*#!Rx+75%N-QpC7IBn~>=J`ri55KzDp9Fct@<>5BQ=7?+wGw#)_dAAL^ zpSmB4+)>5#IHE4)jE;`zj#rJm77M#lAI=k=_Mk=UPxjWsoKvT^mdZZ7aPQ2j2N&)& i{9g<5rt#_g$o(zv4$4hfc%={+ehi+jelF{r5}E+2f1XGH literal 0 HcmV?d00001 diff --git a/westworld/agents/grid_agent.py b/westworld/agents/grid_agent.py index 7fce177..ea52787 100644 --- a/westworld/agents/grid_agent.py +++ b/westworld/agents/grid_agent.py @@ -10,7 +10,7 @@ class BaseGridAgent(BaseRectangle): def __init__(self,x,y,width = 1,height = 1,color = (255,0,0),circle = False,diagonal = False, - curiosity = 20,search_radius = 2, + curiosity = 20,search_radius = 2,speed = 5, active_pathfinding = 1.0, **kwargs, ): @@ -18,6 +18,7 @@ def __init__(self,x,y,width = 1,height = 1,color = (255,0,0),circle = False,diag # Movement description + self.speed = speed self.diagonal = diagonal self.pathfinder = AStar(active_pathfinding) @@ -41,18 +42,16 @@ def __repr__(self): # MOVEMENTS #================================================================================= - def set_direction(self): - self.direction_angle = np.random.uniform(0,2*np.pi) - def _angle_generator(self): - # Not sure it's the right way to do, control is not easy with generators - i = 0 - while True: - if i % self.curiosity == 0: - angle = np.random.uniform(0,2*np.pi) - i += 1 - yield angle + def set_direction(self,angle = None): + if angle is None: angle = np.random.uniform(0,360) + self.direction_angle = angle + + + def turn(self,angle): + self.direction_angle += angle + def explore(self): pass @@ -63,9 +62,13 @@ def when_blocked(self,collisions): def wander(self): - # Move using an unit movement (adjacent squares only) but more or less in the direction given by the angle - dx,dy = self._sample_unit_movement_from_angle(self.direction_angle) - self.move(dx = dx,dy = dy) + if self.on_grid: + # Move using an unit movement (adjacent squares only) but more or less in the direction given by the angle + dx,dy = self._sample_unit_movement_from_angle(self.direction_angle) + self.move(dx = dx,dy = dy) + + else: + self.move(speed = self.speed) # Change direction based on curiosity value if self.clock > 1 and self.clock % self.curiosity == 0: @@ -209,20 +212,28 @@ def follow_mouse(self,n = None): self.move_towards(x = x,y = y,n = n) - def move(self,dx = 0,dy = 0,angle = None,dr = None): + def move(self,dx = 0,dy = 0,speed = None,angle = None): # Store default value for collisions is_collision = False + if speed is not None: + if angle is None: angle = self.direction_angle + angle = 2* np.pi * angle / 360 - 0.5 * np.pi + dx = int(speed * np.cos(angle)) + dy = int(speed * np.sin(angle)) + + self.move(dx = dx,dy = dy) + # Move using radial movement (with angle and radius) - if angle is not None: + elif angle is not None: cell_size = self.cell_size # Compute delta directions with basic trigonometry # In a grid environment, movement is rounded to the integer to fit in the grid - dx = int(dr * cell_size * np.cos(angle)) - dy = int(dr * cell_size * np.sin(angle)) + dx = int(speed * cell_size * np.cos(angle)) + dy = int(speed * cell_size * np.sin(angle)) return self.move(dx = dx,dy = dy) diff --git a/westworld/assets/__init__.py b/westworld/assets/__init__.py index a24c9cb..788eb2b 100644 --- a/westworld/assets/__init__.py +++ b/westworld/assets/__init__.py @@ -1,2 +1,3 @@ from .sprites.ball import make_ball -from .sprites.blob import make_blob \ No newline at end of file +from .sprites.blob import make_blob +from .sprites.arrow import make_arrow \ No newline at end of file diff --git a/westworld/assets/sprites/arrow.py b/westworld/assets/sprites/arrow.py new file mode 100644 index 0000000..591c622 --- /dev/null +++ b/westworld/assets/sprites/arrow.py @@ -0,0 +1,2508 @@ +import numpy as np +def make_arrow(color = (63,72,204),color2 = None,transparency = (200,191,231)): + + if color2 is None: + color2 = color + + return np.array( + [[transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color, + color, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + color2, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency], + [transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency, + transparency]] +) diff --git a/westworld/assets/sprites/utils.py b/westworld/assets/sprites/utils.py new file mode 100644 index 0000000..0d5cfbc --- /dev/null +++ b/westworld/assets/sprites/utils.py @@ -0,0 +1,40 @@ + +from PIL import Image +import numpy as np +import pandas as pd +import pyperclip + + +def make_lighter_color(color,lighter = 0.5): + lighter_fn = lambda x,t : min([255,int((1+t)*x)]) + return tuple([lighter_fn(x,lighter) for x in color]) + +def get_unique_colors_sprite(filepath): + img = Image.open(filepath) + array = np.array(img).reshape(-1,3).tolist() + array = ["(" + ",".join(map(str,x)) + ")" for x in array] + return pd.Series(array).value_counts() + + +def make_sprite_generator_fn(filepath,replace = None,return_array = False): + + img = Image.open(filepath) + shape = img.size + array = np.array(img).reshape(-1,3).tolist() + array = ["(" + ",".join(map(str,x)) + ")" for x in array] + + if replace is not None: + array = [replace.get(x,x) for x in array] + + array = np.array(array).reshape(shape) + + if return_array: + return array + + + array = f"{array.tolist()}".replace(",",",\n\t\t").replace('"','').replace("'","") + + fn_str = f"import numpy as np\n\ndef make_sprite(args):\n\treturn np.array(\n\t\t{array}\n)" + fn_str = fn_str.replace("\t"," ") + pyperclip.copy(fn_str) + print("Copied to clipboard") \ No newline at end of file diff --git a/westworld/environment/grid.py b/westworld/environment/grid.py index c5c49ea..8b5f32c 100644 --- a/westworld/environment/grid.py +++ b/westworld/environment/grid.py @@ -8,14 +8,13 @@ # Custom libraries -from .spatial import SpatialEnvironment from ..algorithms.neighbors import NeighborsFinder -class GridEnvironment(SpatialEnvironment): +class GridEnvironment: def __init__(self,width = None,height = None,cell_size = 10, objects = None,show_grid = False,grid_color = (50,50,50),background_color = (0,0,0), - callbacks_step = None, + callbacks_step = None,max_spawn_trials = 1000, ): # Init pygame @@ -27,6 +26,7 @@ def __init__(self,width = None,height = None,cell_size = 10, self._done = False self.show_grid = show_grid self.grid_color = grid_color + self.max_spawn_trials = max_spawn_trials self.width = width if width is not None else ((GetSystemMetrics(0) - 100) // cell_size) self.height = height if height is not None else ((GetSystemMetrics(1) - 100) // cell_size) self.background_color = background_color @@ -49,6 +49,12 @@ def __init__(self,width = None,height = None,cell_size = 10, self.render() + @property + def is_grid(self): + return self.cell_size > 1 + + + @property def cell_size(self): return self._cell_size @@ -226,34 +232,38 @@ def spawn(self,spawner,n,allow_overlap = False,**kwargs): # Spawn n elements (works also with n = 1) for i in range(n): - # Generate a random position considering or not overlaps - x,y = self.get_random_available_pos(allow_overlap = allow_overlap) + if not self.is_grid and allow_overlap == False: - # Spawn new object using spawner - # Pass also kwargs to spawner - obj = spawner(x,y,**kwargs) - self.add_object(obj) + x,y = self.get_random_available_pos(allow_overlap = True) + obj = spawner(x,y,**kwargs) + self.add_object(obj) + is_spawned = not obj.collides()[0] + i = 0 - # Append to data - self.set_data() + while not is_spawned: + x,y = self.get_random_available_pos(allow_overlap = True) + obj.move_at(x = x,y = y) + is_spawned = not obj.collides()[0] + + i += 1 + if i > self.max_spawn_trials: + is_spawned = True + self.remove_object(obj) + else: - #================================================================================= - # LAYERS - #================================================================================= + # Generate a random position considering or not overlaps + x,y = self.get_random_available_pos(allow_overlap = allow_overlap) + # Spawn new object using spawner + # Pass also kwargs to spawner + obj = spawner(x,y,**kwargs) - def _set_obstacle_layer_group(self): - group = pygame.sprite.Group() - for layer in self.layers: - if layer.obstacle: - group.add(layer.sprite) - self._obstacle_layer_group = group + self.add_object(obj) + # Append to data + self.set_data() - # @property - # def has_layers(self): - # return len(self.layers) >= 1 diff --git a/westworld/environment/spatial.py b/westworld/environment/spatial.py index 8bf0275..6b0a2e8 100644 --- a/westworld/environment/spatial.py +++ b/westworld/environment/spatial.py @@ -1,11 +1,16 @@ +from .grid import GridEnvironment + + +class SpatialEnvironment(GridEnvironment): + def __init__(self,width = None,height = None, + objects = None,background_color = (0,0,0), + callbacks_step = None, + ): + + super().__init__(width = width,height = height,cell_size = 1,show_grid = False,objects = objects, + background_color = background_color,callbacks_step = callbacks_step) -class SpatialEnvironment: - def __init__(self): - pass - @property - def cell_size(self): - return 1 \ No newline at end of file diff --git a/westworld/objects/base_object.py b/westworld/objects/base_object.py index 09322e3..6307596 100644 --- a/westworld/objects/base_object.py +++ b/westworld/objects/base_object.py @@ -67,6 +67,9 @@ def init(self): pass + @property + def on_grid(self): + return self.env.is_grid @property def stationary(self):