This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ale_py | |
| import gymnasium as gym | |
| import numpy as np | |
| from pong_features import PongFeaturesWrapper | |
| gym.register_envs(ale_py) | |
| def make_env(render: bool): | |
| mode = "human" if render else None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import gymnasium as gym | |
| # ALE Pong pixel colors | |
| _PLAYER_COLOR = np.array([92, 186, 92], dtype=np.uint8) # green - right paddle | |
| _OPPONENT_COLOR = np.array([213, 130, 74], dtype=np.uint8) # orange - left paddle | |
| _BALL_COLOR = np.array([236, 236, 236], dtype=np.uint8) # white - ball | |
| # Frame regions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Q-Learning GridWorld</title> | |
| <style> | |
| * { box-sizing: border-box; margin: 0; padding: 0; } | |
| body { | |
| font-family: 'Segoe UI', Arial, sans-serif; | |
| background: #12192b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| random_policy.py β Random policy and rollout utility for the Crawler | |
| ======================================================================= | |
| Classes | |
| ------- | |
| RandomPolicy β uniform random policy; .act() and .learn() interface | |
| Functions | |
| --------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ | |
| crawler_env.py β 2D Crawler RL Environment (Gymnasium-compatible) | |
| ===================================================================== | |
| Robot description | |
| ----------------- | |
| Body : rectangle, slides left/right on the floor (no tipping). | |
| Arm : L-shaped, two rigid segments attached at the front-top of the body. | |
| segment-1 longer, ~horizontal angle ΞΈ1 from horizontal [β30Β°, +30Β°] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from mlagents_envs.environment import UnityEnvironment | |
| from mlagents_envs.envs.unity_gym_env import UnityToGymWrapper | |
| from mlagents_envs.side_channel.engine_configuration_channel import EngineConfigurationChannel | |
| engine_channel = EngineConfigurationChannel() | |
| unity_env = UnityEnvironment( | |
| file_name=r"Simple/Assignment2", # use the path to your built game here | |
| side_channels=[engine_channel], | |
| no_graphics=False, # set to True to disable rendering, which can speed up training |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| import torch.nn as nn | |
| import torch.optim as optim | |
| from torch.distributions import Categorical | |
| import numpy as np | |
| from mlagents_envs.environment import UnityEnvironment | |
| from mlagents_envs.envs.unity_gym_env import UnityToGymWrapper | |
| # ββ Policy network ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| class Policy(nn.Module): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| from time import time | |
| from sklearn.neighbors import KNeighborsClassifier | |
| import numpy as np | |
| from mlagents_envs.environment import UnityEnvironment | |
| from mlagents_envs.envs.unity_gym_env import UnityToGymWrapper | |
| unity_env = UnityEnvironment("gg_det") | |
| env = UnityToGymWrapper(unity_env) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <body> | |
| <div> | |
| <span style="float: left"> | |
| <canvas id="myCanvas" width="800" height="800" | |
| style="border:1px solid #d3d3d3;"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # play_gridworld_terminal.py | |
| # Terminal-playable GridWorld + trajectory tracking (only dependency: numpy) | |
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| from typing import Dict, List, Optional, Tuple | |
| import numpy as np | |
| @dataclass(frozen=True) |
NewerOlder