Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Trying to solve this Matchmaking Problem.

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 :)
Can be closed. Solved it, now the matchmaking works fine.
You need to be L33T Or Uber Or 3PIC to close your threads. suggest contacting an admin to do so.
(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!


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by MelonbreadHFNov 4, 2018 01:44 AM 0 161 Nov 4, 2018 01:44 AM
Last Post: MelonbreadHF
[Java] by LoGiuratoMar 2, 2018 01:30 PM 1 217 Mar 2, 2018 01:30 PM
Last Post: LoGiurato
[C] by keepitlseezy1Mar 8, 2015 06:06 PM 3 130 Mar 8, 2015 06:06 PM
Last Post: P3TE