Skip to content

Instantly share code, notes, and snippets.

View evanthebouncy's full-sized avatar
πŸ’―
ζ―δΊΊιƒ½ε‘ε°ηΊ’θŠ±

evanthebouncy

πŸ’―
ζ―δΊΊιƒ½ε‘ε°ηΊ’θŠ±
View GitHub Profile
@evanthebouncy
evanthebouncy / random_agent.py
Created April 24, 2026 15:09
the random agent that plays the game
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
@evanthebouncy
evanthebouncy / pong_features.py
Created April 24, 2026 15:08
state extraction for pong
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
@evanthebouncy
evanthebouncy / qlearning.html
Last active April 22, 2026 07:57
q-learning html
<!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;
@evanthebouncy
evanthebouncy / random_policy.py
Last active April 18, 2026 01:56
random policy
"""
random_policy.py – Random policy and rollout utility for the Crawler
=======================================================================
Classes
-------
RandomPolicy – uniform random policy; .act() and .learn() interface
Functions
---------
@evanthebouncy
evanthebouncy / crawler_env.py
Created April 17, 2026 15:19
crawler environment
#!/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Β°]
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
@evanthebouncy
evanthebouncy / reinforce.py
Last active March 15, 2026 05:16
reinforce_game+AI
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):
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)
<!DOCTYPE html>
<html>
<body>
<div>
<span style="float: left">
<canvas id="myCanvas" width="800" height="800"
style="border:1px solid #d3d3d3;">
@evanthebouncy
evanthebouncy / grid_manual.py
Created January 23, 2026 15:09
manually play the grid game
# 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)