DEV Community

Aniket Kale
Aniket Kale

Posted on

I Built an AI Puzzle RPG That Talks to You in Any Language | Lingo.dev Hackathon 

I am a DevOps Engineer, who likes building random stuff, using AI. 
In past one month I have been building this one tool for the social media creators.
And I was thinking about adding one more feature to this app. In this feature user would paste any video link, and the
captions will be generated for that video. 

But you could image that,
How I even ended up building a game at this hackathon?

See, while scrolling on X, I found this hackathon by Lingo.dev. Found out that their translation feature can be used to translate the captions of youtube videos in any language. And so I participated in this hackathon. 

Scrapping the first idea….
And surely creators around the world would have found it useful if they can get the youtube video transcript in their native language very easily.

But then I sat over this idea, I realized that there are many such tools available in the market. This would have been no different.

How the game idea took shape…
So I was confused what idea to go with, so then I found this one person criticizing some puzzle game on X. Then it clicked for me , that I could build a puzzle game. But I did not want to create any other random game.
As a history nerd myself, I thought about creating a puzzle Game with some historical characters in it. And then I could use lingo.dev’s translations tools to make this game playable in multiple languages. 

Initially it sounded good. I had thought I would add games like Tetris and wordle to it.

But I had never built roleplaying games. After creating the basic UI of the game, it hit me that no one would play basic Tetris and Wordle on my site. So better I should include puzzle games that are really good and rarely played, so that I would be the one kind-of introducing it to the people.

So then after thorough research I included games like : 

1. Pattern Memory— A set of tiles briefly glow in a pattern; remember and select exactly which ones lit up.

  1. N-Queens Problem — Place kings on a grid so no two kings share the same row, column, or diagonal.

  2. Arithmetic Sprint — Solve as math equations as possible before the timer runs out.

  3. Sudoku — Fill a grid so every row, column, and box contains the grid digits exactly once.

  4. Hashiwokakero (Island Bridges) — Connect numbered islands with bridges so each island’s bridge count matches its number and all islands form one connected group.

I built the story around the game like, our main character will go on a journey to lay the foundation of fallen Nalanda university around 1203 AD. He will travel around the world, visit renowned monks, solve puzzles and collect the manuscripts to bring back home.
So I added other things in game like 5 characters in 5 kingdoms, created their character stripes. Added knowledge chest for storing manuscript.

Kingdoms

Adding translations and the aha moment…
After this, to start integration of lingo’s translation tool, I did not know which one to choose. Also I had never built such projects earlier, So I thought lets start with basic one i.e. Lingo.dev Compiler tool.

So I added the language selection dropdown with 9 language. And integrated the lingo.dev’s compiler tool that translated all the pages during build time. 
Why I selected only 9 languages I will tell in the end.

Even after this, it felt unfinished. There was this feeling that there should be more to this than just a translatable puzzle game.
Also, while creating/researching about these monks earlier characters
I thought it would have been great if I was alive during that time and could have interacted with those monks. 

That’s when it clicked me what if I could create an AI based chatbox that will impersonate these monks from 1203 AD, and the player could interact with them, play puzzles and gain some historical knowledge as well.

On top of that I could use lingo’s translation tools, so that I could interact with these characters in realtime in any language.
So thats when I added the chatting feature with these characters, and integrated lingo.dev’s SDK a runtime translation tool.
Now after adding, this feature it was like a aha moment for me.

One thing I want to mention here is how the difficulty works in this game. When player talk to the scholar character before playing the puzzle, the AI reads player’s tone and attitude. If you are humble and genuine, the scholar gives you an easy puzzle. If you are rude or dismissive, you get the hardest one. I thought this was more interesting than just asking the player to pick easy, medium or hard. The monk characters rewards humility and punishes arrogance.

Now, How the architecture actually works…
The entire app is built with Next.js using the App Router, React, TypeScript and Tailwind CSS. There is no backend, no database, no user accounts. Game progress lives in localStorage. This was a conscious choice and I will explain why in a minute.

