Пример #1
0
        public static void UpdateLadderBasedOnGame(Game game, int DefaultLadderPosition)
        {
            foreach (GamePlayer gameplayer in game.GamePlayers)
            {
                if (game.finished == 1)
                {
                    // add new people to ladder. No longer worrying about people who drop in their first game - just add them to the ladder anyway
                    if (!Ladder.Exists(x => x.PlayerName == gameplayer.playername))
                    {
                        Ladder.Add(new LadderPlayer(gameplayer.playername, DefaultLadderPosition));
                        gameplayer.currentposition = DefaultLadderPosition;
                    }
                    else
                    {
                        gameplayer.currentposition = Ladder.Find(x => x.PlayerName == gameplayer.playername).Position;
                    }

                    AddPositionalScores(game, false);


                    // Add the game info to the ladder player and set their temporary "position" ready for ordering
                    PlayerGameInfo Info = new PlayerGameInfo();
                    Info.GameNumber = game.GameNumber;
                    Info.WeekNumber = game.WeekNumber;
                    Info.Finished   = true;
                    Info.Dropped    = false;
                    Info.Faction    = gameplayer.faction;
                    Info.Rank       = gameplayer.rank;
                    LadderPlayer LP = Ladder.Find(x => x.PlayerName == gameplayer.playername);
                    LP.AddGameInfo(Info);
                    LP.Playing = true;
                    LP.TemporaryPositionDouble = LP.Position - gameplayer.score;
                    LP.AddTogmgMarathonScore(game.GameNumber, (int)gameplayer.rank);
                }
                else
                {
                    LadderPlayer LP = Ladder.Find(x => x.PlayerName == gameplayer.playername);
                    if (LP != null)
                    {
                        LP.Playing = true;
                        LP.TemporaryPositionDouble = (double)(LP.Position);
                    }
                }
            }
        }
