DEV Community

Causal Zap
Causal Zap

Posted on

I Reverse-Engineered a Game's RNG to Build a Strategy Engine with Astro & React

The Problem: "90% Success Chance" is a Lie
If you've played Mewgenics (the upcoming RPG by Edmund McMillen), you know the pain. You see a "90% success chance," you click the button, and... FAILURE. You lose your best cat, your run ends, and you rage-quit.

I got tired of guessing. I wanted to know why the math felt off.

So, I decided to dig into the game files. I didn't just want a wiki; I wanted a Decision Engine. I wanted a tool that takes the raw data and calculates the exact probability of success based on my character's stats.

Here is how I built MewGenius using Astro, React, and a bit of Python for data engineering.

🕵️‍♂️ Phase 1: The Reverse Engineering
The first step wasn't coding; it was data mining. I analyzed the raw game files (classes+Misc.txt and events.csv) and discovered a hidden mechanic that the UI doesn't tell you: The Reroll System.

It turns out, the "Luck" stat isn't linear.

Luck 5: Base roll (1 attempt).

Luck 15: The game rolls twice and takes the best result.

Luck 25: 3 rolls.

This "Rule of 5s" meant that a simple percentage display on a wiki was useless. I needed a calculator that could simulate these rerolls.

🛠️ Phase 2: The Tech Stack
I needed a framework that was fast, SEO-friendly (for thousands of game events), but capable of complex interactivity for the calculators.

My Choice: Astro + React

Astro (SSG): Perfect for the "Cluster Pages." I have hundreds of pages for specific Bosses and Events. Astro generates these as static HTML at build time. Zero JS bloat for the content.

React Islands: For the Luck Calculator and Breeding Simulator, I needed complex state management. I used React components hydrated with client:load only where necessary.

Python: For the ETL (Extract, Transform, Load) pipeline.

🧩 Phase 3: The Architecture

  1. The Data Pipeline (Python) The raw game data is messy CSVs and unstructured text. I wrote Python scripts to clean and structure this into typed JSON.

Python

A simplified snippet of my ETL script

import json
import pandas as pd

def process_events():
df = pd.read_csv('raw_events.csv')
events = []

for index, row in df.iterrows():
    # Parsing the hidden stat checks
    choices = parse_choices(row['options'])
    events.append({
        "id": row['id'],
        "name": row['name'],
        "choices": choices # Contains hidden stat requirements
    })

with open('src/data/events.json', 'w') as f:
    json.dump(events, f)
Enter fullscreen mode Exit fullscreen mode
  1. The Calculation Logic (TypeScript) This is where the magic happens. I translated the reverse-engineered formulas into a TypeScript utility that powers the React frontend.

TypeScript
function effectiveProbability(baseProb: number, luck: number) {
// Logic: Luck < 5 applies a penalty
if (luck < 5) {
const penalty = Math.max(0, 1 - 0.1 * (5 - luck));
return baseProb * penalty;
}

// Logic: Luck >= 15 gives extra "virtual" rolls
const rolls = 1 + Math.floor((luck - 5) / 10);

// The probability of failing ALL rolls
const failProb = Math.pow(1 - baseProb, rolls);

return 1 - failProb;
}

  1. The "Hybrid" UI I used Astro to render the static event details for SEO, and then embedded the React calculator right inside the page.

Code snippet

// EventPage.astro
import LuckCalculator from '@/components/LuckCalculator';

import { eventData } from '@/data/events';

{eventData.name}

{eventData.description}


🚀 The Result: MewGenius.com
The result is a blazing fast static site that feels like a native app.

Luck Calculator: You can slide your Luck stat and watch the "Real Success Rate" update in real-time.

Breeding Sim: Simulates genetic inheritance risks (like Dominant traits) before you ruin your run.

Boss Guides: Tactical data parsed from game files.

🧠 Lessons Learned
SSG is King for Gaming DBs: Generating 500+ event pages statically means instant load times and great SEO.

Type Safety Matters: Using TypeScript interfaces for the game data saved me from countless bugs when the CSV structure changed.

Tools > Wikis: Players don't just want to read data; they want to use it to make decisions.

If you are a fan of Mewgenics or just like seeing how game mechanics are deconstructed into code, check it out at MewGenius.com.

Let me know what you think of the UX! I'm still actively adding features (Class DB is next).

Happy coding (and breeding)! 🐱

Top comments (0)