The AI scholar chat works through Google Gemini, but I call it from a Next.js API route rather than directly from the browser. This way the API key never gets exposed to the client. When a user hits the route, the route calls Gemini, Gemini responds, and then I pass it through the Lingo.dev Runtime SDK to translate it into whatever language the player currently has selected/chatted. 

So the whole flow is this : player types a message → message goes to the API route → API route sends it to Gemini → Gemini replies in English → Lingo.dev translates the reply into the player’s chosen language → translated reply goes back to the browser. All of that happens in one round trip from the player’s perspective.

AI Engine Flow

For the static content, all the UI text, button labels, game instructions, kingdom names, the stuff that does not change, I have used the Lingo.dev Compiler, which runs at build time and bakes the translations into the bundle. 

It's configured in the next.config.ts and point it at the source locale and it generates everything for all target languages automatically. The translated strings cost nothing at runtime because they are already there.

Compiler Flow

I am supporting 8 languages other than English: German, French, Spanish, Japanese, Hindi, Traditional Chinese, Korean, and Russian.
Now initially I wanted to use as many languages as I can but, then it was failing at the build time due to timeout error, so that’s why I only selected 8 languages.

Why I made some choices that might look weird…
No backend and no database is probably the most unusual decision I made and I want to explain it. The hackathon was 3–4 days. Adding a backend meant adding authentication, a database schema, hosting, environment variables in two places, and a whole category of issues that have nothing to do with the actual product. For a hackathon build with single person and 6–7 days, that trade-off was obvious to me. 

*The bug that made me want to close my laptop and go to bed…
*

Islands game

Level 3 of the Island Bridges puzzle was just not working at all. For context, this puzzle type is called Hashiwokakero. Player have to connect numbered islands with bridges, each island’s number tells player to exactly how many bridges must connect to it, and all islands must form one connected network in the end.

Levels 1 and 2 were generating fine. But every time I tested Level 3, the grid was just empty i.e no number for Islands.
No error was being thrown anywhere, so I had no idea where to even start. I added logs everywhere and eventually found out the generator was running 300 attempts and throwing all of them away.

Turns out I had added a constraint called minOddIslands = 3. My idea was that having at least 3 islands with an odd bridge count would stop players from just doubling every bridge and may add more difficulty to the puzzle.

Except it was mathematically impossible. I found out that In any graph, the number of vertices with an odd degree has to be even. I did not know this. So I had set a constraint to 3, which is an odd number, and no puzzle in the universe could ever satisfy it. The generator tried 300 times and failed 300 times because I was asking it to do something that cannot exist.

Once I understood this, the fix was to stop rejecting puzzles and instead fix them after generation.Somewhat like a backtracking algorithm. I remember creating Sudoku game back in my college where I had built backtracking algorithm myself. So fix was If the odd island count was too low, I would find double bridges and downgrade them to single bridges, which changes the degree of both connected islands. I also changed minOddIslands from 3 to 2. AI helped me figure this out faster than I would have on my own.

After both fixes, Level 3 worked perfectly.
That was the most fun I had being frustrated with something in a long time.

What is broken/unfinished or future scope for this project…

The scholar system prompts are good but not as deep as they could be. Each scholar has historical context baked in but there is so much more I could have added more specific texts they are known for, historical events they witnessed. Right now if you ask them on some historical details they sometimes give some answer but not accurate answers.
The manuscript excerpts in the Knowledge Chest are English only. As I said earlier, translating dense historical data across multiple languages was giving timeout error during build time.

The future scope for this game could be, live players anywhere in the world competing on the same puzzle in real time. That could be genuinely the coolest feature in the project. The foundation is there for it but I ran out of time.

How to try it and how to build on it…

Live Game Link: https://questworldlingo.vercel.app/


It’s totally free.
So I would urge you to pick a kingdom, talk to the scholar, try to be rude to them and see what happens.

Demo Link: https://youtu.be/4TqJK-Olef0

Repo Link: https://github.com/Aniket-d-d/questworldlingo


Fork it. Build something interesting. Other details are in the readme.md file. 

If you were to add one more kingdom to this game, which one would you pick and why?

Also, Let me know what you people feel about this game.
And, Thank you.

Top comments (0)