Online Multiplayer game match making

the users who click on the play button, the username of that particular user is added to list in the firebase in the WaitingUsers tag. and if the tag has at least two users or more then how do i match them randomly? here my user name is Smith
Capture


this is what i have done. then what do i do to make random matches? considering huge number of users.

How many users does a single game include?

That should be the cap on your list length, give or take a user.

Since users try to join games randomly, just check if there are enough on the waiting list to fill out a game.

Then remove them from the front of the list.

If there aren't enough to fill out a game, add this user to the waiting list at the end.

Two players needed for this game.

How do i do it?
i m not getting the logic that when players click on play btn they added to waitingusers list. And if there at least two users then they get the match. If there are more than two users(say 100) then how they get match?

This requires thought and research.

It's a multiuser locking problem.

Try searching for Multiplayer Matching Algorithms.

It must be a standard Computer Science topic somewhere.

This is possibly a use for firebase arrays

Store all users in an array, and create a second project bucket that contains matched pairs / users selected so far. in the app, select your array number and a random array number not in the list of matched pairs. When this is done, add the new matched pair to the matches project bucket. When game over, remove from matches list.

pls sir help me with blocks.. i am trying trying from yesterday but not getting the proper block. so i used another method that is using collintree list view. the users who are online will show in the listview then after element click i have done this.( i have used two collintree listview) pls check it out and give some ideas and sir pls suugest some blocks that are u said before


What is Create_Order?

I have used this so that the two users must go to same project bucket

please sir help me. how do i match two players to play the game?

This may help you but this is a paid project made with Kodular.

i asked ChatGpt to help me to match players from a list in firebasae. he is the result i got

If you want the randomly chosen player to be matched with the current player, you can modify the code to remove both the current player and the chosen player from the list. Then, display the matched players' names accordingly. Here's an updated version of the code:

blocks

// Assuming "onlinePlayersList" contains the list of online players ["Player 1", "Player 2", "Player 3", "Player 4"]
var currentPlayer = "Player 1"; // Replace with the name of the current player

// Remove the current player from the list
var modifiedPlayerList = onlinePlayersList.filter(function(player) {
  return player !== currentPlayer;
});

if (modifiedPlayerList.length >= 1) {
  var randomIndex = Math.floor(Math.random() * modifiedPlayerList.length);
  var matchedPlayer = modifiedPlayerList[randomIndex];

  // Remove the matched player from the list
  modifiedPlayerList.splice(randomIndex, 1);

  // Remove the current player from the list
  modifiedPlayerList = modifiedPlayerList.filter(function(player) {
    return player !== matchedPlayer;
  });

  // Display the matched players' names
  var resultElement = document.createElement("p");
  resultElement.innerHTML = "Matched players: " + currentPlayer + " and " + matchedPlayer;
  document.body.appendChild(resultElement);
}

how do i implement this block ? i m confused, need help