Esempio n. 1
0
        public void InitializePlayerScore() // informacje o wcześniejszych poczynaniach gracza oraz inicjalizacja GameScore !
        {
            Player player;

            if (PlayerCount >= 1)
            {
                player         = myBaseSqlite.GetPlayer(player1);
                s1             = new GameScore(player.ID, player.name, player.winCount, player.lostCount, player.bestScore, player.matchCount, player.scoreRatio, player.elo, maxEloPlayersIntoGame, BestEloPlayerIntoGame);
                s1.ArrowCount  = ArrowCount;
                s1.RoundCount  = RoundCount;
                s1.PlayerCount = PlayerCount;
            }

            if (PlayerCount >= 2)
            {
                player         = myBaseSqlite.GetPlayer(player2);
                s2             = new GameScore(player.ID, player.name, player.winCount, player.lostCount, player.bestScore, player.matchCount, player.scoreRatio, player.elo, maxEloPlayersIntoGame, BestEloPlayerIntoGame);
                s2.ArrowCount  = ArrowCount;
                s2.RoundCount  = RoundCount;
                s2.PlayerCount = PlayerCount;
            }

            if (PlayerCount >= 3)
            {
                player         = myBaseSqlite.GetPlayer(player3);
                s3             = new GameScore(player.ID, player.name, player.winCount, player.lostCount, player.bestScore, player.matchCount, player.scoreRatio, player.elo, maxEloPlayersIntoGame, BestEloPlayerIntoGame);
                s3.ArrowCount  = ArrowCount;
                s3.RoundCount  = RoundCount;
                s3.PlayerCount = PlayerCount;
            }

            if (PlayerCount >= 4)
            {
                player         = myBaseSqlite.GetPlayer(player4);
                s4             = new GameScore(player.ID, player.name, player.winCount, player.lostCount, player.bestScore, player.matchCount, player.scoreRatio, player.elo, maxEloPlayersIntoGame, BestEloPlayerIntoGame);
                s4.ArrowCount  = ArrowCount;
                s4.RoundCount  = RoundCount;
                s4.PlayerCount = PlayerCount;
            }

            if (PlayerCount >= 5)
            {
                player         = myBaseSqlite.GetPlayer(player5);
                s5             = new GameScore(player.ID, player.name, player.winCount, player.lostCount, player.bestScore, player.matchCount, player.scoreRatio, player.elo, maxEloPlayersIntoGame, BestEloPlayerIntoGame);
                s5.ArrowCount  = ArrowCount;
                s5.RoundCount  = RoundCount;
                s5.PlayerCount = PlayerCount;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get list of sorted player according to descending score
        /// </summary>
        /// <param name="lastsum">Variable if is true that the final result is run, else if that change who is the best now</param>
        /// <returns></returns>
        public GameScore[] Best(bool lastsum = false)
        {
            int[]     bests = new int[PlayerCount];
            GameScore score;

            for (int i = 0; i < PlayerCount; i++)
            {
                DictGameScore().TryGetValue(i, out score);
                bests[i] = score.Sum;
            }

            Array.Sort(bests);
            Array.Reverse(bests); // zwraca liste wynikow od najepszego

            GameScore[] gameScores = new GameScore[playerCount];
            for (int i = 0; i < PlayerCount; i++)
            {
                for (int j = 0; j < PlayerCount; j++)
                {
                    DictGameScore().TryGetValue(j, out score);

                    if ((i < PlayerCount - 1) && bests[i] == bests[i + 1] && score.Sum == bests[i]) // wejdzie jesli wynik nastepny jest taki sam jak aktualny
                    {
                        if (i > 0 && gameScores[i - 1] != score)
                        {
                            gameScores[i] = score;
                            break;
                        }
                        else if (i == 0)
                        {
                            gameScores[i] = score;
                            break;
                        }
                    }

                    else if (score.Sum == bests[i]) // wejdzie jeśli suma punktow gracza = liscie najlepszych wynikow
                    {
                        if (i == playerCount - 1 && gameScores[j] != score && lastsum == true)
                        {
                            gameScores[i] = score;
                        }

                        else if (i > 0 && bests[i] == bests[i - 1] && lastsum == true) // 0 = 0
                        {
                            continue;
                        }

                        else if (i > 0 && gameScores[i - 1] != score)
                        {
                            gameScores[i] = score;
                        }

                        else if (i == 0)
                        {
                            gameScores[i] = score;
                        }
                    }
                }
            }

            // if array have null value
            bool arrayNullValue = false;
            int  idNull         = 0;

            for (int i = 0; i < playerCount; i++)
            {
                if (gameScores[i] == null)
                {
                    arrayNullValue = true;
                    idNull         = i;
                }
            }


            //anty double value
            if (!arrayNullValue && lastsum)
            {
                for (int i = 0; i < gameScores.Length; i++)
                {
                    if (i > 0 && gameScores[i] == gameScores[i - 1])
                    {
                        if (CoinToss())
                        {
                            gameScores[i] = null;
                            idNull        = i;
                        }
                        else
                        {
                            gameScores[i - 1] = null;
                            idNull            = i - 1;
                        }
                        arrayNullValue = true;
                    }
                }
            }



            //anty error null value
            if (arrayNullValue)
            {
                Dictionary <int, GameScore> nullValue = DictGameScore();

                for (int i = PlayerCount; i <= nullValue.Count; i++)
                {
                    nullValue.Remove(i);
                }

                for (int i = 0; i < playerCount; i++)
                {
                    for (int j = 0; j < DictGameScore().Count; j++)
                    {
                        DictGameScore().TryGetValue(j, out GameScore value);
                        if (gameScores[i] == value)
                        {
                            nullValue.Remove(j);
                        }
                    }
                }

                foreach (KeyValuePair <int, GameScore> item in nullValue)
                {
                    gameScores[idNull] = item.Value;
                }
            }

            // remis sprawdza best hit
            for (int i = 0; i < PlayerCount - 1; i++)
            {
                if (gameScores[i].Sum == gameScores[i + 1].Sum)
                {
                    GameScore best    = new GameScore();
                    int       bestHit = 0;
                    int       currentValue;
                    for (int j = 0; j < roundCount; j++)
                    {
                        gameScores[i].DictScoreEveryRound().TryGetValue(j + 1, out int value1);
                        gameScores[i + 1].DictScoreEveryRound().TryGetValue(j + 1, out int value2);
                        currentValue = GetMax(value1, value2);

                        if (currentValue > bestHit)
                        {
                            bestHit = currentValue;
                            if (bestHit == value1)
                            {
                                best = gameScores[i];
                            }
                            else if (bestHit == value2)
                            {
                                best = gameScores[i + 1];
                            }
                        }
                    }

                    if (best == gameScores[i + 1])
                    {
                        GameScore p1 = gameScores[i];
                        GameScore p2 = gameScores[i + 1];
                        gameScores[i]     = p2;
                        gameScores[i + 1] = p1;
                    }
                }
            }

            return(gameScores);
        }