private void processJsonData(string _dataJson)
        {
            tabelScore = JsonUtility.FromJson <skorCollection>(_dataJson);

            Debug.Log(tabelScore);

            //kalo ikut format JsonData, dibikin variable array penampung tabelScore.data
            // public ListScore[] daftarUser --> initial
            // daftarUser = tabelScore.data;

            //sort by score

            for (int i = 0; i < tabelScore.data.Length; i++)
            {
                for (int j = i + 1; j < tabelScore.data.Length; j++)
                {
                    if (tabelScore.data[j].poin > tabelScore.data[i].poin)
                    {
                        //swap posisi
                        ListScore tmp = tabelScore.data[i];
                        tabelScore.data[i] = tabelScore.data[j];
                        tabelScore.data[j] = tmp;

                        //Debug.log(tabelscore.data[j].poin + "j ini i" + tabelscore.data[i].poin);
                    }
                    Debug.Log(tabelScore.data[j].poin + "j ini i" + tabelScore.data[i].poin);
                }
                //    debug.log(" ini i " + tabelscore.data[i].poin);
            }

            ListScoreTransformList = new List <Transform>();

            foreach (ListScore listScore in tabelScore.data)
            {
                createTableLeaderboard(listScore, contentLeaderboardPool, ListScoreTransformList);
                Debug.Log(listScore.poin);
            }
        }
        public void createTableLeaderboard(ListScore listScore, Transform poolContent, List <Transform> transformList)
        {
            Transform     dataContent      = Instantiate(contentLeaderboard, poolContent);
            RectTransform dataContentReact = dataContent.GetComponent <RectTransform>();

            dataContentReact.anchoredPosition = new Vector2(0, -tinggiContent * transformList.Count);
            dataContent.gameObject.SetActive(true);

            // isi kontent

            int    rank = transformList.Count + 1; // ini ntar ganti index user
            string rankString;

            switch (rank)
            {
            default: rankString = rank + "th"; break;

            case 1: rankString = "1st"; break;

            case 2: rankString = "2nd"; break;

            case 3: rankString = "3rd"; break;
            }

            if (rank == 1)
            {
                // warna paling atas
                dataContent.Find("TextRank").GetComponent <Text>().color  = Color.green;
                dataContent.Find("TextName").GetComponent <Text>().color  = Color.green;
                dataContent.Find("TextScore").GetComponent <Text>().color = Color.green;
                dataContent.Find("TextTime").GetComponent <Text>().color  = Color.green;
            }


            switch (rank)
            {
            //warna tropy
            default:
                dataContent.Find("Trophy").gameObject.SetActive(false);
                break;

            case 1:
                dataContent.Find("Trophy").GetComponent <RawImage>().color = Color.yellow;
                break;

            case 2:
                dataContent.Find("Trophy").GetComponent <RawImage>().color = Color.magenta;
                break;

            case 3:
                dataContent.Find("Trophy").GetComponent <RawImage>().color = Color.red;
                break;
            }

            var hours   = listScore.waktu / 3600;
            var minutes = Mathf.Floor(listScore.waktu / 60) % 60;
            var seconds = listScore.waktu % 60;

            //  rekapWaktu.text = "Waktu: " + string.Format("{0:00} : {1:00}", minutes, seconds);

            dataContent.Find("TextRank").GetComponent <Text>().text = rank.ToString();
            // dataContent.Find("TextRank").GetComponent<Text>().text = rankString;

            dataContent.Find("TextName").GetComponent <Text>().text  = listScore.nama_user;
            dataContent.Find("TextScore").GetComponent <Text>().text = listScore.poin.ToString();
            dataContent.Find("TextTime").GetComponent <Text>().text  = string.Format("{0:00} : {1:00} : {2:00}", hours, minutes, seconds);

            transformList.Add(contentLeaderboard);
            Debug.Log(dataContent);
        }
