Example #1
0
        static void Main(string[] args)
        {
            using (var sim = new QuantumSimulator())
            {
                var result = Teleport.Run(sim).Result;
                Console.WriteLine(result);
            }

            Console.ReadLine();
        }
        public void TeleportQubitAllocationTest()
        {
            RunTest(sim =>
            {
                var qs = new QCTraceSimulator.TracerAllocate(sim).Apply(3);
                Teleport.Run(sim, qs[0], qs[1], qs[2]).Wait();

                var received  = sim.GetMetric <Teleport>(WidthCounter.Metrics.InputWidth);
                var returned  = sim.GetMetric <Teleport>(WidthCounter.Metrics.ReturnWidth);
                var allocated = sim.GetMetric <Teleport>(WidthCounter.Metrics.ExtraWidth);
                var borrowed  = sim.GetMetric <Teleport>(WidthCounter.Metrics.BorrowedWith);

                var summary = sim.ToCSV()[MetricsCountersNames.widthCounter];

                output.WriteLine("\nQubit usage for Teleport:");
                output.WriteLine($"Number of received qubits: {received}");
                output.WriteLine($"Number of returned qubits: {returned}");
                output.WriteLine($"Number of allocated qubits: {allocated}");
                output.WriteLine($"Number of borrowed qubits: {borrowed}");

                output.WriteLine("\nSummary in CSV format:");
                output.WriteLine(summary);
            });
        }
        public static void RunScript(string inputText)
        {
            var arr = inputText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

            for (var i = 0; i < arr.Length; i++)
            {
                var s = arr[i];

                var args = Regex
                           .Split(String.Join(" ", s), "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")
                           .Where(item => !string.IsNullOrEmpty(item))
                           .ToList();

                if (args.Count < 1)
                {
                    continue;
                }

                var cmd = args[0].Trim().ToLower();
                args.RemoveAt(0);

                if (cmd.StartsWith("#") || cmd.StartsWith("//") || cmd == string.Empty)
                {
                    continue;
                }

                switch (cmd)
                {
                case "spawn":
                    Spawn.Run(args, i);
                    break;

                case "roundlock":
                    RoundSummary.RoundLock = true;
                    break;

                case "detonate":
                    ScriptActions.scriptData.detonate = true;
                    break;

                case "teleport":
                    Teleport.Run(args, i);
                    break;

                case "createclass":
                    CreateClass.Run(args, i);
                    break;

                case "clearitems":
                    ClearItems.Run(args, i);
                    break;

                case "give":
                    Give.Run(args, i);
                    break;

                case "infect":
                    Infect.Run(args, i);
                    break;

                case "hp":
                    HP.Run(args, i);
                    break;

                case "scale":
                    Scale.Run(args, i);
                    break;

                case "disabledecontamination":
                    DisableDecontamination.Run(args, i);
                    break;

                case "last":
                    Last.Run(args, i);
                    break;

                case "cassie":
                    TextCommand.Run(args, i, "cassie");
                    break;

                case "broadcast":
                    TextCommand.Run(args, i, "broadcast");
                    break;

                case "hint":
                    TextCommand.Run(args, i, "hint");
                    break;

                case "lights":
                    Lights.Run(args, i);
                    break;

                case "disabledetonation":
                    DisableDetonation.Run(args, i);
                    break;

                case "escape":
                    Commands.Escape.Run(args, i);
                    break;

                default:
                    throw new InvalidCommandException("The command \"" + cmd + "\" on line " + i + " was not found.");
                }
            }
        }