crosswalk-env 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crosswalk_env-0.0.1/LICENSE +21 -0
- crosswalk_env-0.0.1/PKG-INFO +48 -0
- crosswalk_env-0.0.1/README.md +31 -0
- crosswalk_env-0.0.1/pyproject.toml +36 -0
- crosswalk_env-0.0.1/setup.cfg +4 -0
- crosswalk_env-0.0.1/src/crosswalk_env/__init__.py +10 -0
- crosswalk_env-0.0.1/src/crosswalk_env/common/__init__.py +8 -0
- crosswalk_env-0.0.1/src/crosswalk_env/common/action.py +45 -0
- crosswalk_env-0.0.1/src/crosswalk_env/common/gameobject/agent.py +124 -0
- crosswalk_env-0.0.1/src/crosswalk_env/common/gameobject/car.py +114 -0
- crosswalk_env-0.0.1/src/crosswalk_env/common/gameobject/car_details.py +126 -0
- crosswalk_env-0.0.1/src/crosswalk_env/common/gameobject/game_object.py +43 -0
- crosswalk_env-0.0.1/src/crosswalk_env/common/road.py +34 -0
- crosswalk_env-0.0.1/src/crosswalk_env/common/utils.py +12 -0
- crosswalk_env-0.0.1/src/crosswalk_env/environment.py +827 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/README.md +15 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_BOXTRUCK_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_BOXTRUCK_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_BUS_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_BUS_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_CAMPER_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_CAMPER_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_CIVIC_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_CIVIC_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_COUPE_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_COUPE_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_HatchBack_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_HatchBack_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_JEEP_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_JEEP_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_LIMO_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_LIMO_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_LUXURY_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_LUXURY_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_MEDIUMTRUCK_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_MEDIUMTRUCK_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_MICRO_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_MICRO_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_MINIVAN_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_MINIVAN_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_MUSCLECAR_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_MUSCLECAR_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_PICKUP_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_PICKUP_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_SEDAN_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_SEDAN_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_SPORT_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_SPORT_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_SUPERCAR_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_SUPERCAR_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_SUV_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_SUV_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_VAN_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_VAN_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_WAGON_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Green_WAGON_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_BOXTRUCK_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_BOXTRUCK_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_BUS_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_BUS_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_CAMPER_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_CAMPER_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_CIVIC_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_CIVIC_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_COUPE_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_COUPE_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_HatchBack_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_HatchBack_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_JEEP_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_JEEP_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_LIMO_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_LIMO_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_LUXURY_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_LUXURY_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_MEDIUMTRUCK_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_MEDIUMTRUCK_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_MICRO_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_MICRO_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_MINIVAN_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_MINIVAN_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_MUSCLECAR_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_MUSCLECAR_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_PICKUP_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_PICKUP_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_SEDAN_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_SEDAN_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_SPORT_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_SPORT_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_SUPERCAR_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_SUPERCAR_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_SUV_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_SUV_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_VAN_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_VAN_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_WAGON_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Red_WAGON_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_BOXTRUCK_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_BOXTRUCK_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_BUS_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_BUS_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_CAMPER_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_CAMPER_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_CIVIC_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_CIVIC_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_COUPE_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_COUPE_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_HatchBack_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_HatchBack_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_JEEP_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_JEEP_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_LIMO_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_LIMO_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_LUXURY_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_LUXURY_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_MEDIUMTRUCK_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_MEDIUMTRUCK_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_MICRO_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_MICRO_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_MINIVAN_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_MINIVAN_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_MUSCLECAR_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_MUSCLECAR_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_PICKUP_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_PICKUP_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_SEDAN_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_SEDAN_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_SPORT_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_SPORT_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_SUPERCAR_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_SUPERCAR_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_SUV_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_SUV_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_VAN_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_VAN_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_WAGON_CLEAN_EAST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/cars/Yellow_WAGON_CLEAN_WEST_000_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_DOWN_0_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_DOWN_1_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_DOWN_2_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_DOWN_3_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_LEFT_0_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_LEFT_1_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_LEFT_2_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_LEFT_3_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_RIGHT_0_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_RIGHT_1_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_RIGHT_2_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_RIGHT_3_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_UP_0_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_UP_1_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_UP_2_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/sprites/player_color/player_UP_3_cropped.png +0 -0
- crosswalk_env-0.0.1/src/crosswalk_env/task.py +128 -0
- crosswalk_env-0.0.1/src/crosswalk_env/world/__init__.py +3 -0
- crosswalk_env-0.0.1/src/crosswalk_env/world/cars.py +74 -0
- crosswalk_env-0.0.1/src/crosswalk_env/world/roads.py +171 -0
- crosswalk_env-0.0.1/src/crosswalk_env/world/world.py +82 -0
- crosswalk_env-0.0.1/src/crosswalk_env.egg-info/PKG-INFO +48 -0
- crosswalk_env-0.0.1/src/crosswalk_env.egg-info/SOURCES.txt +160 -0
- crosswalk_env-0.0.1/src/crosswalk_env.egg-info/dependency_links.txt +1 -0
- crosswalk_env-0.0.1/src/crosswalk_env.egg-info/requires.txt +3 -0
- crosswalk_env-0.0.1/src/crosswalk_env.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Crosswalk Task
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: crosswalk-env
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Gymnasium environment for risky decision-making
|
|
5
|
+
Author-email: Jinwoo Jeong <jwjeong96@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://crosswalk-task.github.io
|
|
8
|
+
Project-URL: Repository, https://github.com/crosswalk-task/CrosswalkEnv
|
|
9
|
+
Project-URL: Issues, https://github.com/crosswalk-task/CrosswalkEnv/issues
|
|
10
|
+
Requires-Python: <3.13,>=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: pygame>=2.1
|
|
14
|
+
Requires-Dist: numpy<3,>=1.21
|
|
15
|
+
Requires-Dist: gymnasium<2,>=0.28
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# CrosswalkEnv
|
|
19
|
+
|
|
20
|
+
[](https://pypi.org/project/crosswalk-env/)
|
|
21
|
+
|
|
22
|
+
A [Gymnasium](https://gymnasium.farama.org/index.html) environment for risky decision-making.
|
|
23
|
+
|
|
24
|
+
## Requirements
|
|
25
|
+
|
|
26
|
+
* Python 3.9–3.12
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install crosswalk-env
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
|
|
36
|
+
For guides, API references, and examples, see the [Crosswalk Task documentation](https://crosswalk-task.github.io/).
|
|
37
|
+
|
|
38
|
+
* [Getting Started](https://crosswalk-task.github.io/crosswalkenv/getting_started.html)
|
|
39
|
+
* [Running Crosswalk Tasks](https://crosswalk-task.github.io/crosswalkenv/task.html)
|
|
40
|
+
* [CrosswalkEnv API](https://crosswalk-task.github.io/crosswalkenv/environment.html)
|
|
41
|
+
* [Training RL Agents](https://crosswalk-task.github.io/crosswalkenv/training_agents.html)
|
|
42
|
+
* [Observation Space](https://crosswalk-task.github.io/crosswalkenv/obs_space.html)
|
|
43
|
+
|
|
44
|
+
## Live Web Demo
|
|
45
|
+
|
|
46
|
+
For the web version, see [CrosswalkWebEnv](https://github.com/crosswalk-task/CrosswalkWebEnv).
|
|
47
|
+
|
|
48
|
+
Try the [Crosswalk Task Web Demo](https://crosswalk-task.github.io/demo).
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# CrosswalkEnv
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/crosswalk-env/)
|
|
4
|
+
|
|
5
|
+
A [Gymnasium](https://gymnasium.farama.org/index.html) environment for risky decision-making.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
* Python 3.9–3.12
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install crosswalk-env
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Documentation
|
|
18
|
+
|
|
19
|
+
For guides, API references, and examples, see the [Crosswalk Task documentation](https://crosswalk-task.github.io/).
|
|
20
|
+
|
|
21
|
+
* [Getting Started](https://crosswalk-task.github.io/crosswalkenv/getting_started.html)
|
|
22
|
+
* [Running Crosswalk Tasks](https://crosswalk-task.github.io/crosswalkenv/task.html)
|
|
23
|
+
* [CrosswalkEnv API](https://crosswalk-task.github.io/crosswalkenv/environment.html)
|
|
24
|
+
* [Training RL Agents](https://crosswalk-task.github.io/crosswalkenv/training_agents.html)
|
|
25
|
+
* [Observation Space](https://crosswalk-task.github.io/crosswalkenv/obs_space.html)
|
|
26
|
+
|
|
27
|
+
## Live Web Demo
|
|
28
|
+
|
|
29
|
+
For the web version, see [CrosswalkWebEnv](https://github.com/crosswalk-task/CrosswalkWebEnv).
|
|
30
|
+
|
|
31
|
+
Try the [Crosswalk Task Web Demo](https://crosswalk-task.github.io/demo).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "crosswalk-env"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "A Gymnasium environment for risky decision-making"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9,<3.13"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Jinwoo Jeong", email = "jwjeong96@gmail.com" }
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
dependencies = [
|
|
17
|
+
"pygame>=2.1",
|
|
18
|
+
"numpy>=1.21,<3",
|
|
19
|
+
"gymnasium>=0.28,<2",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://crosswalk-task.github.io"
|
|
24
|
+
Repository = "https://github.com/crosswalk-task/CrosswalkEnv"
|
|
25
|
+
Issues = "https://github.com/crosswalk-task/CrosswalkEnv/issues"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools]
|
|
28
|
+
package-dir = {"" = "src"}
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.packages.find]
|
|
31
|
+
where = ["src"]
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.package-data]
|
|
34
|
+
crosswalk_env = [
|
|
35
|
+
"sprites/**/*",
|
|
36
|
+
]
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from crosswalk_env.common.action import *
|
|
2
|
+
from crosswalk_env.common.road import *
|
|
3
|
+
from crosswalk_env.common.utils import *
|
|
4
|
+
|
|
5
|
+
from crosswalk_env.common.gameobject.game_object import *
|
|
6
|
+
from crosswalk_env.common.gameobject.agent import *
|
|
7
|
+
from crosswalk_env.common.gameobject.car import *
|
|
8
|
+
from crosswalk_env.common.gameobject.car_details import *
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
class Action(Enum):
|
|
6
|
+
NOTHING = 0
|
|
7
|
+
UP = 1
|
|
8
|
+
DOWN = 2
|
|
9
|
+
RIGHT = 3
|
|
10
|
+
LEFT = 4
|
|
11
|
+
|
|
12
|
+
def __str__(self):
|
|
13
|
+
string_map = {
|
|
14
|
+
Action.NOTHING: "Nothing",
|
|
15
|
+
Action.UP: "UP",
|
|
16
|
+
Action.DOWN: "DOWN",
|
|
17
|
+
Action.RIGHT: "RIGHT",
|
|
18
|
+
Action.LEFT: "LEFT",
|
|
19
|
+
}
|
|
20
|
+
return string_map[self]
|
|
21
|
+
|
|
22
|
+
ACTION_TO_DELTA = {
|
|
23
|
+
Action.NOTHING.value: np.array([0, 0]),
|
|
24
|
+
Action.UP.value: np.array([0, -1]),
|
|
25
|
+
Action.DOWN.value: np.array([0, 1]),
|
|
26
|
+
Action.RIGHT.value: np.array([1, 0]),
|
|
27
|
+
Action.LEFT.value: np.array([-1, 0]),
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
ACTION_DURATION = {
|
|
31
|
+
Action.NOTHING.value: 1,
|
|
32
|
+
Action.UP.value: 4,
|
|
33
|
+
Action.DOWN.value: 4,
|
|
34
|
+
Action.RIGHT.value: 4,
|
|
35
|
+
Action.LEFT.value: 4,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# NOTE: extra latency for human perception + increased time overs
|
|
39
|
+
ACTION_LATENCY = {
|
|
40
|
+
Action.NOTHING.value: 1,
|
|
41
|
+
Action.UP.value: 1,
|
|
42
|
+
Action.DOWN.value: 1,
|
|
43
|
+
Action.RIGHT.value: 1,
|
|
44
|
+
Action.LEFT.value: 1,
|
|
45
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import pygame
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
from crosswalk_env.common import Action, ACTION_TO_DELTA, ACTION_DURATION
|
|
7
|
+
from crosswalk_env.common.gameobject.game_object import GameObject
|
|
8
|
+
|
|
9
|
+
AGENT_STATUS_ALIVE = "alive"
|
|
10
|
+
AGENT_STATUS_DEAD = "dead"
|
|
11
|
+
|
|
12
|
+
class Agent(GameObject):
|
|
13
|
+
TARGET_LANE = 0
|
|
14
|
+
|
|
15
|
+
def __init__(self, agent_x_range, map_grid_width, map_grid_height, pix_square_size, steps_per_second, player_asset_info):
|
|
16
|
+
fixed_speed = 2.5
|
|
17
|
+
self.init_pos = (int(map_grid_width / 2), map_grid_height - 1)
|
|
18
|
+
cur_location = np.array([self.init_pos[0], self.init_pos[1]], dtype=float)
|
|
19
|
+
super().__init__(fixed_speed, cur_location, pix_square_size, steps_per_second)
|
|
20
|
+
self.map_grid_width = map_grid_width
|
|
21
|
+
self.map_grid_height = map_grid_height
|
|
22
|
+
self.is_dead = False
|
|
23
|
+
self.MIN_X = agent_x_range[0]
|
|
24
|
+
self.MAX_X = agent_x_range[1]
|
|
25
|
+
self.last_direction = Action.DOWN.value
|
|
26
|
+
self.images = player_asset_info["images"]
|
|
27
|
+
self.sizes = player_asset_info["sizes"]
|
|
28
|
+
self.mini_step_count = 0
|
|
29
|
+
|
|
30
|
+
def get_hitbox(self):
|
|
31
|
+
center_x = self.cur_location[0]
|
|
32
|
+
center_y = self.cur_location[1]
|
|
33
|
+
sub_dir = AGENT_STATUS_DEAD if self.is_dead else AGENT_STATUS_ALIVE
|
|
34
|
+
direction = self.mini_step_count % ACTION_DURATION[self.last_direction]
|
|
35
|
+
[player_width, player_height] = self.sizes[self.last_direction][sub_dir][direction]
|
|
36
|
+
top_y = center_y - player_height/2
|
|
37
|
+
bottom_y = top_y + player_height
|
|
38
|
+
left_x = center_x - player_width/2
|
|
39
|
+
right_x = left_x + player_width
|
|
40
|
+
return [top_y, bottom_y, left_x, right_x]
|
|
41
|
+
|
|
42
|
+
def get_cur_location_grid(self):
|
|
43
|
+
return int(round(self.cur_location[0])), int(round(self.cur_location[1]))
|
|
44
|
+
|
|
45
|
+
def get_cur_location_rounded(self):
|
|
46
|
+
return round(self.cur_location[0], 2), round(self.cur_location[1], 2)
|
|
47
|
+
|
|
48
|
+
def get_target_y(self):
|
|
49
|
+
return round(self.target_location[1], 2)
|
|
50
|
+
|
|
51
|
+
def update_target(self, action_value):
|
|
52
|
+
if action_value != Action.NOTHING.value:
|
|
53
|
+
self.last_direction = action_value
|
|
54
|
+
delta = ACTION_TO_DELTA[action_value] * (self.default_speed / self.steps_per_second) * ACTION_DURATION[action_value]
|
|
55
|
+
self.target_location = np.clip(self.cur_location + delta,
|
|
56
|
+
[self.MIN_X, self.TARGET_LANE],
|
|
57
|
+
[self.MAX_X, self.map_grid_height - 1])
|
|
58
|
+
|
|
59
|
+
def set_dead(self):
|
|
60
|
+
self.is_dead = True
|
|
61
|
+
self.stop()
|
|
62
|
+
|
|
63
|
+
def render(self, background):
|
|
64
|
+
adjustment = 0.5 * self.pix_square_size
|
|
65
|
+
agent_center_x = self.cur_location[0] * self.pix_square_size
|
|
66
|
+
agent_center_y = self.cur_location[1] * self.pix_square_size + adjustment
|
|
67
|
+
agent_position = (agent_center_x, agent_center_y)
|
|
68
|
+
if self.images is not None:
|
|
69
|
+
sub_dir = AGENT_STATUS_DEAD if self.is_dead else AGENT_STATUS_ALIVE
|
|
70
|
+
direction = self.mini_step_count % ACTION_DURATION[self.last_direction]
|
|
71
|
+
image = self.images[self.last_direction][sub_dir][direction]
|
|
72
|
+
[agent_grid_width, agent_grid_height] = self.sizes[self.last_direction][sub_dir][direction]
|
|
73
|
+
left_x_pix = agent_center_x - (agent_grid_width * self.pix_square_size / 2)
|
|
74
|
+
top_y_pix = agent_center_y - (agent_grid_height * self.pix_square_size / 2)
|
|
75
|
+
background.blit(image, (left_x_pix, top_y_pix))
|
|
76
|
+
return agent_position
|
|
77
|
+
|
|
78
|
+
def load_player_asset_info(pix_square_size, render_sprite):
|
|
79
|
+
directions = [Action.UP, Action.DOWN, Action.RIGHT, Action.LEFT]
|
|
80
|
+
size_ratio = {
|
|
81
|
+
"player_UP_0_cropped.png": [57,73],
|
|
82
|
+
"player_UP_1_cropped.png": [53,69],
|
|
83
|
+
"player_UP_2_cropped.png": [57,73],
|
|
84
|
+
"player_UP_3_cropped.png": [53,69],
|
|
85
|
+
|
|
86
|
+
"player_DOWN_0_cropped.png": [57,73],
|
|
87
|
+
"player_DOWN_1_cropped.png": [53,69],
|
|
88
|
+
"player_DOWN_2_cropped.png": [57,73],
|
|
89
|
+
"player_DOWN_3_cropped.png": [53,69],
|
|
90
|
+
|
|
91
|
+
"player_RIGHT_0_cropped.png": [49,69],
|
|
92
|
+
"player_RIGHT_1_cropped.png": [49,65],
|
|
93
|
+
"player_RIGHT_2_cropped.png": [49,69],
|
|
94
|
+
"player_RIGHT_3_cropped.png": [49,65],
|
|
95
|
+
|
|
96
|
+
"player_LEFT_0_cropped.png": [49,69],
|
|
97
|
+
"player_LEFT_1_cropped.png": [49,65],
|
|
98
|
+
"player_LEFT_2_cropped.png": [49,69],
|
|
99
|
+
"player_LEFT_3_cropped.png": [49,65],
|
|
100
|
+
}
|
|
101
|
+
images = {} if render_sprite else None
|
|
102
|
+
sizes = {}
|
|
103
|
+
for d in directions:
|
|
104
|
+
if render_sprite:
|
|
105
|
+
images[d.value] = {}
|
|
106
|
+
images[d.value][AGENT_STATUS_ALIVE] = []
|
|
107
|
+
images[d.value][AGENT_STATUS_DEAD] = []
|
|
108
|
+
sizes[d.value] = {}
|
|
109
|
+
sizes[d.value][AGENT_STATUS_ALIVE] = []
|
|
110
|
+
sizes[d.value][AGENT_STATUS_DEAD] = []
|
|
111
|
+
for i in range(4):
|
|
112
|
+
for status in [AGENT_STATUS_ALIVE, AGENT_STATUS_DEAD]:
|
|
113
|
+
file_name = f"player_{str(d)}_{i}_cropped.png"
|
|
114
|
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
115
|
+
image_path = os.path.join(current_dir, "../..", f"sprites/player_color/", file_name)
|
|
116
|
+
[width_ratio, height_ratio] = size_ratio[file_name]
|
|
117
|
+
agent_grid_height = (height_ratio / 140) * (0.4 if status == AGENT_STATUS_DEAD else 1)
|
|
118
|
+
agent_grid_width = (width_ratio / 140) * (2.4 if status == AGENT_STATUS_DEAD else 1)
|
|
119
|
+
if render_sprite:
|
|
120
|
+
object_image = pygame.image.load(image_path)
|
|
121
|
+
image = pygame.transform.scale(object_image, (agent_grid_width * pix_square_size, agent_grid_height * pix_square_size))
|
|
122
|
+
images[d.value][status].append(image)
|
|
123
|
+
sizes[d.value][status].append([agent_grid_width, agent_grid_height])
|
|
124
|
+
return {"images": images, "sizes": sizes}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from crosswalk_env.common.gameobject.game_object import GameObject
|
|
4
|
+
from crosswalk_env.common.utils import is_overlapping
|
|
5
|
+
from crosswalk_env.common.road import CrossWalk
|
|
6
|
+
|
|
7
|
+
class Car(GameObject):
|
|
8
|
+
CAR_SPEEDS = [3.0, 3.5, 4.0, 4.5] # NOTE: 2 is slightly faster than the player
|
|
9
|
+
|
|
10
|
+
def __init__(self, uid, initial_x, start_row_idx, car_grid_height, road, map_grid_width, pix_square_size, steps_per_second, car_details, random):
|
|
11
|
+
row_indices = []
|
|
12
|
+
for i in range(car_grid_height):
|
|
13
|
+
row_indices.append(start_row_idx + i)
|
|
14
|
+
initial_y = np.mean(row_indices)
|
|
15
|
+
cur_location = np.array([initial_x, initial_y], dtype=float)
|
|
16
|
+
super().__init__(0, cur_location, pix_square_size, steps_per_second)
|
|
17
|
+
self.uid = uid
|
|
18
|
+
self.rows = row_indices
|
|
19
|
+
self.map_grid_width = map_grid_width
|
|
20
|
+
self.car_details = car_details
|
|
21
|
+
self.random = random
|
|
22
|
+
self.set_random_speed()
|
|
23
|
+
self.road = road
|
|
24
|
+
self.nearby_cars = [] # all the cars in the overlapping lane
|
|
25
|
+
|
|
26
|
+
def get_cur_speed(self):
|
|
27
|
+
return self.default_speed if self.is_moving else 0
|
|
28
|
+
|
|
29
|
+
def get_hitbox(self):
|
|
30
|
+
left_x, right_x = self.get_cur_x_pos()
|
|
31
|
+
top_y, bottom_y = self.get_cur_y_pos()
|
|
32
|
+
return [top_y, bottom_y, left_x, right_x]
|
|
33
|
+
|
|
34
|
+
def get_cur_x_pos(self):
|
|
35
|
+
left_x = self.cur_location[0] - (self.car_details.car_grid_width/2)
|
|
36
|
+
right_x = self.cur_location[0] + (self.car_details.car_grid_width/2)
|
|
37
|
+
return left_x, right_x
|
|
38
|
+
|
|
39
|
+
def get_cur_y_pos(self):
|
|
40
|
+
top_y = self.cur_location[1] - (self.car_details.car_grid_height/2)
|
|
41
|
+
bottom_y = self.cur_location[1] + (self.car_details.car_grid_height/2)
|
|
42
|
+
return top_y, bottom_y
|
|
43
|
+
|
|
44
|
+
def set_random_speed(self):
|
|
45
|
+
self.default_speed = self.random.choice(self.CAR_SPEEDS)
|
|
46
|
+
if not self.car_details.go_right:
|
|
47
|
+
self.default_speed *= -1
|
|
48
|
+
|
|
49
|
+
def restart_if_needed(self):
|
|
50
|
+
# teleport to start of the lane when reaching the end
|
|
51
|
+
if self.car_details.go_right and self.cur_location[0] >= self.map_grid_width:
|
|
52
|
+
self.cur_location[0] = 0
|
|
53
|
+
self.set_random_speed()
|
|
54
|
+
if not self.car_details.go_right and self.cur_location[0] <= 0:
|
|
55
|
+
self.cur_location[0] = self.map_grid_width - 1
|
|
56
|
+
self.set_random_speed()
|
|
57
|
+
|
|
58
|
+
def update_target(self, dt):
|
|
59
|
+
self.restart_if_needed()
|
|
60
|
+
# stop in the current location when another car is in front of the car
|
|
61
|
+
if len(self.nearby_cars) > 0:
|
|
62
|
+
threshold = 0.1
|
|
63
|
+
my_left, my_right = self.get_cur_x_pos()
|
|
64
|
+
for other_car in self.nearby_cars:
|
|
65
|
+
other_left, other_right = other_car.get_cur_x_pos()
|
|
66
|
+
# stop when another car is in front of me
|
|
67
|
+
if self.car_details.go_right:
|
|
68
|
+
front_dist = other_left - my_right
|
|
69
|
+
else:
|
|
70
|
+
front_dist = my_left - other_right
|
|
71
|
+
if 0 < front_dist <= threshold:
|
|
72
|
+
self.stop()
|
|
73
|
+
return
|
|
74
|
+
|
|
75
|
+
# make the one in the back stop if the both cars are overlapping
|
|
76
|
+
# make the one with lower uid stop if the front positions are the same
|
|
77
|
+
if self.car_details.go_right:
|
|
78
|
+
front_diff = other_right - my_right
|
|
79
|
+
else:
|
|
80
|
+
front_diff = my_left - other_left
|
|
81
|
+
if front_diff > 0 or (front_diff == 0 and self.uid < other_car.uid):
|
|
82
|
+
if is_overlapping(my_left, my_right, other_left, other_right):
|
|
83
|
+
self.stop()
|
|
84
|
+
return
|
|
85
|
+
|
|
86
|
+
# stop in front of the crosswalk when it is activated
|
|
87
|
+
crosswalk = self.road.crosswalk
|
|
88
|
+
if crosswalk is not None and crosswalk.is_active:
|
|
89
|
+
car_left, car_right = self.get_cur_x_pos()
|
|
90
|
+
cw_left, cw_right = crosswalk.get_activation_left_right()
|
|
91
|
+
if self.car_details.go_right:
|
|
92
|
+
front_dist = abs(cw_left - car_right)
|
|
93
|
+
else:
|
|
94
|
+
front_dist = abs(cw_right - car_left)
|
|
95
|
+
if front_dist < CrossWalk.THRESHOLD_DISTANCE:
|
|
96
|
+
if is_overlapping(car_left, car_right, cw_left, cw_right):
|
|
97
|
+
pass # keep going to clear up the crosswalk
|
|
98
|
+
else:
|
|
99
|
+
self.stop()
|
|
100
|
+
return
|
|
101
|
+
self.target_location[0] = self.cur_location[0] + (self.default_speed * dt / 1000)
|
|
102
|
+
self.is_moving = True # moving unless stopped
|
|
103
|
+
|
|
104
|
+
def render(self, background):
|
|
105
|
+
left_x, _ = self.get_cur_x_pos()
|
|
106
|
+
top_y, _ = self.get_cur_y_pos()
|
|
107
|
+
left_x_pix = left_x * self.pix_square_size
|
|
108
|
+
top_y_pix = top_y * self.pix_square_size
|
|
109
|
+
adjustment = 0.5 * self.pix_square_size
|
|
110
|
+
if self.car_details.image is not None:
|
|
111
|
+
background.blit(self.car_details.image, (left_x_pix, top_y_pix + adjustment))
|
|
112
|
+
|
|
113
|
+
def __str__(self):
|
|
114
|
+
return f"Car(cur_pos=({self.cur_location[0], self.cur_location[1]}), crosswalk=({self.road.crosswalk}))"
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
import pygame
|
|
6
|
+
|
|
7
|
+
class Penalty(Enum):
|
|
8
|
+
LOW = 100
|
|
9
|
+
MEDIUM = 500
|
|
10
|
+
HIGH = 1000
|
|
11
|
+
|
|
12
|
+
class CarColorType(Enum):
|
|
13
|
+
GREEN = 0
|
|
14
|
+
YELLOW = 1
|
|
15
|
+
RED = 2
|
|
16
|
+
|
|
17
|
+
def __str__(self):
|
|
18
|
+
string_map = {
|
|
19
|
+
CarColorType.GREEN: "GREEN",
|
|
20
|
+
CarColorType.YELLOW: "YELLOW",
|
|
21
|
+
CarColorType.RED: "RED",
|
|
22
|
+
}
|
|
23
|
+
return string_map[self]
|
|
24
|
+
|
|
25
|
+
class RiskDetail:
|
|
26
|
+
def __init__(self, color_name, color, penalty):
|
|
27
|
+
self.color_name = color_name
|
|
28
|
+
self.color = color
|
|
29
|
+
self.penalty = penalty
|
|
30
|
+
|
|
31
|
+
RiskDetails = {
|
|
32
|
+
CarColorType.RED: RiskDetail(color_name="Red", color=(255, 0, 0), penalty=Penalty.HIGH),
|
|
33
|
+
CarColorType.YELLOW: RiskDetail(color_name="Yellow", color=(255, 255, 0), penalty=Penalty.MEDIUM),
|
|
34
|
+
CarColorType.GREEN: RiskDetail(color_name="Green", color=(0, 255, 0), penalty=Penalty.LOW),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# key = start_row_idx, value = car_heights
|
|
38
|
+
CARS_PER_LANE_PAIR_COMPOSITION = [
|
|
39
|
+
# 2 small cars
|
|
40
|
+
{0: [1], 1: [1]},
|
|
41
|
+
{0: [1], 1: [1]},
|
|
42
|
+
# 3 small cars
|
|
43
|
+
{0: [1], 1: [1, 1]},
|
|
44
|
+
{0: [1, 1], 1: [1]},
|
|
45
|
+
# 1 big car, 1 small car
|
|
46
|
+
{0: [2, 1], 1: []},
|
|
47
|
+
{0: [2], 1: [1]},
|
|
48
|
+
# 1 big car, 2 small cars
|
|
49
|
+
{0: [2, 1], 1: [1]},
|
|
50
|
+
{0: [2, 1], 1: [1]},
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
# key=height, value=(car_type, height:width ratio)
|
|
54
|
+
CAR_CANDIDATES = {
|
|
55
|
+
1: [
|
|
56
|
+
("MICRO", 1.1875),
|
|
57
|
+
("JEEP", 1.3043),
|
|
58
|
+
("CIVIC", 1.5556),
|
|
59
|
+
("VAN", 1.6136),
|
|
60
|
+
("SUV", 1.8333),
|
|
61
|
+
("MINIVAN", 1.9070),
|
|
62
|
+
("WAGON", 1.9545),
|
|
63
|
+
("HatchBack", 1.9750),
|
|
64
|
+
("SPORT", 1.9756),
|
|
65
|
+
("COUPE", 2.0238),
|
|
66
|
+
("MUSCLECAR", 2.0244),
|
|
67
|
+
("LUXURY", 2.0698),
|
|
68
|
+
("SEDAN", 2.0750),
|
|
69
|
+
("SUPERCAR", 2.2895),
|
|
70
|
+
("LIMO", 3.2250),
|
|
71
|
+
],
|
|
72
|
+
2: [
|
|
73
|
+
("CAMPER", 1.8868),
|
|
74
|
+
("MEDIUMTRUCK", 1.8983),
|
|
75
|
+
("BOXTRUCK", 2.0600),
|
|
76
|
+
("PICKUP", 2.1250),
|
|
77
|
+
# ("BUS", 2.2540), # Too white
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
def get_max_car_grid_width():
|
|
82
|
+
max_width = 0
|
|
83
|
+
for height in CAR_CANDIDATES:
|
|
84
|
+
for candidate in CAR_CANDIDATES[height]:
|
|
85
|
+
max_width = max(max_width, candidate[1] * height)
|
|
86
|
+
return max_width
|
|
87
|
+
|
|
88
|
+
def get_max_car_grid_height():
|
|
89
|
+
max_height = 0
|
|
90
|
+
for height in CAR_CANDIDATES:
|
|
91
|
+
max_height = max(max_height, height)
|
|
92
|
+
return max_height
|
|
93
|
+
|
|
94
|
+
class CarDetails:
|
|
95
|
+
def __init__(self, car_type, color_type, go_right, pix_square_size, car_grid_height, ratio, render_sprite, height_buffer = 0.1):
|
|
96
|
+
self.car_type = car_type
|
|
97
|
+
risk_detail = RiskDetails[color_type]
|
|
98
|
+
self.color = color_type
|
|
99
|
+
self.penalty = risk_detail.penalty
|
|
100
|
+
self.go_right = go_right
|
|
101
|
+
|
|
102
|
+
self.car_grid_height = car_grid_height - height_buffer # NOTE: needed to handle the overlap between the lanes
|
|
103
|
+
self.car_grid_width = self.car_grid_height * float(ratio)
|
|
104
|
+
self.car_width = self.car_grid_width * pix_square_size
|
|
105
|
+
self.car_height = self.car_grid_height * pix_square_size
|
|
106
|
+
|
|
107
|
+
self.image = None
|
|
108
|
+
if render_sprite:
|
|
109
|
+
direction = "EAST" if go_right else "WEST"
|
|
110
|
+
file_name = f"{risk_detail.color_name}_{car_type}_CLEAN_{direction}_000_cropped.png"
|
|
111
|
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
112
|
+
image_path = os.path.join(current_dir, "../..", "sprites/cars/", file_name)
|
|
113
|
+
object_image = pygame.image.load(image_path)
|
|
114
|
+
self.image = pygame.transform.scale(object_image, (self.car_width, self.car_height))
|
|
115
|
+
|
|
116
|
+
def load_car_details_dict(pix_square_size, render_sprite):
|
|
117
|
+
car_details_dict = {}
|
|
118
|
+
for height in [1, 2]:
|
|
119
|
+
for i in range(len(CAR_CANDIDATES[height])):
|
|
120
|
+
(car_type, ratio) = CAR_CANDIDATES[height][i]
|
|
121
|
+
car_details_dict[car_type] = {}
|
|
122
|
+
for color_type in RiskDetails.keys():
|
|
123
|
+
car_details_dict[car_type][color_type] = {}
|
|
124
|
+
for go_right in [False, True]:
|
|
125
|
+
car_details_dict[car_type][color_type][go_right] = CarDetails(car_type, color_type, go_right, pix_square_size, height, ratio, render_sprite)
|
|
126
|
+
return car_details_dict
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
class GameObject:
|
|
2
|
+
|
|
3
|
+
def __init__(self, default_speed, cur_location, pix_square_size, steps_per_second):
|
|
4
|
+
self.default_speed = default_speed
|
|
5
|
+
self.cur_location = cur_location
|
|
6
|
+
self.target_location = self.cur_location
|
|
7
|
+
self.pix_square_size = pix_square_size
|
|
8
|
+
self.steps_per_second = steps_per_second
|
|
9
|
+
self.is_moving = False
|
|
10
|
+
|
|
11
|
+
def update_position(self, dt):
|
|
12
|
+
tx, ty = self.target_location
|
|
13
|
+
cx, cy = self.cur_location
|
|
14
|
+
|
|
15
|
+
dx = tx - cx
|
|
16
|
+
dy = ty - cy
|
|
17
|
+
if abs(dx) < 0.1:
|
|
18
|
+
self.cur_location[0] = tx
|
|
19
|
+
dx = 0
|
|
20
|
+
if abs(dy) < 0.1:
|
|
21
|
+
self.cur_location[1] = ty
|
|
22
|
+
dy = 0
|
|
23
|
+
if dx == 0 and dy == 0: return
|
|
24
|
+
|
|
25
|
+
if dx != 0 and dy != 0: # diagonal move
|
|
26
|
+
dist = (dx ** 2 + dy ** 2) ** 0.5
|
|
27
|
+
else: # straight move
|
|
28
|
+
dist = max(abs(dx), abs(dy))
|
|
29
|
+
step = abs(self.default_speed) * (dt / 1000.0)
|
|
30
|
+
move = min(step, dist)
|
|
31
|
+
ux = dx / dist
|
|
32
|
+
uy = dy / dist
|
|
33
|
+
|
|
34
|
+
self.cur_location[0] += ux * move
|
|
35
|
+
self.cur_location[1] += uy * move
|
|
36
|
+
self.is_moving = True
|
|
37
|
+
|
|
38
|
+
def stop(self):
|
|
39
|
+
self.target_location = self.cur_location
|
|
40
|
+
self.is_moving = False
|
|
41
|
+
|
|
42
|
+
def render(self, background):
|
|
43
|
+
pass
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from crosswalk_env.common.gameobject.car_details import CarColorType, RiskDetails
|
|
2
|
+
|
|
3
|
+
class Road:
|
|
4
|
+
COMPOSITION_SIZE = 2
|
|
5
|
+
|
|
6
|
+
def __init__(self, uid, top_y, bottom_y, going_right_rows, random, crosswalk = None):
|
|
7
|
+
self.uid = uid
|
|
8
|
+
self.top_y = top_y
|
|
9
|
+
self.bottom_y = bottom_y
|
|
10
|
+
self.going_right = going_right_rows
|
|
11
|
+
self.car_color_type = random.choice([CarColorType.RED, CarColorType.YELLOW, CarColorType.GREEN])
|
|
12
|
+
self.risk_detail = RiskDetails[self.car_color_type]
|
|
13
|
+
self.crosswalk = crosswalk
|
|
14
|
+
|
|
15
|
+
class CrossWalk:
|
|
16
|
+
RATIO = 0.6
|
|
17
|
+
THRESHOLD_DISTANCE = 0.3
|
|
18
|
+
|
|
19
|
+
def __init__(self, uid, col, top_row, end_row):
|
|
20
|
+
self.uid = uid
|
|
21
|
+
self.col = col
|
|
22
|
+
self.left_end = col - 1
|
|
23
|
+
self.right_end = col + 1
|
|
24
|
+
self.top_row = top_row
|
|
25
|
+
self.end_row = end_row
|
|
26
|
+
self.is_active = False
|
|
27
|
+
|
|
28
|
+
def get_activation_left_right(self):
|
|
29
|
+
left = self.left_end - self.THRESHOLD_DISTANCE
|
|
30
|
+
right = self.right_end + self.THRESHOLD_DISTANCE
|
|
31
|
+
return left, right
|
|
32
|
+
|
|
33
|
+
def __str__(self):
|
|
34
|
+
return f"CrossWalk(active={self.is_active}, x=({self.left_end}, {self.right_end}), y=({self.top_row}, {self.end_row}))"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
def is_overlapping(left1, right1, left2, right2):
|
|
2
|
+
if right1 < left2 or right2 < left1:
|
|
3
|
+
return False
|
|
4
|
+
return True
|
|
5
|
+
|
|
6
|
+
def is_overlapping_rectangles(rect1, rect2):
|
|
7
|
+
(t1, b1, l1, r1) = rect1
|
|
8
|
+
(t2, b2, l2, r2) = rect2
|
|
9
|
+
|
|
10
|
+
if r1 < l2 or r2 < l1: return False
|
|
11
|
+
if b1 < t2 or b2 < t1: return False
|
|
12
|
+
return True
|