3D Minesweeper: Because P2P State Shouldn't Be a Mess 💥
Welcome, fellow explorer! This isn't just a 3D Minesweeper game; it's a testament to the architectural imperative of a peer-to-peer game loop. We've taken the core of our FSM_API, the concept that state shouldn't be a mess, and applied it to a multiplayer, 3D environment using a new FSM_Helix package.
This project is a foundational stepping stone for building future complex, 3D applications and game prototypes. It showcases a sophisticated architecture that can scale to high player numbers by dynamically expanding the game board and delegating authority to a round-robin system.
Our solution re-imagines the game's control flow using our FSM_API to manage a decentralized peer-to-peer system. Each client can exist in one of four distinct application states:
Disconnected: The initial state when a player enters a new match name or first launches the app.Client: The player is connected to a match and receives updates, but they do not have network authority for the current frame.Client-RoundRobinAuthoritative: The player's client is the arbiter of all updates for the current frame. They process local actions and broadcast the authoritative state to the group.Authoritative: This state is an abstraction of theClient-RoundRobinAuthoritativestate, representing the current authority.
This round-robin system ensures a distributed, fault-tolerant game loop, while the FSM_API guarantees that each client remains in a predictable, consistent state.
When a player launches the app, a simple, collapsible UI appears, allowing them to enter a name, a match name, and a player color (which is randomly assigned if not set).
The game's primary flow is managed by an FSM that follows player actions:
- A user starts the app and is immediately put into the
Disconnectedstate. - The system tries to find or create a game with the name "Default." If found, the client joins and transitions to the
Clientstate. If no match is found, the client creates one and transitions to theClient-RoundRobinAuthoritativestate. - If a user changes the match name in the UI, their client broadcasts a disconnect message to the current group and re-enters the
Disconnectedstate, seeking a new match.
stateDiagram-v2
direction LR
Disconnected --> Client : MatchFound
Disconnected --> ClientRoundRobinAuthoritative : MatchCreated
ClientRoundRobinAuthoritative --> Disconnected : MatchNameChange
Client --> Disconnected : MatchNameChange
| Current State | Event/Trigger | Next State | Action |
|---|---|---|---|
| Disconnected | MatchFound(MatchName) |
Client | Joins the match, syncs board state, and awaits the next authoritative frame. |
| Disconnected | NoMatchFound(MatchName) |
Client-RoundRobinAuthoritative | Creates a new match, sets the initial board size, and becomes the first authoritative client. |
| Client | MatchNameChanged(NewName) |
Disconnected | Sends a disconnect broadcast, asyncs search for a new match, and enters a disconnected state. |
| Client-RoundRobinAuthoritative | MatchNameChanged(NewName) |
Disconnected | Sends a disconnect broadcast, asyncs search for a new match, and enters a disconnected state. |
Game actions, such as revealing a tile or placing a flag, are an integral part of this FSM-driven peer-to-peer loop.
- A player initiates an action on a cell they are "standing" on.
- Their client sends this action to the current
Authoritativeclient. - The
Authoritativeclient processes the request and then broadcasts the new game state to all otherClients in the match. - The
Authoritativeclient then passes authority to the next client in the round-robin queue, transitioning that client to theClient-RoundRobinAuthoritativestate.
sequenceDiagram
participant P1 as Player A (Client)
participant P2 as Player B (Authoritative)
participant Pn as Player N (Client)
P1->>P2: Player A's action (e.g., reveal tile)
P2-->>P1: Acknowledgment
P2-->>Pn: Broadcast new game state
P2->>Pn: Hand over authority
Pn-->>P2: Acknowledgment
loop every round
Note over Pn: Pn is now the authoritative client
Pn->>P1: Broadcast new game state
Pn->>P2: Broadcast new game state
Pn->>...: Broadcast new game state
end
The Singularity Workshop - Tools for the curious, the bold, and the systemically inclined.
Because state shouldn't be a mess.
-
API NuGet Package: https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API
-
FSM_API Repository: https://github.com/TrentBest/FSM_API
-
💖 Support the Project: Donate via PayPal