Skip to content

Instantly share code, notes, and snippets.

View evanthebouncy's full-sized avatar
💯
每人都发小红花

evanthebouncy

💯
每人都发小红花
View GitHub Profile
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)
@evanthebouncy
evanthebouncy / resolution_lower.py
Created January 18, 2026 08:24
resolution lower bound
import numpy as np
# generate a random number between 0 and 1
# calculate its distance (min) to either 0 and 1 (absolute value of difference)
def do_once():
x = np.random.rand()
return min(abs(x - 0), abs(x - 1))
# do it many times and get the average value
def do_many_times(n):
@evanthebouncy
evanthebouncy / kruskal.py
Created September 21, 2025 15:27
kruskal
E = {
"A": [("B", 4), ("H", 8)],
"B": [("A", 4), ("C", 8), ("H", 11)],
"C": [("B", 8), ("D", 7), ("F", 4), ("I", 2)],
"D": [("C", 7), ("E", 9), ("F", 14)],
"E": [("D", 9), ("F", 10)],
"F": [("C", 4), ("D", 14), ("E", 10), ("G", 2)],
"G": [("F", 2), ("H", 1), ("I", 6)],
"H": [("A", 8), ("B", 11), ("G", 1), ("I", 7)],
"I": [("C", 2), ("G", 6), ("H", 7)],
@evanthebouncy
evanthebouncy / q14.py
Created September 13, 2025 16:57
q14
E = {
"A": [],
"B": ["A", "E"],
"C": ["D", "H"],
"D": ["B"],
"E": ["F"],
"F": [],
"G": ["A"],
"H": ["B", "G"],
}
@evanthebouncy
evanthebouncy / q13.py
Created September 13, 2025 14:32
q13
E = {
"A": [],
"B": ["A", "E"],
"C": ["D", "H"],
"D": ["B"],
"E": ["F"],
"F": [],
"G": ["A"],
"H": ["B", "G"],
}
@evanthebouncy
evanthebouncy / toposort.py
Created September 7, 2025 16:30
topological sort
E = { "A": ["E"],
"B": ["A", "C", "G"],
"C": ["A"],
"D": ["B", "G"],
"E": ["F"],
"F": [],
"G": ["A", "F"],
}