Esempio n. 1
0
        public EloResult CalcElo(int playerOneElo, int playerTwoElo, MatchWinner winner)
        {
            // A2 = A1 + 32 (G-(1/(1+10 ** ((B1-A1)/400))))
            float G  = 0;
            float A1 = System.Convert.ToSingle(playerOneElo);
            float B1 = System.Convert.ToSingle(playerTwoElo);

            if (winner == MatchWinner.PlayerOne)
            {
                G = 1;
            }
            if (winner == MatchWinner.PlayerTwo)
            {
                G = 0;
            }

            double changeValue    = factor * (G - (1 / (1 + System.Math.Pow(10, ((B1 - A1) / divisor)))));
            int    changeValueInt = System.Convert.ToInt32(changeValue);

            EloResult result = new EloResult();

            if (winner == MatchWinner.PlayerOne)
            {
                result.PlayerOneElo = playerOneElo + changeValueInt;
                result.PlayerTwoElo = playerTwoElo - changeValueInt;
            }
            if (winner == MatchWinner.PlayerTwo)
            {
                result.PlayerOneElo = playerOneElo + changeValueInt;
                result.PlayerTwoElo = playerTwoElo - changeValueInt;
            }
            result.changeValue = changeValueInt;

            return(result);
        }
Esempio n. 2
0
        public int CreateMatch(DateTime dateOfMatch, int player1, int player2, MatchWinner winner)
        {
            ValidateMatchIsNotHistoric(dateOfMatch);

            if (player1 == player2)
            {
                throw new Exception("Player 1 and Player 2 must be different players");
            }

            int   lastMatchDayOrder = db.Matches.Where(m => DbFunctions.TruncateTime(m.DateOfMatch) == dateOfMatch.Date).Max(m => (int?)m.DayMatchOrder) ?? 0;
            int   matchDayOrder     = lastMatchDayOrder + ORDER_VALUE_SPACING;
            Match match             = new Match()
            {
                DateOfMatch = dateOfMatch, DayMatchOrder = matchDayOrder, MatchParticipations = new List <MatchParticipation>()
            };

            var player1LadderRank = GetCurrentLadderRank(player1, dateOfMatch.Year, dateOfMatch.Month);
            var player2LadderRank = GetCurrentLadderRank(player2, dateOfMatch.Year, dateOfMatch.Month);

            if (player1LadderRank == player2LadderRank)
            {
                player2LadderRank++;
            }

            match.MatchParticipations.Add(CreateMatchParticipation(player1, player2, (winner == MatchWinner.Player1), dateOfMatch, player1LadderRank, player2LadderRank));
            match.MatchParticipations.Add(CreateMatchParticipation(player2, player1, (winner == MatchWinner.Player2), dateOfMatch, player2LadderRank, player1LadderRank));

            db.Matches.Add(match);
            db.SaveChanges();

            return(match.MatchID);
        }
Esempio n. 3
0
 private static void WinnerHandler(PacketHeader header, Connection connection, byte[] winner)
 {
     using (MemoryStream stream = new MemoryStream(winner))
     {
         MatchWinner matchWinner = Serializer.Deserialize <MatchWinner>(stream);
         Console.WriteLine("Team {0} won ({1}, {2})",
                           matchWinner.TeamWinner,
                           matchWinner.PseudoA,
                           matchWinner.PseudoB);
     }
 }
Esempio n. 4
0
 public void Play()
 {
     if (First.Note == Second.Note)
     {
         Winner = First.Title.CompareTo(Second.Title) <= 0 ? MatchWinner.FirstPlayer : MatchWinner.SecondPlayer;
         return;
     }
     else
     {
         Winner = First.Note > Second.Note ? MatchWinner.FirstPlayer : MatchWinner.SecondPlayer;
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Sends the result.
 /// </summary>
 private void SendResult()
 {
     using (MemoryStream stream = new MemoryStream())
     {
         MatchWinner win = new MatchWinner()
         {
             TeamWinner = WinnerId(),
             PseudoA    = ConnectionManager.Get(_teams[WinnerId()].Players[0].Connection).Pseudo,
             PseudoB    = ConnectionManager.Get(_teams[WinnerId()].Players[1].Connection).Pseudo
         };
         Serializer.Serialize(stream, win);
         foreach (var player in _players)
         {
             player.Connection.SendObject("MatchWinner", stream.ToArray());
             player.Connection.SendObject("LobbySelect");
         }
     }
 }
Esempio n. 6
0
        public int CreateMatch(DateTime dateOfMatch, string player1FullName, string player2FullName, MatchWinner winner)
        {
            var allPlayers    = db.Players.ToList();
            var player1Record = allPlayers.Where(p => p.FullName == player1FullName).SingleOrDefault();
            var player2Record = allPlayers.Where(p => p.FullName == player2FullName).SingleOrDefault();

            if (player1Record == null)
            {
                throw new IndexOutOfRangeException($"Cannot find player with name {player1FullName}");
            }
            if (player2Record == null)
            {
                throw new IndexOutOfRangeException($"Cannot find player with name {player2FullName}");
            }

            int player1ID = player1Record.PlayerID;
            int player2ID = player2Record.PlayerID;

            return(CreateMatch(dateOfMatch, player1ID, player2ID, winner));
        }