示例#1
0
        /// <summary>
        /// Will add points to a ranking of a player, score will be multiplied by MatchCategory
        /// </summary>
        /// <param name="game"> game </param>
        /// <param name="player"> player </param>
        /// <param name="cat"> match category </param>
        /// <param name="score"> score </param>
        private void AddPoints(GameType game, PlayerType player, MatchCategories cat, int score)
        {
            int realScore = 0;

            switch (cat)
            {
            case MatchCategories.Training:
                realScore = score;
                break;

            case MatchCategories.Competition:
                realScore = score * 2;
                break;

            case MatchCategories.Tournament:
                realScore = score * 3;
                break;

            default:
                break;
            }
            PlayerGameRankingType r = new PlayerGameRankingType(game, player, realScore);

            if (backend.RankingList.Contains(r))
            {
                backend.RankingList[backend.RankingList.IndexOf(r)] = new PlayerGameRankingType(game, player, realScore + backend.RankingList[backend.RankingList.IndexOf(r)].Points);
            }
            else
            {
                backend.RankingList.Add(new PlayerGameRankingType(game, player, realScore));
            }
            backend.SubmitRankingListChanges();
        }
示例#2
0
        /// <summary>
        /// Updates all rankings (NEEDS VALID SCORES!)
        /// </summary>
        private void UpdateRankings()
        {
            IPlayerManipulations pm = new PlayerLogic();

            // update rankings
            for (int i = 0; i < backend.RankingList.Count; i++)
            {
                PlayerGameRankingType r = backend.RankingList[i];
                if (pm.GetGameMatchesForPlayer(r.Game, r.Player).Count < 4)
                {
                    // player is unranked
                    backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Unranked);
                    continue;
                }
                else
                {
                    // get the scores for the game
                    List <int> scoresInGame = new List <int>();
                    foreach (PlayerGameRankingType g in backend.RankingList)
                    {
                        if (g.Game == r.Game)
                        {
                            scoresInGame.Add(g.Points);
                        }
                    }
                    // calculate percentile
                    int percentile = CalculatePercentile(scoresInGame, r.Points);
                    // update ranking
                    if (percentile < 10)
                    {
                        backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Novice);
                    }
                    else if (percentile >= 10 && percentile < 50)
                    {
                        backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Competent);
                    }
                    else if (percentile >= 50 && percentile < 85)
                    {
                        backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Advanced);
                    }
                    else
                    {
                        backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Elite);
                    }
                }
            }
            backend.SubmitRankingListChanges();
        }
