Example #1
0
        public bool DebugStep(ParallelType pType = ParallelType.Sequential)
        {
            switch (pType)
            {
                case ParallelType.ParallelFree:
                case ParallelType.ParallelLockstep:
                    {
                        Parallel.ForEach(Dwarves.Where(dorf => !dorf.Dead), d =>
                        {
                            d.Turn(this);
                        });
                        break;
                    }
                case ParallelType.Sequential:
                default:
                    {
                        foreach (var d in Dwarves.Where(dorf => !dorf.Dead))
                        {
                            d.Turn(this);
                        }
                        break;
                    }
            }

            return Dwarves.Any(x => !x.Dead);
        }
Example #2
0
File: World.cs Project: Frib/Armok
        public bool DebugStep(ParallelType pType = ParallelType.Sequential)
        {
            switch (pType)
            {
            case ParallelType.ParallelFree:
            case ParallelType.ParallelLockstep:
            {
                Parallel.ForEach(Dwarves.Where(dorf => !dorf.Dead), d =>
                    {
                        d.Turn(this);
                    });
                break;
            }

            case ParallelType.Sequential:
            default:
            {
                foreach (var d in Dwarves.Where(dorf => !dorf.Dead))
                {
                    d.Turn(this);
                }
                break;
            }
            }

            return(Dwarves.Any(x => !x.Dead));
        }
Example #3
0
        public World Execute(string consoleInput, ParallelType pType = ParallelType.Sequential)
        {
            World world = new World(dwarves, routines);

            world.Run(consoleInput, pType);

            return world;
        }
Example #4
0
        public World Execute(string consoleInput, ParallelType pType = ParallelType.Sequential)
        {
            World world = new World(dwarves, routines);

            world.Run(consoleInput, pType);

            return(world);
        }
Example #5
0
File: World.cs Project: Frib/Armok
        public void Run(string consoleInput, ParallelType pType = ParallelType.Sequential)
        {
            sb    = new StringBuilder();
            input = consoleInput.ToArray();
            int turn = 0;

            switch (pType)
            {
            case ParallelType.ParallelFree:
            {
                Parallel.ForEach(Dwarves, d =>
                    {
                        int t = 0;
                        while (!d.Dead)
                        {
                            DoTurn(d, t);
                        }
                        t++;
                    });
                break;
            }

            case ParallelType.ParallelLockstep:
            {
                while (Dwarves.Any(x => !x.Dead))
                {
                    Parallel.ForEach(Dwarves.Where(dorf => !dorf.Dead), d =>
                        {
                            DoTurn(d, turn);
                        });
                    turn++;
                }
                break;
            }

            case ParallelType.Sequential:
            default:
            {
                while (Dwarves.Any(x => !x.Dead))
                {
                    foreach (var d in Dwarves.Where(dorf => !dorf.Dead))
                    {
                        d.Turn(this);
                        if (turn > 1000000)
                        {
                            d.Dead = true;
                            Trace.WriteLine(d.Name + " went berserk: infinite loop?");
                        }
                    }
                    turn++;
                }
                break;
            }
            }

            Trace.WriteLine("All dwarves are dead and/or stopped working after " + turn + " turns");
        }
Example #6
0
        private SMSProvider GetSMSProvider(ParallelType type)
        {
            SMSProvider provider;

            if (type.Equals(ParallelType.Thread))
            {
                provider = new SMSProviderThread();
            }
            else
            {
                provider = new SMSProviderTask();
            }
            return(provider);
        }
Example #7
0
        private Battery GetBattery(ParallelType type, IUserInOut userInOut)
        {
            Battery battery;
            int     capacity     = 5000;
            int     chargingTime = 60;

            if (type.Equals(ParallelType.Thread))
            {
                battery = new BatteryThread(capacity, chargingTime, userInOut);
            }
            else
            {
                battery = new BatteryTask(capacity, chargingTime, userInOut);
            }
            return(battery);
        }