Пример #2
0
        // Legacy method for GW < 38
        static void AddGameToLadder(Game game)
        {
            // add everyone to the ladder in order
            int ProcessingOrder = 1;


            // if the player dropped in their first game, don't add them to the ladder
            foreach (GamePlayer gameplayer in game.GamePlayers.Where(x => x.dropped != 1).OrderBy(x => x.rank).ThenBy(x => x.playername))
            {
                if (!Ladder.Exists(x => x.PlayerName == gameplayer.playername))
                {
                    if (OldPlayers.Exists(x => x.PlayerName == gameplayer.playername))
                    {
                        LadderPlayer Player = OldPlayers.Where(x => x.PlayerName == gameplayer.playername).First();
                        Player.Position = Ladder.Count() + 1;
                        Ladder.Add(Player);
                    }
                    else
                    {
                        Ladder.Add(new LadderPlayer(gameplayer.playername, Ladder.Count() + 1));
                    }
                }
                gameplayer.processingorder = ProcessingOrder;
                ProcessingOrder++;

                PlayerGameInfo Info = new PlayerGameInfo();
                Info.GameNumber = game.GameNumber;
                Info.WeekNumber = game.WeekNumber;
                Info.Finished   = true;
                Info.Dropped    = false;
                Info.Faction    = gameplayer.faction;
                Info.Rank       = gameplayer.rank;
                Ladder.Find(x => x.PlayerName == gameplayer.playername).AddGameInfo(Info);

                if (game.WeekNumber >= 5)
                {
                    Ladder.Find(x => x.PlayerName == gameplayer.playername).AddTogmgMarathonScore(game.GameNumber, (int)gameplayer.rank);
                }
            }


            // give everyone a score
            AddPositionalScores(game, true);

            // set people's new positions
            int TotalPlayers = Ladder.Count();

            // get their new position
            foreach (GamePlayer gameplayer in game.GamePlayers.OrderBy(x => x.processingorder))
            {
                /* this is the description of how to find your new position
                 *
                 * To determine ladder positions, the following algorithm is applied to each game in order of completion:
                 * Anyone in the game who's not yet on the ladder, gets added at the bottom of the ladder, in order of finishing position (alphabetically in the case of a tie)
                 * Everyone in the game gets their new ladder position calculated as follows (L is current ladder position, S is the score as determined by the table to the right)
                 * For positive S: New L = Floor(Min(L *(1 - S/20), L - S))
                 * For negative S: New L = Ceiling(Max(L *(1 - S/20), L - S))
                 * If N players from the game receive the same new position, they are allocated positions L through L+ N - 1 ordered by position in the game and then alphabetically
                 * Ls are adjusted such that they are between 1 and (# of players on ladder)
                 */

                // if the player dropped in their first game, they may not be on the ladder at all
                if (Ladder.Exists(x => x.PlayerName == gameplayer.playername))
                {
                    gameplayer.currentposition = Ladder.Find(x => x.PlayerName == gameplayer.playername).Position;
                    double ScoreRelative = Convert.ToDouble(gameplayer.currentposition) * gameplayer.score / 20;
                    int    PlacesToMove  = 0;

                    if (gameplayer.score < 0)
                    {
                        PlacesToMove = Convert.ToInt32(Math.Floor(Math.Min(gameplayer.score, ScoreRelative)));
                    }
                    else
                    {
                        PlacesToMove = Convert.ToInt32(Math.Ceiling(Math.Max(gameplayer.score, ScoreRelative)));
                    }

                    if (CurrentPlayers.Count() == 0 || PlacesToMove <= 0 || game.WeekNumber > 8)
                    {
                        gameplayer.newposition = Math.Max(gameplayer.currentposition - PlacesToMove, 1);
                    }
                    else
                    {
                        gameplayer.newposition = gameplayer.currentposition;
                        int j = 0;
                        while (j < PlacesToMove && gameplayer.newposition > 1)
                        {
                            gameplayer.newposition--;
                            if (gameplayer.newposition < 1)
                            {
                                j++;
                            }
                            else
                            {
                                j = j + Ladder.Where(x => x.Position == gameplayer.newposition && CurrentPlayers.Contains(x.PlayerName)).Count();
                            }
                        }
                    }

                    // resolve duplicates - shunt them down 1 if someone has the same position
                    while (game.GamePlayers.Where(x => x.processingorder < gameplayer.processingorder && x.newposition == gameplayer.newposition).Count() > 0)
                    {
                        gameplayer.newposition += 1;
                    }
                }
            }

            // The resolve duplicates code above may have resulted in a gap at the bottom of the ladder - fix this.
            // finally, we can update them on the ladder
            foreach (GamePlayer gameplayer in game.GamePlayers.OrderByDescending(x => x.processingorder))
            {
                // if the player dropped in their first game, they may not be on the ladder at all
                if (Ladder.Exists(x => x.PlayerName == gameplayer.playername))
                {
                    if (gameplayer.newposition > TotalPlayers)
                    {
                        gameplayer.newposition = TotalPlayers;
                    }

                    while (game.GamePlayers.Where(x => x.processingorder > gameplayer.processingorder && x.newposition == gameplayer.newposition).Count() > 0)
                    {
                        gameplayer.newposition -= 1;
                    }

                    Ladder.Find(x => x.PlayerName == gameplayer.playername).Position = gameplayer.newposition;
                }
            }



            // update the rest of the ladder
            int newpos = 1;

            foreach (LadderPlayer LadderPlayer in Ladder.OrderBy(x => x.Position))
            {
                if (game.GamePlayers.Select(x => x.playername).ToList().Contains(LadderPlayer.PlayerName))
                {
                    continue;
                }

                while (game.GamePlayers.Where(x => x.newposition == newpos).Count() > 0)
                {
                    newpos++;
                }
                if (LadderPlayer.Position != newpos)
                {
                    LadderPlayer.Position = newpos;
                }
                newpos++;
            }
        }