Skip to content

Commit

Permalink
update CARLMario
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikschubert committed Sep 4, 2023
1 parent 3a2c03c commit afeb85c
Show file tree
Hide file tree
Showing 301 changed files with 9,561 additions and 176 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,8 @@ RNA and Mario at this point, however, will not run on any operation system besid

To install ToadGAN for the Mario environment:
```bash
git submodule update --init --recursive

# if this does not work, clone manually
git clone https://github.com/frederikschubert/Mario-AI-Framework carl/envs/mario/Mario-AI-Framework
git clone https://github.com/Mawiszus/TOAD-GUI carl/envs/mario/TOAD-GUI

# System requirements
sudo apt install libfreetype6-dev xvfb

# Compile java source files
cd carl/envs/mario/Mario-AI-Framework/src
javac *.java
```

If you want to use RNA, please take a look at the associated [ReadME](carl/envs/rna/readme.md).
Expand Down
6 changes: 3 additions & 3 deletions carl/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ def check_spec(spec_name: str) -> bool:
if found:
from carl.envs.dmc import *

found = check_spec("distance")
if found:
from carl.envs.rna import *
# found = check_spec("distance")
# if found:
# from carl.envs.rna import *
46 changes: 14 additions & 32 deletions carl/envs/mario/carl_mario.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
import sys

from typing import List

Expand All @@ -8,24 +9,14 @@
CategoricalContextFeature,
ContextFeature,
UniformFloatContextFeature,
UniformIntegerContextFeature,
)
from carl.context.selection import AbstractSelector
from carl.envs.carl_env import CARLEnv
from carl.envs.mario.mario_env import MarioEnv
from carl.envs.mario.toad_gan import generate_level
from carl.envs.mario.pcg_smb_env import MarioEnv, generate_level
from carl.utils.types import Contexts

try:
from carl.envs.mario.toad_gan import generate_initial_noise
except FileNotFoundError:
from torch import Tensor

def generate_initial_noise(width: int, height: int, level_index: int) -> Tensor:
return Tensor()


INITIAL_HEIGHT = 16
INITIAL_WIDTH = 100
LEVEL_HEIGHT = 16


class CARLMarioEnv(CARLEnv):
Expand All @@ -52,43 +43,34 @@ def __init__(
**kwargs,
)
self.levels: List[str] = []
self._update_context()

