MatchmakingEx is a powerful, extensible matchmaking system designed for Elixir applications. It offers a robust set of features including filter-based matching, two-way confirmation, and automatic re-queuing, ensuring seamless pairing of users based on customizable criteria while maintaining high performance and fault tolerance.
MatchmakingEx is a powerful and extensible matchmaking system designed for Elixir applications, leveraging OTP principles to deliver high performance and scalability. This project aims to efficiently match users based on compatible profiles or criteria, automating the process of forming pairs or groups according to customizable rules.
GenServers, Supervisors, and a Registry for fault tolerance and high performance.Integrating MatchmakingEx into an application requires setting up a supervision tree, starting player processes, and managing the matchmaking flow.
Players can search for matches with or without filters:
# Simple search with no filters
MatchmakingEx.Player.search("player-123")
# Search with filters
filters = %{rank: "gold", mode: "1v1"}
MatchmakingEx.Player.search("player-456", filters)
Upon finding a match, both players receive a message to confirm:
# Accept the match
MatchmakingEx.Player.accept("player-123")
# Or decline the match
MatchmakingEx.Player.decline("player-456")
If both players accept, the match is confirmed. If one player declines or a timeout occurs, the match is cancelled, and accepted players are re-queued.
The matchmaking process is represented in a state diagram, detailing how matches transition based on player responses, including scenarios for acceptances, declines, and timeouts.
This table illustrates the outcomes based on various combinations of player responses, facilitating clarity on how the system manages different scenarios:
| P1 | P2 | Status | P1 Cooldown | P2 Cooldown | P1 Back to Queue | P2 Back to Queue | Scenario |
|---|---|---|---|---|---|---|---|
| ✅ Accept | ✅ Accept | :confirmed | No | No | No | No | 1. Both Accept |
| ✅ Accept | ❌ Reject | :rejected | No | Yes | Yes | No | 2. P1 Accepts, P2 Rejects |
| ❌ Reject | ✅ Accept | :rejected | Yes | No | No | Yes | 3. P1 Rejects, P2 Accepts |
| ❌ Reject | ❌ Reject | :rejected | Yes | Yes | No | No | 4. Both Reject |
| ⏳ Timeout | ⏳ Timeout | :timeout | No | No | No | No | 5. Both Timeout |
| ✅ Accept | ⏳ Timeout | :timeout | No | No | Yes | No | 6. P1 Accepts, P2 Timeout |
| ⏳ Timeout | ✅ Accept | :timeout | No | No | No | Yes | 7. P1 Timeout, P2 Accepts |
| ❌ Reject | ⏳ Timeout | :rejected | Yes | No | No | No | 8. P1 Rejects, P2 Timeout |
| ⏳ Timeout | ❌ Reject | :rejected | No | Yes | No | No | 9. P1 Timeout, P2 Rejects |
For a practical demonstration, processes can be started within an interactive Elixir shell:
# 1. Start processes for two players
iex> MatchmakingEx.Player.start_link("aragorn")
{:ok, #PID<...>}
iex> MatchmakingEx.Player.start_link("gimli")
{:ok, #PID<...>}
# 2. Both search with compatible filters
iex> MatchmakingEx.Player.search("aragorn", %{quest: "fellowship"})
:ok
iex> MatchmakingEx.Player.search("gimli", %{quest: "fellowship"})
:ok
Console output will indicate readiness for confirmation, outlining the next steps for players to accept or decline.
No comments yet.
Sign in to be the first to comment.