Esempio n. 1
0
 public IEnumerable <Game> Run()
 {
     foreach (MatchRecord gameRecord in GameList)
     {
         PendingGames.Enqueue(gameRecord);
     }
     while (PendingGames.Count > 0)
     {
         MatchRecord currentGameRecord = PendingGames.Dequeue();
         if (currentGameRecord.SavedGameFile != null)
         {
             if (File.Exists(CurrentPath + Path.DirectorySeparatorChar + currentGameRecord.SavedGameFile))
             {
                 System.GC.Collect();
                 TextReader reader = new StreamReader(CurrentPath + Path.DirectorySeparatorChar + currentGameRecord.SavedGameFile);
                 Game       game   = Manager.LoadGame(reader);
                 reader.Close();
                 game.StartMatch();
                 game.ComputerControlled[0] = true;
                 game.ComputerControlled[1] = true;
                 game.AddInternalEngine(0);
                 game.AddInternalEngine(1);
                 TimeControl timeControl = new TimeControl(currentGameRecord.TimeControl);
                 game.Match.SetTimeControl(timeControl);
                 yield return(game);
             }
             else
             {
                 throw new Exception("Cannot find saved game: " + currentGameRecord.SavedGameFile);
             }
         }
     }
 }
Esempio n. 2
0
        public MatchSet LoadMatches(TextReader reader, string defaultPath)
        {
            Dictionary <string, int> dataFileColumnMap = new Dictionary <string, int>();
            MatchSet matchSet = new MatchSet();

            //	read the header row
            string input = reader.ReadLine();

            //	parse the headers
            string[] split = input.Split('\t');
            for (int x = 0; x < split.Length; x++)
            {
                dataFileColumnMap.Add(split[x].ToUpper(), x);
            }
            if (!dataFileColumnMap.ContainsKey("GAME"))
            {
                throw new Exception("LoadMatches: column 'Game' is required");
            }
            if (!dataFileColumnMap.ContainsKey("ENGINE1"))
            {
                throw new Exception("LoadMatches: column 'Engine1' is required");
            }
            if (!dataFileColumnMap.ContainsKey("ENGINE2"))
            {
                throw new Exception("LoadMatches: column 'Engine2' is required");
            }
            if (!dataFileColumnMap.ContainsKey("TIME CONTROL"))
            {
                throw new Exception("LoadMatches: column 'Time Control' is required");
            }

            int gameNumber = 1;

            while ((input = reader.ReadLine()) != null)
            {
                string[] parts = input.Split('\t');
                if (parts.Length != dataFileColumnMap.Count)
                {
                    throw new Exception("LoadMatches: Incorrect number of elements - expected " +
                                        dataFileColumnMap.Count.ToString() + " but found " + parts.Length.ToString());
                }
                MatchRecord record = new MatchRecord();
                record.ID = dataFileColumnMap.ContainsKey("ID")
                                        ? parts[dataFileColumnMap["ID"]]
                                        : gameNumber.ToString() + ".";

                string game = parts[dataFileColumnMap["GAME"]];
                record.SavedGameFile  = Path.IsPathRooted(game) ? game : Path.Combine(defaultPath, game);
                record.TimeControl    = parts[dataFileColumnMap["TIME CONTROL"]];
                record.EngineNames[0] = parts[dataFileColumnMap["ENGINE1"]];
                record.EngineNames[1] = parts[dataFileColumnMap["ENGINE2"]];
                record.PlayerNames[0] = dataFileColumnMap.ContainsKey("PLAYER1") ? parts[dataFileColumnMap["PLAYER1"]] : parts[dataFileColumnMap["ENGINE1"]];
                record.PlayerNames[1] = dataFileColumnMap.ContainsKey("PLAYER2") ? parts[dataFileColumnMap["PLAYER2"]] : parts[dataFileColumnMap["ENGINE2"]];
                record.Variation      = 0;
                if (dataFileColumnMap.ContainsKey("VARIATION"))
                {
                    if (parts[dataFileColumnMap["VARIATION"]].ToUpper() == "NONE" || parts[dataFileColumnMap["VARIATION"]] == "0")
                    {
                        record.Variation = 0;
                    }
                    if (parts[dataFileColumnMap["VARIATION"]].ToUpper() == "SMALL" || parts[dataFileColumnMap["VARIATION"]] == "1")
                    {
                        record.Variation = 1;
                    }
                    if (parts[dataFileColumnMap["VARIATION"]].ToUpper() == "MEDIUM" || parts[dataFileColumnMap["VARIATION"]] == "2")
                    {
                        record.Variation = 2;
                    }
                    if (parts[dataFileColumnMap["VARIATION"]].ToUpper() == "LARGE" || parts[dataFileColumnMap["VARIATION"]] == "3")
                    {
                        record.Variation = 3;
                    }
                }
                matchSet.Add(record);
                gameNumber++;
            }
            return(matchSet);
        }