示例#3
0
        public void TestRankingSerialisation()
        {
            var DAL = (IGameRankingDataAccess)getInterfaceImplementation(typeof(IGameRankingDataAccess));

            ClearAllData(DAL);
            Assert.IsNotNull(DAL.RankingList, "DAL property \"RankingList\" is null after calling \"ClearAllData\"");
            Assert.IsTrue(DAL.RankingList.Count == 0, "DAL property \"RankingList\" is not empty after calling \"ClearAllData\"");
            PlayerGameRankingType ranking = new PlayerGameRankingType()
            {
                Game = new GameType()
                {
                    Name = "testgame", ParticipantType = ParticipantTypes.Team
                },
                Player = new PlayerType()
                {
                    Name = "testplayer", Mail = "*****@*****.**", Tag = "Tagname"
                },
                Points  = 123,
                Ranking = Ranks.Competent
            };

            DAL.RankingList.Add(ranking);
            Assert.IsTrue(DAL.RankingList.Count == 1, "Count for DAL property \"RankingList\" != 1 after adding one ranking.");
            DAL.SubmitRankingListChanges();
            // destroy DAL & force reload from files...
            DAL = null;
            DAL = (IGameRankingDataAccess)getInterfaceImplementation(typeof(IGameRankingDataAccess));
            Assert.IsNotNull(DAL.RankingList, "DAL property \"RankingList\" is null after creating a new instance of the DAL.");
            Assert.IsTrue(DAL.RankingList.Count == 1, "Added ranking was not persisted.");
            Assert.AreEqual(DAL.RankingList[0].Game.Name, ranking.Game.Name,
                            $"Ranking.Game.Name not OK after serialisation. Expected: {ranking.Game.Name}, was: {DAL.RankingList[0].Game.Name}");
            Assert.AreEqual(DAL.RankingList[0].Player.Name, ranking.Player.Name,
                            $"Ranking.Player.Name not OK after serialisation. Expected: {ranking.Player.Name}, was: {DAL.RankingList[0].Player.Name}");
            Assert.AreEqual(DAL.RankingList[0].Points, ranking.Points,
                            $"Ranking.Points not OK after serialisation. Expected: {ranking.Points}, was: {DAL.RankingList[0].Points}");
            Assert.AreEqual(DAL.RankingList[0].Ranking, ranking.Ranking,
                            $"Ranking.Ranking not OK after serialisation. Expected: {ranking.Ranking}, was: {DAL.RankingList[0].Ranking}");
        }
 /// <summary>
 /// Will add points to a ranking of a player, score will be multiplied by MatchCategory
 /// </summary>
 /// <param name="game"> game </param>
 /// <param name="player"> player </param>
 /// <param name="cat"> match category </param>
 /// <param name="score"> score </param>
 private void AddPoints(GameType game, PlayerType player, MatchCategories cat, int score)
 {
     int realScore = 0;
     switch (cat)
     {
         case MatchCategories.Training:
             realScore = score;
             break;
         case MatchCategories.Competition:
             realScore = score * 2;
             break;
         case MatchCategories.Tournament:
             realScore = score * 3;
             break;
         default:
             break;
     }
     PlayerGameRankingType r = new PlayerGameRankingType(game, player, realScore);
     if (backend.RankingList.Contains(r))
     {
         backend.RankingList[backend.RankingList.IndexOf(r)] = new PlayerGameRankingType(game, player, realScore + backend.RankingList[backend.RankingList.IndexOf(r)].Points);
     }
     else
     {
         backend.RankingList.Add(new PlayerGameRankingType(game, player, realScore));
     }
     backend.SubmitRankingListChanges();
 }
示例#5
0
 public void TestRankingSerialisation()
 {
     var DAL = (IGameRankingDataAccess)getInterfaceImplementation(typeof(IGameRankingDataAccess));
     ClearAllData(DAL);
     Assert.IsNotNull(DAL.RankingList, "DAL property \"RankingList\" is null after calling \"ClearAllData\"");
     Assert.IsTrue(DAL.RankingList.Count == 0, "DAL property \"RankingList\" is not empty after calling \"ClearAllData\"");
     PlayerGameRankingType ranking = new PlayerGameRankingType()
     {
         Game = new GameType() { Name = "testgame", ParticipantType = ParticipantTypes.Team },
         Player = new PlayerType() { Name = "testplayer", Mail = "*****@*****.**", Tag = "Tagname" },
         Points = 123,
         Ranking = Ranks.Competent
     };
     DAL.RankingList.Add(ranking);
     Assert.IsTrue(DAL.RankingList.Count == 1, "Count for DAL property \"RankingList\" != 1 after adding one ranking.");
     DAL.SubmitRankingListChanges();
     // destroy DAL & force reload from files...
     DAL = null;
     DAL = (IGameRankingDataAccess)getInterfaceImplementation(typeof(IGameRankingDataAccess));
     Assert.IsNotNull(DAL.RankingList, "DAL property \"RankingList\" is null after creating a new instance of the DAL.");
     Assert.IsTrue(DAL.RankingList.Count == 1, "Added ranking was not persisted.");
     Assert.AreEqual(DAL.RankingList[0].Game.Name, ranking.Game.Name,
         $"Ranking.Game.Name not OK after serialisation. Expected: {ranking.Game.Name}, was: {DAL.RankingList[0].Game.Name}");
     Assert.AreEqual(DAL.RankingList[0].Player.Name, ranking.Player.Name,
         $"Ranking.Player.Name not OK after serialisation. Expected: {ranking.Player.Name}, was: {DAL.RankingList[0].Player.Name}");
     Assert.AreEqual(DAL.RankingList[0].Points, ranking.Points,
         $"Ranking.Points not OK after serialisation. Expected: {ranking.Points}, was: {DAL.RankingList[0].Points}");
     Assert.AreEqual(DAL.RankingList[0].Ranking, ranking.Ranking,
         $"Ranking.Ranking not OK after serialisation. Expected: {ranking.Ranking}, was: {DAL.RankingList[0].Ranking}");
 }