コード例 #1
0
        static List <Tuentiverse> ParseInputFile(string path)
        {
            var input  = File.ReadAllLines(path);
            var output = new List <Tuentiverse>();

            if (input.Length <= 1)
            {
                throw new Exception("Error while parsing input file.");
            }

            for (int csid = 1, line = 1; line < input.Length; csid++)
            {
                var colnum = int.Parse(input[line++]);
                var colors = new Color[colnum];

                // Parse colors
                for (var cid = 0; cid < colnum; cid++)
                {
                    var bits = input[line++].Split(
                        new[] { ' ' },
                        StringSplitOptions.RemoveEmptyEntries
                        );

                    var name = bits[0];
                    var cnum = int.Parse(bits[1]);
                    var comp = new Color[cnum];

                    // Parse composites
                    for (var pid = 0; pid < cnum; pid++)
                    {
                        var cname = bits[2 + pid];
                        comp[pid] = colors.Where((x) => x.Name == cname).First();
                    }

                    colors[cid] = new Color((int)Math.Pow(2, cid), name, comp);
                }

                var galnum   = int.Parse(input[line++]);
                var galaxies = new Galaxy[galnum];

                // Parse galaxies
                for (var gid = 0; gid < galnum; gid++)
                {
                    var gcolnum = int.Parse(input[line++]);
                    var gcolors = new Color[gcolnum];

                    // Parse galaxy colors
                    for (var gcid = 0; gcid < gcolnum; gcid++)
                    {
                        var gcbits = input[line++].Split(
                            new[] { ' ' },
                            StringSplitOptions.RemoveEmptyEntries
                            );

                        var gcname = gcbits[0];
                        var gctime = int.Parse(gcbits[1]);

                        gcolors[gcid] = new Color(colors.Where((x) => x.Name == gcname).First())
                        {
                            Delay = gctime
                        };
                    }

                    galaxies[gid] = new Galaxy(gid, gcolors);
                }

                var wrmnum = int.Parse(input[line++]);
                var wrmhls = new Wormhole[wrmnum];

                // Parse wormholes
                for (var wid = 0; wid < wrmnum; wid++)
                {
                    var wbits = input[line++].Split(
                        new[] { ' ' },
                        StringSplitOptions.RemoveEmptyEntries
                        );

                    var wcolor = colors.Where((x) => x.Name == wbits[0]).First();
                    var worign = int.Parse(wbits[1]);
                    var wtargt = int.Parse(wbits[2]);

                    var gorign = galaxies[worign];
                    var gtargt = galaxies[wtargt];

                    var wormhole = new Wormhole(
                        wcolor, gorign, gtargt
                        );

                    wrmhls[wid] = wormhole;

                    gorign.Wormholes.Add(wormhole);
                    // gtargt.Wormholes.Add(wormhole);
                }

                output.Add(new Tuentiverse(csid, colors, galaxies, wrmhls));
            }

            return(output);
        }
コード例 #2
0
 public Wormhole(Color color, Galaxy origin, Galaxy target)
 {
     Color  = color;
     Origin = origin;
     Target = target;
 }