Esempio n. 1
0
        public Player AddRandomPlayer(MatchMakingContext dbContext)
        {
            lock (_lock)
            {
                using (dbContext)
                {
                    var player = GenerateRandomPlayer();

                    dbContext.Players.Add(player);
                    dbContext.SaveChanges();
                    return(player);
                }
            }
        }
Esempio n. 2
0
        public void AddRandomPlayers(MatchMakingContext dbContext, int numberOfPlayers)
        {
            lock (_lock)
            {
                using (dbContext)
                {
                    var playerList = new List <Player>();
                    for (int i = 0; i < numberOfPlayers; i++)
                    {
                        playerList.Add(GenerateRandomPlayer());
                    }

                    dbContext.Players.AddRange(playerList);
                    dbContext.SaveChanges();

                    Console.WriteLine($"{numberOfPlayers} new players added, {dbContext.Players.Count()} player(s) in the queue.");
                }
            }
        }
Esempio n. 3
0
        public void TestingAlgorithms(MatchMakingContext dbContext)
        {
            using (dbContext)
            {
                dbContext.Players.Add(new Player()
                {
                    Name = "Cem", Skill = 0.5, Remoteness = 15
                });
                dbContext.SaveChanges();

                Thread.Sleep(1000);
                AddRandomPlayers(dbContext, 999);
                dbContext.SaveChanges();

                var players1 = NearestToAverage(dbContext.Players.Take(1000).ToList(), 20);
                var match1   = new Match(players1);
                Console.WriteLine(match1);

                var players2 = NearestToFirst(dbContext.Players.Take(1000).ToList(), 20);
                var match2   = new Match(players2);
                Console.WriteLine(match1);
            }
        }
Esempio n. 4
0
        public Match TryMatchmaking(MatchMakingContext dbContext)
        {
            lock (_lock)
            {
                using (dbContext)
                {
                    var players = dbContext.Players.ToList();
                    if (!ShouldStartMatch(players, _matchSize, _timeout))
                    {
                        return(null);
                    }

                    var selectedPlayers = NearestToAverage(players, _matchSize);
                    var newMatch        = new Match(selectedPlayers);

                    dbContext.Players.RemoveRange(selectedPlayers);
                    dbContext.Matches.Add(newMatch);
                    dbContext.SaveChanges();

                    return(newMatch);
                }
            }
        }