def _update_context(self) -> None:
self.env: MarioEnv
self.context = CARLMarioEnv.get_context_space().insert_defaults(
self.context
)
if not self.levels:
for context in self.contexts.values():
level = generate_level(
width=INITIAL_WIDTH,
height=INITIAL_HEIGHT,
level, _ = generate_level(
width=context["level_width"],
height=LEVEL_HEIGHT,
level_index=context["level_index"],
initial_noise=context["noise"],
seed=context["noise_seed"],
filter_unplayable=True,
)
self.levels.append(level)
self.env.mario_state = self.context["mario_state"]
self.env.mario_inertia = self.context["mario_inertia"]
self.env.levels = [self.levels[self.context_index]]

def _log_context(self) -> None:
if self.logger:
loggable_context = {k: v for k, v in self.context.items() if k != "noise"}
self.logger.write_context(
self.episode_counter, self.total_timestep_counter, loggable_context
)
self.env.levels = [self.levels[self.context_id]]

@staticmethod
def get_context_features() -> dict[str, ContextFeature]:
return {
"level_width": UniformIntegerContextFeature("level_width", 16, 1000, default_value=100),
"level_index": CategoricalContextFeature(
"level_index", choices=np.arange(0, 14), default_value=0
),
"noise": UniformFloatContextFeature(
"noise",
lower=-1.0,
upper=1.0,
default_value=generate_initial_noise(INITIAL_WIDTH, INITIAL_HEIGHT, 0),
),
"noise_seed": UniformIntegerContextFeature("noise_seed", 0, sys.maxsize, default_value=0),
"mario_state": CategoricalContextFeature(
"mario_state", choices=[0, 1, 2], default_value=0
),
Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions carl/envs/mario/pcg_smb_env/Mario-AI-Framework/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Mario AI Framework

## Build

```bash
mvn clean package && mv target/Mario-AI-Framework-0.8.0-SNAPSHOT.jar .
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------g-----------------------------------------------------------------------------------------------------------------------
----------------------!---------------------------------------------------------SSSSSSSS---SSS!--------------@-----------SSS----S!!S--------------------------------------------------------##------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------###------------
-------------------------------------------------------------------------------g----------------------------------------------------------------------------------------------------------####------------
----------------------------------------------------------------1------------------------------------------------------------------------------------------------------------------------#####------------
----------------!---S@S!S---------------------tt---------tt------------------S@S--------------C-----SU----!--!--!-----S----------SS------#--#----------##--#------------SS!S------------######------------
--------------------------------------tt------tt---------tt-----------------------------------------------------------------------------##--##--------###--##--------------------------#######------------
----------------------------tt--------tt------tt---------tt----------------------------------------------------------------------------###--###------####--###-----tt--------------tt-########--------F---
---M-----------------g------tt--------tt-g----tt-----g-g-tt------------------------------------g-g--------k-----------------gg-g-g----####--####----#####--####----tt---------gg---tt#########--------#---
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--XXXXXXXXXXXXXXX---XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--XXXXXXXXXXXXXXX---XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------oo--------------------------------------------------------------------------------------------------------------------
-------------------------------------g-g--------------------------------------------------------------------------------------------------------------
----------------------ooor---------%%%%%%%-------------oooo----------R------------------oo--oo--------------------------------------------------------
---------------------%%%%%----------|||||--------------%%%%----------------g----oo---------------------------R-----oo--------------------##-----------
----------------------|||-----------|||||----oo---------||-------------%%%%%%------------------------r-----------------------------------##-----------
----------------------|||-----------|||||---------------||--------------||||-----------------------%%%%%%%%-------------------SSS------####-----------
----------------------|||-----%%%%%-|||||---------SSS---||--------------||||-----SS-----------------||||||-----------------------------####-----------
-------------------%%%%%%%%----|||--|||||---------------||-------%%%----||||-------------SS---------||||||-----%%%%--%%%%------------######-----------
--------------------||||||-----|||--|||||-------------U-||--------|-----||||------------------------||||||------||----||-------------######-----------
--------------------||||||--o--|||--|||||---------------||--------|-----||||-----------------%%%%---||||||------||----||-------------######--------F--
-M-----------%%%%---||||||-%%%-|||--|||||---------------||--------|-----||||------------------||----||||||--ooo-||----||---------r---######--------#--
XXXXXXXXXXX---||----||||||--|--|||--|||||----%%%%-----%%%%%-%%%%%-|-----||||------------------||----||||||--%%%-||----||----XXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXX---||----||||||--|--|||--|||||-----||-------|||---|||--|-----||||------------------||----||||||---|--||----||----XXXXXXXXXXXXXXXXXXXXXXXXXX
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------US-----------------------------------------------------y---------------------2--------------------------------------------------------------###------------
----------------------------------------------------------------------------------#SSS---------------------------------------------------------y-------------------------###------------
---------------------------------------------------------------------oo----------##------------------------------------y---------------------#SS--o-------------------y--###------------
-----------------------------------------------------------------y--------------###1--------------ooo------------------XSS-?Q---------------##------------------------#--###------------
---------QQ-----------------####--SSC------------------ooo-------##-------------###-----------------------2-----------XX-------------------###--SC-------------------##--###------------
-----------------------y-#####----------------------------------###-----------#-###--SSS-------TT--------------------XXX------------------####---------------------y###--###------------
--------------------y-######-----------------------------------####----------##-###------------TT-------------------XXXX-------y---------#####---SSS---------------####--###--------F---
-------------------#######------------------y-y---------------#####-------------###---------y--TT-------y--y-------XXXXX---SSSSS-----y--######--------------------#####--###--------#---
XXXXXXXXXXXXX--XXXXXXXXX------XX--XXXXXXXXXXXXXXXX--XXXXXXXXXXXXXXX---XXXXXXXXXXXXXXXX---XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-------XX-XXXXXXXXXXXX------XXXXXXXXX---XXXXXXX--XXXXXXXXXXXXXXX
XXXXXXXXXXXXX--XXXXXXXXX------XX--XXXXXXXXXXXXXXXX--XXXXXXXXXXXXXXX---XXXXXXXXXXXXXXXX---XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-------XX-XXXXXXXXXXXX------XXXXXXXXX---XXXXXXX--XXXXXXXXXXXXXXX
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------K------------
--------------------------------------------------------------g----------------------------------------------------k--------------------------------------------------------------------------------------------------
------------------SCS-----------------------------------------SSSSS-----SSSSS---------------------------------S---SSSSSSSSS------------US---SS-------------SSS-------------------------------------------##-----------
---------------------------TT-----------------------------------------------------------------------------TT------------------------------------------------------TT------------------------------------###-----------
---------------------------TT----------------------------TT-----------------------TT----------------------TT------------------------------------------------------TT-----------------------------------####-----------
---------------------------XX----------------------TT----TT-----------------------TT----------------------TT-------------------------SS---------------------------TT----------------------------------#####-----------
-----SSS------TT---2---TT----------------TT---SU---TT----XX------------------2----TT-------------tt------SXXS------------------------------SSS---------#---SSS----XX-----TT-------TT----------------TT#####-----------
--------------TT-------TT-------------K--TT--------TT----------------------TT-----TT-----TT------tt-----------------------------------------------#-TT-#-----------------TT-----TTTT----TT---------#TT#####-----------
--------------TT-------TT-----TTTT-------TT--------TT---------TT-----tt----TT--TT-TT-----TT------tt-TT--------TT--------------TT--TT-------------##-TT-##----------------TT---TTTTTT----TT--------##TT#####--------F--
--------------TT----k--TT-----TTTT-------TT------k-TT---------TT-----tt----TT--TT-TT---k-TT------tt-TT--------TT--------------TT--TT------------###-TT-##---------k------TT---TTTTTT----TT-------###TT#####--------#--
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX------XXXXXXXXXXXX-X-XXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX------XXXXXXXXXXXX-X-XXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------oo-------------------------------------------------------ooo----------------------------------------------------------------------------------
--------------------------------------------------?-----------------------------%%%------------------------------------------------------------------oo--------------
--------------------------------------ooooooo------------------------------------|-----------------------------------------------------------------------------------
----------------------SSSS---------SSSS---------------------------SSoo----SS-----|----------------------------------------oo---%%%%--------------------%%%%----------
------------------------------------------------SSSS-----------------------------|-------------------------------SSS------SS----||--------------SSS-----||-----------
-----------------------------------------SSSS------------------------------------|----------------------------------------------||------SSS-oo----------||-----------
---------------------------------------------------------------------------------|---%%%%------oooo-----------------------------||----------------------||-----------
----------------%%%%------%%%%%-----------------------------%%%%%%----SS-----SS--|----||--------------%%%%%%-----------------SS-||%%%%%-----SS----------||-----------
-----------------||--------|||-------------------------SSS---||||---------------%%%%%%||---------------||||---------------------||-|||------------------||-----------
-----------------||--------|||--------------%%%%%------------||||----------------||||-||---------------||||---------------------||-|||------------------||---------F-
-M---------------||--------|||---------------|||-------------||||----------------||||-||---------------||||---------------------||-|||------------------||---------X-
XXXXXXXXXXX--%%%%||%%%%----|||--%%%%--%%%%---|||-------------||||----------------||||-||%%%%%%%%%-%%%%-||||-%%%%%%----%%%%-----%%%%|||------------------||-XXXXXXXXXX
XXXXXXXXXXX---||-||-||-----|||---||----||----|||-------------||||----------------||||-||-|||||||---||--||||--||||------||-------||-|||------------------||-XXXXXXXXXX
Loading

0 comments on commit afeb85c

Please sign in to comment.