I’m making a turn based game, and trying to construct the matching function, when a player chooses to play with a random opponent. I’m a noob when it comes to mysql so I need some help.
I was thinking about doing this:
-
When a player chooses to play against a random opponent, check the “waiting_list” table to see if there’s any opponents there.
-
If there isn’t any opponent, add the player to the waiting list.
-
It there is an opponent on the waiting list, remove the player from the list, and start the game with the other player.
My concern is, if I do it like this, is there any chance the same player on the waiting list, will be choosen by several players. Imagine if there is 100,000 player choosing the auto match feature, will the database (phpmyadmin) be able to handle it fine? How would you construct the logic?
Thanks
To help prevent a single player from getting pulled into multiple games, you could do the waiting list with an additional column (if not there already) for the “GameIDAssigned”, defaulting to 0 (or even PlayAgainstPerson ).
At the time of querying the data available for and displayed to many players, the records may all have similar timestamps, but you only want 1. So, pick one at some random method, then assign the ID where it equals the timestamp and no game assigned. If it comes back that 1 record was updated, its yours. If it was assigned to someone else, the GameIDAssigned will have been filled in, thus preventing you from getting it assigned a second time. Such as…
Without seeing any other elements of how your game is structured, or columns of tables, not much more I can offer at this time, but hopefully enough for you to get the idea. If one waiting list person is ATTEMPTED to be assigned by multiple people at the same time, only the first one who gets the updated done (while the gameIDAssigned still = 0) wins and everyone else trying to get that person will miss and need to try the next available…