Improve client matchmaking flow with ticket handling, auto-join, and mode distribution

### PlayerWebSocketHandler updates
- Track `ticket` and `match_id` per player instance
- Handle `matchmaker_ticket` messages and store ticket
- Handle `matchmaker_matched` and automatically join created match
- Enhance matchmaking debug output
- Update join_matchmaking() to include mode-based string_properties + query

### Matchmaking simulation improvements
- Evenly distribute players between "classic" and "blitz" modes
- Randomize assignment order to simulate real queue behavior
- Log player→mode mapping for visibility during tests

Example:
  player_0 -> classic
  player_3 -> blitz
  player_5 -> classic

Client test harness now accurately reflects multi-mode matchmaking behavior.
This commit is contained in:
2025-11-26 17:11:20 +05:30
parent eb35ccd180
commit 10058710fb
2 changed files with 33 additions and 8 deletions

View File

@@ -1,8 +1,9 @@
import asyncio
from game_flow import PlayerWebSocketHandler
import random
from game_flow import PlayerWebSocketHandler, TEST_SCENARIOS
async def simulate_matchmaking(num_players: int = 6, mode: str = "classic"):
async def simulate_matchmaking(num_players: int = 6):
print(f"\n🎮 Spawning {num_players} players...\n")
# 1) Login + WebSocket connect
@@ -21,12 +22,20 @@ async def simulate_matchmaking(num_players: int = 6, mode: str = "classic"):
await asyncio.sleep(0.3)
# 3) Queue all players in matchmaking
print(f"\n🎯 Queuing players for mode={mode}...\n")
# 3) Split evenly between classic & blitz
half = num_players // 2
assignments = ["classic"] * half + ["blitz"] * (num_players - half)
# Optional — shuffle for realism
random.shuffle(assignments)
print("\n🎯 Queuing players:")
for p, mode in zip(players, assignments):
print(f" - {p.label} -> {mode}")
await asyncio.gather(*[
p.join_matchmaking(mode)
for p in players
for p, mode in zip(players, assignments)
])
print("\n✅ All players queued — waiting for matches...\n")