Esempio n. 1
0
 protected bool Equals(FightInfo other)
 {
     return((Player1Id == other.Player1Id && Player2Id == other.Player2Id) ||
            ((Player1Id == other.Player2Id) && (Player2Id == other.Player1Id)));
 }
Esempio n. 2
0
        public void Run(DirectoryInfo di)
        {
            mugenWorkingDirectory = di;
            mugenExe = new FileInfo(Path.Combine(di.FullName, "mugen.exe"));
            if (!mugenExe.Exists)
            {
                Console.WriteLine("{0} was not found.", mugenExe);
                return;
            }

            DirectoryInfo charsPath = new DirectoryInfo(Path.Combine(di.FullName, "chars"));

            if (!charsPath.Exists)
            {
                Console.WriteLine("{0} was not found.", charsPath);
                return;
            }

            DirectoryInfo stagesPath = new DirectoryInfo(Path.Combine(di.FullName, "stages"));

            if (!stagesPath.Exists)
            {
                Console.WriteLine("{0} was not found.", stagesPath);
                return;
            }

            //Felder initialisieren
            FileInfo[]      stageFileInfos     = stagesPath.GetFiles("*.def", SearchOption.TopDirectoryOnly);
            string[]        stageNames         = Array.ConvertAll(stageFileInfos, x => Path.GetFileNameWithoutExtension(x.Name));
            DirectoryInfo[] charsDirectoryInfo = charsPath.GetDirectories("*", SearchOption.TopDirectoryOnly);
            string[]        charNames          = Array.ConvertAll(charsDirectoryInfo, x => x.Name);
            int             numChars           = charNames.Length;
            Random          rng = new Random();

            Nullable <double>[][] scoreboard = new Nullable <double> [numChars][];
            List <FightInfo>      fights     = new List <FightInfo>();

            //Pairings bestimmen
            for (int y = 0; y < numChars; y++)
            {
                scoreboard[y] = new Nullable <double> [numChars];
                for (int x = 0; x < numChars; x++)
                {
                    if (x == y)
                    {
                        scoreboard[x][y] = null;
                        continue;
                    }

                    FightInfo fi = new FightInfo();
                    fi.Player1   = charNames[x];
                    fi.Player2   = charNames[y];
                    fi.Player1Id = x;
                    fi.Player2Id = y;
                    fi.Stage     = stageNames[rng.Next(stageNames.Length)];

                    if (!fights.Contains(fi))
                    {
                        fights.Add(fi);
                    }
                }
            }

            //Reihenfolge durchwürfeln
            for (int i = 0; i < fights.Count * 2; i++)
            {
                int idxA = rng.Next(fights.Count);
                int idxB = rng.Next(fights.Count);

                FightInfo helperVar = fights[idxA];
                fights[idxA] = fights[idxB];
                fights[idxB] = helperVar;
            }

            //Kämpfe austragen
            while (fights.Count > 0)
            {
                FightInfo current = fights[0];
                fights.RemoveAt(0);
                WinningTeam wt = Fight(current.Player1, current.Player2, current.Stage);
                switch (wt)
                {
                case WinningTeam.Player1:
                    scoreboard[current.Player1Id][current.Player2Id] = 1.0f;
                    scoreboard[current.Player2Id][current.Player1Id] = 0.0f;
                    break;

                case WinningTeam.Player2:
                    scoreboard[current.Player1Id][current.Player2Id] = 0.0f;
                    scoreboard[current.Player2Id][current.Player1Id] = 1.0f;
                    break;

                case WinningTeam.Draw:
                    scoreboard[current.Player1Id][current.Player2Id] = 0.5f;
                    scoreboard[current.Player2Id][current.Player1Id] = 0.5f;
                    break;

                default:
                    throw new NotImplementedException(wt.ToString());
                }
            }

            //Scoreboard speichern
            FileStream   outStream    = File.OpenWrite("output.csv");
            StreamWriter streamWriter = new StreamWriter(outStream, Encoding.ASCII);

            streamWriter.Write(";");
            for (int i = 0; i < charNames.Length; i++)
            {
                streamWriter.Write(charNames[i]);
                streamWriter.Write(";");
            }
            streamWriter.WriteLine();
            for (int y = 0; y < charNames.Length; y++)
            {
                streamWriter.Write(charNames[y]);
                streamWriter.Write(";");
                double score = 0.0f;
                for (int x = 0; x < charNames.Length; x++)
                {
                    if (scoreboard[y][x].HasValue)
                    {
                        streamWriter.Write(scoreboard[y][x].Value);
                        score += scoreboard[y][x].Value;
                    }
                    streamWriter.Write(";");
                }
                streamWriter.Write(score);
                streamWriter.Write(";");
                streamWriter.WriteLine(";");
            }
            streamWriter.Flush();
            streamWriter.Close();
            streamWriter.Dispose();
        }