Hack Forums
[.NET] Trying to solve this Matchmaking Problem. - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Trying to solve this Matchmaking Problem. (/showthread.php?tid=5601304)



Trying to solve this Matchmaking Problem. - iNCEPTiON_V - Apr 16, 2017

EDIT Sorry wrong Forum!

Hello,

im currently trying to wrap my head around this interesting Problem.
So what im trying to implement here, is a basic matchmaking system for my Quiz mobile App ( Server Side ).

Background

For this task im using a ASP.NET Core App with Web Sockets for the Connections.

1. First i would Register the User in a Collection.
2. Find an Opponent Player.
3. Add those Players in a Match Collection ?

Implementation / Logic

1. Register User

Code
// Usercollection just stores the Socket and the Username
// very basic.

public static bool RegisterUser(GameSessionModel player) {
            if(!UsersOnlineCollection.Contains(player)) {
                UsersOnlineCollection.Add(player);
                return true;
            }
            return false;
        }

2. Find Oponent

Code
public static GameSessionModel FindOponent(GameSessionModel player) {
            return UsersOnlineCollection.OrderBy(x => Guid.NewGuid())
                    .FirstOrDefault(x => x.Username != player.Username && x.IsAvailable);
        }

3. Store / Create Session with found Players

Now this is where im struggling so far....
How should i store them so i can continue to work with them in the Game.

What im thinking of is , store them in a Dictionary like this ?

Code
// string is the Guid
// concurrentdictionary is a thread safe dictionary

public static ConcurrentDictionary<string, MatchModel> MatchSessions { get; set; }

public static void CreateSession(GameSessionModel playerOne, GameSessionModel playerTwo) {
            if (!MatchSessions.ContainsKey(playerOne.MatchGuid)
                && !MatchSessions.ContainsKey(playerTwo.MatchGuid)) {

                if (playerOne.MatchGuid == playerTwo.MatchGuid) {

                    MatchSessions.TryAdd(playerOne.MatchGuid, new MatchModel {
                        PlayerOne = playerOne, PlayerTwo = playerTwo
                    });
                }
                else {
                    ????
                 }


            }

        }

Would this go in the right direction? Or is there a better way ? wich im sure there must be :)


* - iNCEPTiON_V - Apr 18, 2017

Can be closed. Solved it, now the matchmaking works fine.


* - tuNNelZ - Apr 18, 2017

You need to be L33T Or Uber Or 3PIC to close your threads. suggest contacting an admin to do so.


* - iNCEPTiON_V - Apr 18, 2017

(Apr 18, 2017 05:49 AM)tuNNelZ Wrote:  You need to be L33T Or Uber Or 3PIC to close your threads. suggest contacting an admin to do so.

Thanks didn't now that!