When you sit down to play a board game with friends, rule disputes often arise — is a move allowed, how many points for a combination? In a mobile version, there should be no such disputes: every move and every score is controlled by code. We take a board game and formalize its rules as a finite state machine, eliminating any ambiguity. Below I'll explain how we do this and what stack we use. Our mobile board game development services include implementing AI opponents and Firebase multiplayer.
A finite state machine is an abstract machine that can be in one of a finite number of states.
Wikipedia
Formalizing Rules
The first step is to write a complete specification of the rules as a State Machine. For a game like Monopoly or Ludo, that's dozens of states and transitions. We use the State pattern or the Stateless library (ported to Unity). Each transition includes guard conditions and actions. This guarantees: you cannot transition to an invalid state, all rules are explicitly coded, and testing is done via unit tests of states without running Unity.
Here's what the core logic looks like in Swift:
enum GameState { case waitingForPlayers case playerTurn(Player) case resolvingMove case gameOver(winner: Player?) } struct Game { var state: GameState mutating func apply(action: Action) -> Bool { switch (state, action) { case (.waitingForPlayers, .startGame): state = .playerTurn(.first) return true // ... remaining transitions default: return false } } } AI Opponent
For perfect-information games (chess, checkers, abstract strategy), we use Minimax with Alpha-Beta pruning. Search depth depends on the game's branching factor. On mobile devices, we limit search time: if the AI doesn't find a move within 500ms, we take the best found so far. For imperfect-information games (cards, hidden moves), we use Monte Carlo Tree Search (MCTS). MCTS doesn't require an evaluation function and models random factors. On an iPhone 14, MCTS with 10,000 iterations completes within 200ms.
Firebase Multiplayer Setup
For online mode, we use Firebase Realtime Database. The board state is stored as JSON, and client observers synchronize via the Transaction API for atomicity. We configure security rules so each player can only update their own data. Detailed documentation is available in the official Firebase guide.Choosing an AI Opponent
- Determine the type of information: if all state data is available to both players (checkers, Go) — use Minimax. If there's hidden information (cards in hand) — use MCTS.
- Estimate the average game depth: Minimax is efficient with a small branching factor (up to 30-40 moves). For large branching factors, MCTS is better.
- Test performance on target devices: try both methods and choose the best accuracy-to-speed ratio. For example, on an iPhone 14, Minimax can achieve 6-ply depth within 500ms, while MCTS runs 10,000 iterations in 200ms.
Get a consultation on your project — we'll assess complexity and propose the optimal solution.
Why MCTS Is Better Than Minimax for Imperfect-Information Games
MCTS models random factors without a priori knowledge, whereas Minimax requires a complete evaluation function. For card games, MCTS is 3× more accurate in move selection because it accounts for card draw probabilities.
Multiplayer: Local Pass-and-Play
The simplest and most underrated mode: one phone, multiple players taking turns. Implementation is trivial, but the conversion to organic sharing is high. Add a "pass the phone" screen with a flip animation — and local multiplayer is ready.
For online mode in board games, Firebase Realtime Database is optimal: the board state as a JSON object, observers on both clients. The Transaction API guarantees atomic updates — no race conditions during simultaneous moves.
Comparison of AI Methods
| Method | Information Completeness | Performance | Applicability |
|---|---|---|---|
| Minimax | Perfect | 4-8 ply depth in 500ms | Chess, checkers |
| MCTS | Imperfect | 10,000 iterations in 200ms | Cards, hidden moves |
Work Process
| Phase | Description | Estimated Time |
|---|---|---|
| Analysis | Rule specification, state definition | 1-2 weeks |
| Design | Architecture, stack selection | 1 week |
| Implementation | Coding, AI, multiplayer | 2-6 months |
| Testing | Unit tests, beta testing | 2-4 weeks |
| Deployment | Publishing to App Store and Google Play | 1-2 weeks |
Timelines: a classic board game without AI — 2–4 months; with AI and online multiplayer — 4–7 months. Development cost typically ranges from $5,000 to $20,000 depending on features.
What's Included
- Source code with comments and documentation.
- Build and publishing configurations (code signing, provisioning profiles).
- Firebase setup, analytics integration.
- Assistance with app store review.
We have been specializing in mobile development for over 5 years and have completed 20+ game projects. We guarantee quality and on-time delivery. Contact us to assess your project — order turnkey mobile board game development, and we will propose the optimal solution.
Learn more about State Machine on Wikipedia and about MCTS on Wikipedia.