示例#3
0
        public override string GetAnswer()
        {
            try
            {
                string ans = "[Метод Кондорсе]\r\n";
                for (int i = 0; i < CandidateCount; i++)
                {
                    for (int j = i + 1; j < CandidateCount; j++)
                    {
                        ans += CompareAlter(i, j);
                    }
                }

                ans += "Ответ: " + Result() + "\r\n\r\n";
                return(ans);

                string CompareAlter(int X, int Y)
                {
                    int CountVotes = ListVote.Sum();

                    int X_Votes = 0;

                    for (int i = 0; i < ListAlt.Count; i++)
                    {
                        if (ListAlt[i].IndexOf(ALPHABET[X].ToString()) < ListAlt[i].IndexOf(ALPHABET[Y].ToString()))
                        {
                            X_Votes += ListVote[i];
                        }
                    }

                    char symbol;

                    if (X_Votes > (CountVotes - X_Votes))
                    {
                        symbol = '>';
                        ListScore[X]++;
                    }
                    else if (X_Votes < (CountVotes - X_Votes))
                    {
                        symbol = '<';
                        ListScore[Y]++;
                    }
                    else
                    {
                        symbol = '=';
                    }

                    string s = ALPHABET[X] + " " + symbol + " " + ALPHABET[Y] + " : " + X_Votes + " " + symbol + " " + (CountVotes - X_Votes) + "\r\n";

                    return(s);
                }

                string Result()
                {
                    List <int> list_temp = new List <int>();

                    for (int i = 0; i < ListScore.Count; i++)
                    {
                        list_temp.Add(ListScore[i]);
                    }
                    list_temp.Sort();

                    for (int i = 0; i < list_temp.Count; i++)
                    {
                        if (list_temp[i] > i)
                        {
                            return("Парадокс Кондорсе!");
                        }
                        else if (i != 0)
                        {
                            if (list_temp[i] != list_temp[i - 1] && list_temp[i] != i)
                            {
                                return("Парадокс Кондорсе!");
                            }
                        }
                    }

                    string s   = null;
                    int    cnt = ListScore.Count;
                    int    max = ListScore.Max();

                    for (int i = 0; i < cnt; i++)
                    {
                        if (i != 0)
                        {
                            if (max == ListScore.Max())
                            {
                                s += " = ";
                            }
                            else
                            {
                                s += " > ";
                            }
                        }
                        s  += ALPHABET[ListScore.IndexOf(ListScore.Max())];
                        max = ListScore.Max();
                        ListScore[ListScore.IndexOf(max)] = -1;
                    }

                    return(s);
                }
            }
            catch { return(null); }
        }
示例#4
0
        public override string GetAnswer()
        {
            try
            {
                string ans = "[Метод Борда]\r\n";
                for (int i = 0; i < CandidateCount; i++)
                {
                    CompareAlter(i);
                    ans += ALPHABET[i] + " = " + ListScore[i] + "\r\n";
                }
                ans += "Ответ: " + Answer() + "\r\n";
                return(ans);

                bool CompareAlter(int X)
                {
                    List <string> list_tmp = new List <string>();

                    for (int i = 0; i < ListAlt.Count; i++)
                    {
                        list_tmp.Add(ListAlt[i]);
                    }

                    for (int i = 0; i < list_tmp.Count; i++)
                    {
                        for (int j = 0; j < list_tmp[i].Length; j++)
                        {
                            if (list_tmp[i][j] == ' ' || list_tmp[i][j] == '>')
                            {
                                list_tmp[i] = list_tmp[i].Remove(j--, 1);
                            }
                        }

                        string s = null;
                        for (int c = list_tmp[i].Length - 1; c >= 0; c--)
                        {
                            s += list_tmp[i][c];
                        }
                        list_tmp[i] = s;

                        ListScore[X] += ListVote[i] * list_tmp[i].IndexOf(ALPHABET[X].ToString());
                    }
                    return(true);
                }

                string Answer()
                {
                    string s   = null;
                    int    cnt = ListScore.Count;
                    int    max = ListScore.Max();

                    for (int i = 0; i < cnt; i++)
                    {
                        if (i != 0)
                        {
                            if (max == ListScore.Max())
                            {
                                s += " = ";
                            }
                            else
                            {
                                s += " > ";
                            }
                        }
                        s  += ALPHABET[ListScore.IndexOf(ListScore.Max())];
                        max = ListScore.Max();
                        ListScore[ListScore.IndexOf(max)] = -1;
                    }

                    return(s);
                }
            }
            catch { return(null); }
        }
