If we suppose a online dual player game.
There is a table in a database (Users table) with columns id, name, level, ...
When a user click a button it has to search for another user(who also clicked the button to search) with similar level and connect those users and start the game.
What I want is the algorithm to connect two players who are searching for a one when clicked a button.
It is easy if any can give a php code.
Let me give you an idea. Share your thought if you find anything not fitting your request.
Player's table: **id name level status** 1 1 1 idle 2 2 3 playing 3 3 1 idle 4 4 3 playing 5 5 1 idle
step 1: only idle player can search for player. say player:1 pressed search button. then player:1's status will be searching. but it won't find anything as no body else is in search state and of the same state (searching).
send asynchronous request from the client that will periodically look for player via a php get/post request.
repeat this for any player who pressed search.
game table: **id playerOneId playerTwoId pLayerOneStatus pLayerTwoStatus status** 1 1 5 ready ready started
step-3: the moment asynchronous request get game id as response it will redirect the player to game page. and set the player status to ready.
step-4: the moment both player are in ready state. the game will be started.
step-5: once the game end change player's table status to idle. change game status to end
Let me know if it serves your question.