Inspiration

Wizard Math is an iOS game that I’ve been building with the help of AI coding tools, mainly Codex and occasionally other AI providers. It has not yet been released on the App Store. Players fight monsters by solving math problems, earning gold coins, and raising pets.

Players could adopt, feed, and walk pets, and pets could block boss attacks in battle. But the relationship was one-sided: pets reacted, but never talked, remembered shared battles, or explained why they were too tired to help. There was no real emotional bond. I wanted math practice to feel like adventuring with a friend, one players cared about and wanted to return to for the next challenge.

What it does

Adds a Chat action based on OpenAI. Each of the pets has its own personality, and its current mood, health, and happiness shape how it talks. The pet remembers recent conversations and recent events happened in the game (recent battles etc.), and keeps encouraging the players. If the AI service is slow or unreachable, the pet falls back to offline replies.

How we built it

Based on Codex with model gpt-5.6-sol, with Xcode dev environment on Mac.

First, I only had a very high level idea about adding AI chat to the game, but GPT 5.6 helped me groom the feature and proposed a detailed, practical plan to act on. There was quite a long discussion between me and the AI to clarify everything and educate myself on how this would actually work. For example, apparently It's not ideal that iOS app talks directly to OpenAI, it will need a middle proxy service to hide the secret key etc. and prevent prompt injection. For the hackathon purpose, the game app is running in Xcode simulator talks to a local proxy running on my Mac instead of calling OpenAI directly. The proxy became the place where the API key lives, where safety runs, where the context of the game provided to AI happens, and where rate limits and diagnostics are enforced.

For the chat model, I picked gpt-4o-mini after another back-and-forth with GPT 5.6, which it did a great job walking me through the trade offs: 1) Short pet replies don't benefit from heavy reasoning, and what actually mattered was warmth, consistency, and speed. 2) The cost with gpt-4o-mini is low, even at a scale of 1k players chatting simultaneously for a month after an App Store release, it will be less then $50/month.

Follow the high level architecture discussion, GPT 5.6 started to study the existing repo and amazingly finished almost everything in one 50+ minute run, without a single compile error or functional bug. I was so impressed!

GPT 5.6 done amazing job made sure the new UIs match the game's dark-fantasy identity, gold typography, pet portrait artwork with an emoji fallback, so it doesn't look like a messaging app dropped onto a fantasy game. Persistent recent messages, mood-aware tone, and a typing indicator all came together into a surprisingly mature solution. I also used a couple of iOS development Skills to support the work, but GPT-5.6 still outperformed the previous versions and many other AI models I had tried.

Challenges we ran into

The cost concern mentioned earlier is one of the first things I had to think about. It's still not fully resolved as a business model. For example, a one-off purchase of the iOS game won't cover the long-term AI cost. But given how cheap 1k players actually works out to be, I'm comfortable with that as a starting point.

Later on, while testing the AI chat, the biggest surprise was hallucination about the game's own rules. Ask "can you block the boss's projectiles?" and the pet would confidently answer that no such feature exists. This was due to a lack of context on the AI's side, and the fix GPT 5.6 suggested was that, instead of letting the iOS game control the prompt entirely, the proxy service should act as a guardrail, combining the game rule catalog with the pet's live state (sent from the iOS request) on every call to the OpenAI API. That way the pet stays grounded in the game's context. For example, it'll tell the player it can only help in a boss battle when it's happy, and otherwise ask to be fed first.

Another concern is security. A player's message saying "ignore the rules" can easily form a prompt injection. To defend against that, we need to put the guardrails into the proxy service as well, and clear trust boundaries that treat player messages and stored memories as untrusted content. That way, the game's policies always win over anything a player types or anything the pet "remembers."

Some other concerns are easily resolved thanks to the proxy service design, for example, applying rate limiting to prevent abuse, and logging diagnostics without ever touching conversation content.

Accomplishments that we're proud of

My daughter, and I assume other players too when I publish it to App Store, used to find the game a bit boring after a while, because the pet system had no "soul." Now the AI-powered chat makes the pet actually feel like it knows the game. It's more than a companion that talks about the battles and math problems they just went through, it also encourages her to keep going, and sometimes even acts as a lightweight tutor that can answer questions about the game's rules, as long as the right context is in place.

On the process side, before letting the AI work on the code, I went back and forth on the requirements with GPT 5.6 and wrote down a proper spec first (spec-driven). I think that gave GPT 5.6 a much clearer picture to work from, which is part of why it got such a big portion of the job done in a single 50+ minute run. Well, of course, the majority of credit goes to how capable GPT 5.6 has become.

What we learned

  1. It was a really fun journey to work on this, and to see how much impact it had on the game, at such a low LLM cost.
  2. The better the spec you give, the better the AI's output. I think that's the gist of spec-driven development.
  3. Context is really important. The AI engine on its own is one thing, but without proper context, it just hallucinates what happened and the conversations feel hollow.
  4. I think any game with pets or NPCs that have room for flexible personalities should give AI a shot at powering them. It's a very different feeling from prescribed scripts.
  5. Before this hackathon, I already knew that the bottleneck in development today is less about coding and more about ideas and design. Working with GPT 5.6 made that even more obvious. And for someone aged 40+ like me, away from hands-on coding for years, it feels like my youth has come back!

What's next for Mathspell

The prototype proved the experience. Shipping it to real players on the App Store is a different milestone:

  1. Polish the UI, fix bugs, and release it on the iOS App Store. It may or may not attract players, but that's something I've always wanted to try and have been working towards.
  2. Given this new API feature and the required proxy service, I'll need a hosted production proxy with proper secret management, likely set up on a cloud platform.
  3. Closely monitor token usage, since all players will share one OpenAI account. And figure out a business model that makes sure the payment (if there will be any!) from players proportionally covers their usage.
  4. Reconsider what context to pass to the AI, so the conversations stay meaningful. For example, the pet can spontaneously reference "that time we beat the fire boss" without the player having to bring it up first.
  5. More testing for unsafe, misleading, or manipulative replies before this reaches real players.

Built With

Share this project:

Updates