示例#5
0
        public override string GetAnswer()
        {
            try
            {
                string ans = "[Метод Копленда]\r\n";
                for (int i = 0; i < CandidateCount; i++)
                {
                    for (int j = 0; j < CandidateCount; j++)
                    {
                        if (i != j)
                        {
                            CompareAlter(i, j);
                        }
                    }
                    ans += ALPHABET[i] + " = " + ListScore[i] + "\r\n";
                }
                ans += "Ответ: " + Answer() + "\r\n\r\n";
                return(ans);

                bool CompareAlter(int X, int Y)
                {
                    int sum        = 0;
                    int CountVotes = ListVote.Sum();

                    for (int i = 0; i < ListAlt.Count; i++)
                    {
                        if (ListAlt[i].IndexOf(ALPHABET[X].ToString()) < ListAlt[i].IndexOf(ALPHABET[Y].ToString()))
                        {
                            sum += ListVote[i];
                        }
                    }
                    if (sum > (CountVotes - sum))
                    {
                        ListScore[X]++;
                    }
                    else if (sum < (CountVotes - sum))
                    {
                        ListScore[X]--;
                    }
                    return(true);
                }

                string Answer()
                {
                    string s   = null;
                    int    cnt = ListScore.Count;
                    int    max = ListScore.Max();
                    int    min = ListScore.Min();

                    for (int i = 0; i < cnt; i++)
                    {
                        if (i != 0)
                        {
                            if (max == ListScore.Max())
                            {
                                s += " = ";
                            }
                            else
                            {
                                s += " > ";
                            }
                        }
                        s  += ALPHABET[ListScore.IndexOf(ListScore.Max())];
                        max = ListScore.Max();
                        ListScore[ListScore.IndexOf(max)] = min - 1;
                    }
                    return(s);
                }
            }
            catch { return(null); }
        }
示例#6
0
        public override string GetAnswer()
        {
            try
            {
                List <int> list_tmp = new List <int>();
                for (int i = 0; i < CandidateCount; i++)
                {
                    list_tmp.Add(0);
                }

                string ans = "[Метод Симпсона]\r\n";
                for (int i = 0; i < CandidateCount; i++)
                {
                    ClearListTmp();
                    for (int j = 0; j < CandidateCount; j++)
                    {
                        if (i != j)
                        {
                            CompareAlter(i, j);
                        }
                    }
                    list_tmp[i]  = list_tmp.Max() + 1;
                    ListScore[i] = list_tmp.Min();
                    ans         += "Оценка по " + ALPHABET[i] + " = " + ListScore[i] + "\r\n";
                }
                ans += "Ответ: " + Answer() + "\r\n\r\n";
                return(ans);

                bool ClearListTmp()
                {
                    for (int i = 0; i < list_tmp.Count; i++)
                    {
                        list_tmp[i] = 0;
                    }
                    return(true);
                }

                bool CompareAlter(int X, int Y)
                {
                    for (int i = 0; i < ListAlt.Count; i++)
                    {
                        if (ListAlt[i].IndexOf(ALPHABET[X].ToString()) < ListAlt[i].IndexOf(ALPHABET[Y].ToString()))
                        {
                            list_tmp[Y] += ListVote[i];
                        }
                    }
                    return(true);
                }

                string Answer()
                {
                    string s   = null;
                    int    max = ListScore.Max();

                    #region
                    //int cnt = ListScore.Count;
                    //int min = ListScore.Min();
                    //for (int i = 0; i < cnt; i++)
                    //{
                    // if (i != 0)
                    // {
                    // if (max == ListScore.Max())
                    // s += " = ";
                    // else
                    // s += " > ";
                    // }
                    // s += ALPHABET[ListScore.IndexOf(ListScore.Max())];
                    // max = ListScore.Max();
                    // ListScore[ListScore.IndexOf(max)] = min - 1;
                    //}
                    #endregion

                    int cnt = 0;
                    for (int i = 0; i < ListScore.Count; i++)
                    {
                        if (max == ListScore[i])
                        {
                            if (cnt != 0)
                            {
                                s += ", ";
                            }
                            s += ALPHABET[i];
                            cnt++;
                        }
                    }


                    s += " - наилучшая(ие) альтернатива(ы)!";
                    return(s);
                }
            }
            catch { return(null); }
        }