Example #8
0
        public SimCorpMobile(IUserInOut userInOut) : base(userInOut)
        {
            int    micSensitivityRate = 70;
            string micBandwidth       = "40 - 20k Hz";

            vMicrophone = new Microphone(micSensitivityRate, micBandwidth, userInOut);

            int    outputPower      = 50;
            string speakerBandwidth = "20 - 18k Hz";

            vSpeaker = new Speaker(outputPower, speakerBandwidth, userInOut);

            CellularType cellModuleType  = CellularType.Lte;
            int          workingDistance = 1000;

            vCellModule = new CellularModule(cellModuleType, workingDistance, userInOut);

            int            screenHeight  = 1920;
            int            screenWidth   = 1080;
            ScreenType     screenType    = ScreenType.Lcd;
            int            brightness    = 73;
            int            contrast      = 57;
            IScreenProfile screenProfile = new BasicScreenProfile(brightness, contrast);

            vScreen = new TuningScreen(screenHeight, screenWidth, screenType, screenProfile, userInOut);

            int controlHeght         = 140;
            int controlWidth         = 68;
            int touchSensitivityRate = 90;

            vMultiTouchPanel = new MultiTouchPanel(controlHeght, controlWidth, touchSensitivityRate, userInOut);

            vMessageStorage = new MessageStorage {
                Contacts = new List <Contact> {
                    new Contact("John", 380101),
                    new Contact("Nick", 380102),
                    new Contact("Emma", 380103)
                }
            };

            ParallelType type = ParallelType.Task;

            vSMSProvider = GetSMSProvider(type);
            vBattery     = GetBattery(type, userInOut);
        }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object"/> class.
 /// </summary>
 public ParallelisationOptions(ParallelType type = ParallelType.None, int threshold = 0, int maxDegreeOfParallisation = 0)
 {
     _type      = type;
     _threshold = threshold;
 }
Example #10
0
        public World Debug(ParallelType pType = ParallelType.Sequential)
        {
            World world = new World(dwarves, routines);

            return world;
        }
Example #11
0
        public World Debug(ParallelType pType = ParallelType.Sequential)
        {
            World world = new World(dwarves, routines);

            return(world);
        }
Example #12
0
        public void Run(string consoleInput, ParallelType pType = ParallelType.Sequential)
        {
            sb = new StringBuilder();
            input = consoleInput.ToArray();
            int turn = 0;

            switch (pType)
            {
                case ParallelType.ParallelFree:
                    {
                        Parallel.ForEach(Dwarves, d =>
                            {
                                int t = 0;
                                while (!d.Dead)
                                {
                                    DoTurn(d, t);
                                }
                                t++;
                            });
                        break;
                    }

                case ParallelType.ParallelLockstep:
                    {
                        while (Dwarves.Any(x => !x.Dead))
                        {
                            Parallel.ForEach(Dwarves.Where(dorf => !dorf.Dead), d =>
                            {
                                DoTurn(d, turn);
                            });
                            turn++;
                        }
                        break;
                    }
                case ParallelType.Sequential:
                default:
                    {
                        while (Dwarves.Any(x => !x.Dead))
                        {
                            foreach (var d in Dwarves.Where(dorf => !dorf.Dead))
                            {
                                d.Turn(this);
                                if (turn > 1000000)
                                {
                                    d.Dead = true;
                                    Trace.WriteLine(d.Name + " went berserk: infinite loop?");
                                }
                            }
                            turn++;
                        }
                        break;
                    }

            }

            Trace.WriteLine("All dwarves are dead and/or stopped working after " + turn + " turns");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object"/> class.
 /// </summary>
 public ParallelisationOptions(ParallelType type = ParallelType.None, int threshold = 0, int maxDegreeOfParallisation = 0)
 {
     _type = type;
     _threshold = threshold;
 }
Example #14
0
 public BTParallel(ParallelType _type, BTPrecondition _precondition) : base(_precondition)
 {
     resList  = new List <BTResult>();
     paraType = _type;
 }
Example #15
0
 public BTParallel(ParallelType _type) : this(_type, null)
 {
 }