예제 #1
0
        public static void Build()
        {
            StreamReader sr = new StreamReader(".\\..\\..\\..\\Results.csv");
            string contents = sr.ReadToEnd().Replace("\r", "");
            sr.Dispose();

            string[] x = contents.Split('\n');

            for (int i = 1; i < 1011; i++)
            {
                string name = x[i].Split(',')[0];
                if (!ps.ContainsKey(name))
                {
                    ps[name] = new Player(name, 0);
                    ps[name].GamesPlayed = 1;
                }
                else
                {
                    ps[name].GamesPlayed++;
                }
            }

            for (int i = 0; i < 101; i++)
            {
                Game g = new Game();
                g.GoalDiff = double.Parse(x[i * 10 + 1].Split(',')[2]);

                for (int a = 0; a < 5; a++)
                    g.TA[a] = ps[x[(i * 10) + a + 1].Split(',')[0]];
                for (int b = 0; b < 5; b++)
                    g.TB[b] = ps[x[(i * 10) + b + 6].Split(',')[0]];

                if (g.TA.All(z => z.GamesPlayed > 2) && g.TB.All(z => z.GamesPlayed > 2))
                    gs.Add(g);
            }

            Games = gs.ToArray();
            Shuffle(Games);
            Players = ps.Select(z => z.Value).Where(z => z.GamesPlayed > 2).ToArray();

            int playerCount = Players.Count();
            Results = new double[Games.Count()];
            WhoPlayed = new double[Games.Count()][];

            for (int i = 0; i < Games.Count(); i++)
            {
                Game g = Games[i];
                Results[i] = Conv(g.GoalDiff);

                WhoPlayed[i] = new double[playerCount];
                for (int j = 0; j < playerCount; j++)
                {
                    if (g.TA.Contains(Players[j])) WhoPlayed[i][j] = 1;
                    else if (g.TB.Contains(Players[j])) WhoPlayed[i][j] = -1;
                    else WhoPlayed[i][j] = 0;
                }
            }
        }
예제 #2
0
        private static void Shuffle(Game[] games)
        {
            Random r = new Random();

            for (int i = 0; i < 1000; i++)
            {
                int r1 = r.Next(0, games.Length);
                int r2 = r.Next(0, games.Length);
                Game temp = games[r1];
                games[r1] = games[r2];
                games[r2] = temp;
            }
        }