A lightweight Gym-style environment suite for MoonBit.
git clone https://github.com/zhaoyuanjuns/MoonGridGym.git
cd MoonGridGym
moon check
moon test
moon run cmd/mainmoon add zhaoyuanjuns/moongridgymmoon check
moon test
moon run cmd/mainmoon fmt --check
moon info
moon check --deny-warn
moon test --deny-warnlet env = @moongridgym.new_grid_world(7)
let obs = env.reset()
println(env.summary())
println(obs.ascii)
let result = env.step(@moongridgym.Action::Right)
println(result.info)
println(result.observation.ascii)let rows = @moongridgym.benchmark(2026, 5)
let report = @moongridgym.benchmark_report(2026, 5)
let data = @moongridgym.collect_episode(
@moongridgym.ScenarioKind::RandomMaze,
2026,
@moongridgym.PolicyKind::ShortestPath,
512,
)
println(data.summary())
println(data.to_csv())pub struct ActionCheck {
action : String
legal : Bool
moves : Bool
reaches_goal : Bool
lands_in_hazard : Bool
reason : String
}pub struct ActionHistogram {
up : Int
down : Int
left : Int
right : Int
stay : Int
total : Int
}pub struct BenchmarkRow {
scenario : String
policy : String
episodes : Int
successes : Int
total_steps : Int
total_reward : Int
min_steps : Int
max_steps : Int
reachable : Int
planned_steps : Int
}pub struct BoundaryScore {
scenario : String
tested_actions : Int
blocked_actions : Int
hazard_actions : Int
goal_actions : Int
stable : Bool
}pub struct ContractResult {
name : String
passed : Bool
detail : String
}pub struct EncodedObservation {
width : Int
height : Int
agent_x : Int
agent_y : Int
goal_x : Int
goal_y : Int
step : Int
done : Bool
cells : Array[Int]
}pub struct EpisodeDataset {
scenario : String
seed : Int
transitions : Array[Transition]
total_reward : Int
success : Bool
}pub struct EpisodeScore {
scenario : String
policy : String
seed : Int
steps : Int
reward : Int
success : Bool
terminated : Bool
truncated : Bool
reachable : Int
planned_steps : Int
}pub struct EpisodeStats {
steps : Int
reward_sum : Int
terminated : Bool
truncated : Bool
final_render : String
info : String
}pub struct GridGym {
kind : ScenarioKind
initial_seed : Int
seed : Int
width : Int
height : Int
start_x : Int
start_y : Int
goal_x : Int
goal_y : Int
agent_x : Int
agent_y : Int
step_count : Int
step_limit : Int
done : Bool
board : Array[Int]
}pub struct Observation {
kind : String
ascii : String
agent_x : Int
agent_y : Int
step_count : Int
done : Bool
}pub struct PlanExecution {
found : Bool
planned_steps : Int
executed_steps : Int
reached_goal : Bool
reward : Int
exact : Bool
}pub struct PolicyComparison {
scenario : String
seed : Int
best_policy : String
best_reward : Int
planner_reward : Int
greedy_reward : Int
random_reward : Int
stay_reward : Int
planner_success : Bool
greedy_success : Bool
random_success : Bool
stay_success : Bool
}pub(all) enum PolicyKind {
ShortestPath
GreedyGoal
SeededRandom
Stay
}pub struct QualityScore {
scenarios : Int
valid_scenarios : Int
solvable_scenarios : Int
deterministic_scenarios : Int
total_reachable : Int
total_planned_steps : Int
passed : Bool
}pub struct ReplayComparison {
same_observation : Bool
same_reward : Bool
same_terminal_flags : Bool
compared_steps : Int
mismatch_count : Int
}pub(all) enum ScenarioKind {
GridWorld
CliffWalking
Maze
FrozenLakeLike
RandomMaze
EmptyRoom
FourRooms
}pub struct ScenarioMetadata {
kind : String
description : String
width : Int
height : Int
step_limit : Int
supports_stochasticity : Bool
recommended_use : String
}pub struct StepResult {
observation : Observation
reward : Int
terminated : Bool
truncated : Bool
info : String
}pub struct Transition {
scenario : String
seed : Int
index : Int
x : Int
y : Int
action : String
reward : Int
next_x : Int
next_y : Int
terminated : Bool
truncated : Bool
info : String
}pub struct ValidationReport {
scenario : String
valid : Bool
reachable : Int
planned_steps : Int
checks : Int
failures : Int
message : String
}fn action_roundtrip_count() -> Intfn boundary_report(seed : Int) -> Stringfn collect_episode(kind : ScenarioKind, seed : Int, policy : PolicyKind, max_steps : Int) -> EpisodeDatasetfn normalized_episode_count(episodes : Int) -> Intfn release_gate(seed : Int) -> Stringfn train_curve(kind : ScenarioKind, policy : PolicyKind, seed : Int, episodes : Int) -> TrainingCurveA lightweight Gym-style environment suite for MoonBit.