Ejemplo n.º 1
0
        internal IEnumerable <IScenario> Convert(string mapFilepath, string scenFilepath, int maxScenario = int.MaxValue)
        {
            var scenarioList = new List <Scenario>();

            if (!File.Exists(mapFilepath) || !File.Exists(scenFilepath))
            {
                return(scenarioList);
            }

            using var streamReader = new StreamReader(new FileStream(scenFilepath, FileMode.Open));
            string line           = streamReader.ReadLine(); //skip first line of scenario file as useless.
            var    scenarioParams = new ScenarioParams()
            {
                FilePath = mapFilepath,
                MapType  = MapTypes.Grid
            };

            for (int i = 0; i < maxScenario && !streamReader.EndOfStream; i++)
            {
                var fileScenario = new FileScenario(streamReader.ReadLine().Split('\t'));
                scenarioParams.ScenarioName   = i.ToString();
                scenarioParams.Start          = new GridNode(fileScenario.StartX, fileScenario.StartY);
                scenarioParams.End            = new GridNode(fileScenario.EndX, fileScenario.EndY);
                scenarioParams.ExpectedLength = fileScenario.ExpectedLength;
                var scen = new Scenario();
                scen.TrySetScenario(scenarioParams);
                scenarioList.Add(scen);
            }

            return(scenarioList);
        }
Ejemplo n.º 2
0
 public virtual MethodResult TrySetScenario(ScenarioParams @params)
 {
     IsSet   = false;
     _params = @params;
     Map     = MapSingleton.Instance.GetMap(_params.FilePath, _params.MapType);
     if (Map is EmptyMapWithError)
     {
         return(new MethodResult(false, Map.ToString()));
     }
     if (!Map.IsValidInMap(Start))
     {
         return(new MethodResult(false, "Invalid Start Point. Is either on a position which it cannot be or out of the map"));
     }
     if (!Map.IsValidInMap(End))
     {
         return(new MethodResult(false, "Invalid Stop Point. Is either on a position which it cannot be or out of the map"));
     }
     IsSet = true;
     return(MethodResult.WithSuccess);
 }