Ejemplo n.º 1
0
        async static Task Main(string[] args)
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var seedArgIndex  = Array.IndexOf <string>(args, "-r") + 1;
            var jsonArgIndex  = Array.IndexOf <string>(args, "-s") + 1;
            var pathArgIndex  = Array.IndexOf <string>(args, "-f") + 1;
            var countArgIndex = Array.IndexOf <string>(args, "-c") + 1;

            var seed = seedArgIndex > 0 && args.Length > seedArgIndex && int.TryParse(args[seedArgIndex], out var arg)
                ? arg
                : Environment.TickCount;

            var random = new Pseudorandom(seed);

            const int size        = 3;
            var       shape       = new Hexagon(size);
            var       routeFinder = new RouteFinder(random, shape);

            var grid = new HexGrid(size, 0.3d, random);
            // var grid = new Grid(8, 0.3d, random);

            var pathJson = (string)null;

            if (jsonArgIndex > 0 && args.Length > jsonArgIndex)
            {
                pathJson = args[jsonArgIndex];
            }
            else if (pathArgIndex > 0 && args.Length > pathArgIndex && File.Exists(args[pathArgIndex]))
            {
                using var textReader = File.OpenText(args[pathArgIndex]);
                pathJson             = textReader.ReadToEnd();
            }

            var countJson = (string)null;

            if (countArgIndex > 0 && args.Length > countArgIndex)
            {
                countJson = args[countArgIndex];
            }

            if (!string.IsNullOrEmpty(pathJson))
            {
                var path = JsonConvert.DeserializeObject <List <Coordinates> >(pathJson);
                grid.SetSequence(path.Select(coord => (coord.X, coord.Y)));
            }
            else if (!string.IsNullOrEmpty(countJson))
            {
                var nodeCounts = JsonConvert.DeserializeObject <List <int> >(countJson);
                grid.SetNodeCounts(NodeCountHelper.MapNodeCounts(nodeCounts));
            }
            else
            {
                await routeFinder.Initiate();

                var nodeCounts = routeFinder.SelectNodeCount();
                grid.SetNodeCounts(NodeCountHelper.MapNodeCounts(nodeCounts));
            }

            Application.Run(new Canvas(grid, routeFinder));
        }