Question:
There is a game mode with 2 and 3 players.
Selects the game mode (2x,3x) and presses search for a game.
I use websocket for communication.
What algorithm is needed for the optimal operation of the search for opponents. (On the example of the game sea battle 2)
How to correctly implement the logic of this functionality?
Answer:
Each player must be assigned a unique id. When entering the game, you must establish a connection with the server and register each new player as a free player, saving them to the list of such players. Availability confirmation must be obtained periodically from each free player. Having picked up a couple or three participants, each player needs to display information about the connection. If one of them does not answer, then it is necessary to replace this participant. After the end of the game, the participants are again placed in the list of available ones.
When selecting rivals, you can take into account the track record and (or) geography, interests, etc. This information can be saved for each player in the game. You can make it possible to set a filter when searching for rivals. Then, for choosing a stronger player, you can give additional points.