Spielerando

Make a Multiplayer Game With AI: Plan It From Day One

Multiplayer cannot be sprinkled on later, so decide on day one which computer is in charge, and build two players in one room before anything else. If your idea works with turns, use turns, because real-time play over the internet is far harder.

Why is two players so much harder than one?

In a solo game there is one truth, and it lives on one computer. With two players there are two screens, and they have to agree even though messages between them take time to arrive.

Say your game has two friends rowing one boat through a canyon, one oar each. Anna pulls left at the same moment Ben pulls right. On Anna's screen the boat has already turned. On Ben's it has not. A moment later, one of those screens has to change its mind. Most of what is hard about multiplayer lives in that moment.

Game programmer Gabriel Gambetta describes the usual answer in his guide to this subject. One computer, a server, is the only authority on what happens. Players send what they want to do, and the server decides and reports back. He notes that delays of 100, 200 or even 500 milliseconds are not unusual, which is why this can feel sluggish in fast games.

His other rule is blunt: do not trust the player. A changed copy of your game can claim anything, such as full health or a new position. So health, score and position belong on the server.

Turns or real time?

This choice decides how big your project is. With turns, a half-second delay hardly matters, and the server only has to check each move and pass it on. With real time, every delay is felt on every key press, and your AI has to hide it with tricks that are hard to get right and hard for you to judge.

If your idea survives being turned into turns, choose turns. The rowing game could be real time, or each player could pick a stroke every three seconds. The second version is a far smaller job, and it might even be funnier.

What is the first thing to build?

Two dots in one room. Each player moves one, and both see both, using two browser windows on your own computer. That is the whole first goal, and it is already a real achievement.

Next, join by short code. Then decide what happens when someone leaves, because that will happen in every session: does the game pause, end, or wait a minute for them to come back? Only then move your game's rules onto the server. Try it with a phone on mobile data, not only on your home network.

Keep in mind that a server keeps running, and someone looks after it. Ask your AI what it needs and what that may cost before you commit. Never let secret keys sit inside the game itself, because players can read them.

What is the mistake that kills these projects?

"I'll add multiplayer later." A solo game assumes one truth and instant answers, and those assumptions are everywhere in its code. Adding a second player afterwards usually means starting again.

Paste this to your AI

I want a small online game for two players. Start with only this: two dots in one room, each moved by one player, joined by a short code.

First draw the session as a state machine in a Mermaid diagram: create room, waiting, second player joins, playing, one player drops, reconnect window, game over. Say what each player sees in each state, and what happens if both act at the same instant. Build from that.

One server decides what is true. Players send what they want to do, and you never trust a value a player sends. Tell me what hosting you need and what it may cost.

When you say two screens agree, show me what you did: which windows, which actions, and what each one displayed. If you could not run two at once, say you do not know.

Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP

How to check it worked

  • Open two windows side by side. Move in one. The other should follow.
  • Close one in the middle of a game. The other player should be told what is going on.
  • Press at the same moment. Both screens should end up showing the same thing.
  • Use a phone on mobile data. A home network hides most problems.
  • Add a delay. Ask your AI for half a second of fake delay. The game should stay playable.
  • Try to cheat. Ask your AI to send a fake move. The server should refuse it.

Sources

Last updated: 2026-11-02