예제 #1
0
 protected override void OnSimObjectUpdating(SimObject simObject, SimModel simModel, SimState simState)
 {
     if (Prey != null && (!CanBeVictim(Prey) || simObject.Location.GetDistance(Prey.Location) > ViewDistance))
     {
         if (CanBeVictim(Prey))
         {
             Prey.Color = Colors.Black;
         }
         Prey = null;
         GiveRandomDirection(simObject, simObject.Velocity.VectorMagnitude());
     }
     if (Prey == null)
     {
         Prey = GetObjectsInView(simModel, simObject)
                .Where(CanBeVictim)
                .FirstOrDefault();
     }
     if (Prey != null)
     {
         Prey.Color = Colors.Green;
         SetDestination(Prey.Location, simObject);
         var energy = simObject.GetProperty <EnergyProperty>();
         if (energy != null && energy.Energy > 15)
         {
             UpdateSpeed(RunSpeed, simObject);
         }
     }
 }
예제 #2
0
        public ActionResult Index2(int user1, int user2)
        {
            var model = new SimModel();

            var products = recoEntities.Products.ToList();
            var user1P   = recoEntities.UserProducts.Where(x => x.UserId == user1).Select(x => x.ProductId).ToList();
            var user2P   = recoEntities.UserProducts.Where(x => x.UserId == user2).Select(x => x.ProductId).ToList();

            foreach (var prod in products)
            {
                if (user1P.Contains(prod.Id))
                {
                    model.ProductsUser1.Add(prod.Nume);
                }
                else
                {
                    model.ProductsUser1.Add("-");
                }
                if (user2P.Contains(prod.Id))
                {
                    model.ProductsUser2.Add(prod.Nume);
                }
                else
                {
                    model.ProductsUser2.Add("-");
                }
            }

            return(View(model));
        }
예제 #3
0
        protected override void OnSimObjectUpdating(SimObject simObject, SimModel simModel, SimState simState)
        {
            if (_halt)
            {
                return;
            }

            var bouncedRecently = simState.MillisecondsSinceSimStart - _lastBounce < 2000;

            if (!bouncedRecently && _canHuntNectar)
            {
                simObject.Color = Colors.Black;
                var closestStaticObjectWithNectar = simModel.GetSimObjectsCopy()
                                                    .Where(x => x.Velocity.IsZero && x.Location.GetDistance(simObject.Location) < MaxViewDistance)
                                                    .Select(x => new { SimObject = x, Nectar = x.GetProperty <NectarProperty>() })
                                                    .Where(x => x.Nectar != null && x.Nectar.HasNectar)
                                                    .Select(x => x.SimObject)
                                                    .FirstOrDefault();

                if (closestStaticObjectWithNectar != null)
                {
                    simObject.Velocity = simObject.Location.GetDirection(closestStaticObjectWithNectar.Location).ScalarMultiply(Speed);
                }
            }
        }
예제 #4
0
 protected IEnumerable <SimObject> GetObjectsInView(SimModel simModel, SimObject simObject)
 {
     return(simModel.SimObjects
            .Select(sim => new { sim, Distance = simObject.Location.GetDistance(sim.Location) })
            .Where(x => x.sim != simObject && x.Distance < ViewDistance)
            .OrderBy(x => x.Distance)
            .Select(x => x.sim));
 }
예제 #5
0
        public void ReturnFalseAndNull_WhenParseFailed(string fileName)
        {
            var json = File.ReadAllText($"{projectPath}\\Tests\\data\\{fileName}");

            var result = SimModel.TryParse(json, out var data);

            result.Should().BeFalse();
            data.Should().BeNull();
        }
예제 #6
0
        private void StartBeeSimulator(object sender, RoutedEventArgs e)
        {
            var gameState = new SimModel(new CollisionDetection(), new Random());

            gameState.CreateHiveAndFlower(ScreenWidth / 2, ScreenHeight / 2);

            var simulation = new SimulationRunner(gameState);

            simulation.Start("Bee Simulation");
        }
예제 #7
0
        public void Work_Correctly(string fileName)
        {
            var input          = File.ReadAllText($"{assemblyPath}\\Tests\\data\\{fileName}.in");
            var expectedOutput = File.ReadLines($"{assemblyPath}\\Tests\\data\\{fileName}.out");

            SimModel.TryParse(input, out var data);
            var result = new SimQueryExecutor(data).ExecuteQueries();

            result.Should().BeEquivalentTo(expectedOutput);
        }
예제 #8
0
        protected override void OnSimObjectUpdating(SimObject simObject, SimModel simModel, SimState simState)
        {
            var nectarProp = simObject.GetProperty <NectarProperty>();

            if (nectarProp == null)
            {
                nectarProp = new NectarProperty();
                simObject.Properties.Add(nectarProp);
            }
            nectarProp.FillNectar();
        }
예제 #9
0
        protected override void OnSimObjectUpdating(SimObject simObject, SimModel simModel, SimState simState)
        {
            var energy = simObject.GetProperty <EnergyProperty>();

            if (energy == null)
            {
                return;
            }
            var magnitude = simObject.Velocity.VectorMagnitude();

            energy.UseEnergy(magnitude * simState.MillisecondsSinceLastUpdate / 1000.0);
        }
예제 #10
0
파일: Program.cs 프로젝트: pajcak/fluidsim
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ISimModel      model      = new SimModel();
            ISimView       view       = new SimView();
            ISimController controller = new SimController(model, view);

            //start a new thread with controller.simulate()
            //throw new NotImplementedException();
            Application.Run(view.mainWindow);
            // NEED TO START NEW THREAD FOR SIMULATION
        }
예제 #11
0
 protected override void OnSimObjectUpdating(SimObject simObject, SimModel simModel, SimState simState)
 {
     if (Bees.Count < 30 && Bees.Count < simState.MillisecondsSinceSimStart / 1000.0)
     {
         var bee = new Actor(SpawnLocation);
         if (simModel.DetectCollisions(bee).Any())
         {
             return;
         }
         bee.Behaviours.Add(new BeeBehaviour(_random, simObject));
         bee.Behaviours.Add(new NectarCarrierBehaviour());
         Bees.Add(bee);
         simModel.AddSimObject(bee);
     }
 }
예제 #12
0
        protected override void OnSimObjectCollision(SimObject sender, SimModel simModel, SimState simState, List <SimObject> collidingObjects)
        {
            var myNectar = sender.GetProperty <NectarProperty>();

            if (myNectar != null && !myNectar.HasNectar)
            {
                foreach (var collidingObject in collidingObjects)
                {
                    var theirNectar = collidingObject.GetProperty <NectarProperty>();
                    if (myNectar.GetNectarFrom(theirNectar))
                    {
                        return;
                    }
                }
            }
        }
예제 #13
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            // Do not access the form's BackgroundWorker reference directly.
            // Instead, use the reference provided by the sender parameter.
            BackgroundWorker bw = sender as BackgroundWorker;

            // Extract the argument.
            SimModel model = (SimModel)e.Argument;

            // Start the time-consuming operation.
            ModellingProcess(bw, model);
            // If the operation was canceled by the user,
            // set the DoWorkEventArgs.Cancel property to true.
            if (bw.CancellationPending)
            {
                e.Cancel = true;
            }
        }
예제 #14
0
 protected override void OnSimObjectCollision(SimObject sender, SimModel simModel, SimState simState, List <SimObject> collidingObjects)
 {
     foreach (var collidingObject in collidingObjects)
     {
         foreach (var behaviour in collidingObject.Behaviours.ToList())
         {
             if (!(behaviour is ZombieBehaviour))
             {
                 collidingObject.Behaviours.Remove(behaviour);
                 collidingObject.Behaviours.Add(new ZombieBehaviour(Random));
                 Prey = null;
                 var energyProp = sender.GetProperty <EnergyProperty>();
                 energyProp.AddEnergy(10);
             }
         }
     }
     GiveRandomDirection((Actor)sender, Speed);
 }
예제 #15
0
        // GET: Sim
        public ActionResult Index(int userId)
        {
            var model = new SimModel();

            model.UserId = userId;

            var similarities           = getAllUsersSimilarity(userId);
            var descendingSimilarities = similarities.OrderByDescending(x => x.Similarity);

            model.Similarities = descendingSimilarities.ToList();

            foreach (var sim in model.Similarities)
            {
                var user = recoEntities.Users.Single(x => x.Id == sim.UserId);
                sim.UserName = user.Forename + " " + user.Surname;
            }

            return(View(model));
        }
예제 #16
0
        protected override void OnSimObjectUpdating(SimObject simObject, SimModel simModel, SimState simState)
        {
            //Energy += Math.Max(MaxEnergy,elapsedMilliseconds/1000.0 / 5);
            //var magnitude = simObject.Velocity.VectorMagnitude();
            //if (magnitude > Speed)
            //{
            //    Energy -= magnitude * elapsedMilliseconds / 1000.0;
            //}
            //var runningObject = GetObjectsInView(gameState, simObject)
            //    .FirstOrDefault(x => x.Velocity.VectorMagnitude() > Speed);

            //if (runningObject == null || Energy < 10)
            //{
            //    simObject.Velocity = simObject.Velocity.UnitVector().ScalarMultiply(Speed);
            //}
            //else
            //{
            //    simObject.Velocity = runningObject.Velocity.UnitVector().ScalarMultiply(RunSpeed);
            //}
        }
예제 #17
0
 public SimulationRunner(SimModel simModel)
 {
     _simModel = simModel;
 }
예제 #18
0
 protected override void OnSimObjectCollision(SimObject sender, SimModel simModel, SimState simState, List <SimObject> collidingObjects)
 {
     GiveRandomDirection(sender, Speed);
 }
 public GameStateUpdateEventArgs(SimModel simModel, SimState simState)
 {
     SimModel = simModel;
     SimState = simState;
 }
예제 #20
0
 // This method models an operation that may take a long time
 // to run. It can be cancelled, it can raise an exception,
 // or it can exit normally and return a result. These outcomes
 // are chosen randomly.
 private void ModellingProcess(BackgroundWorker bw, SimModel model)
 {
     model.Run();
 }
예제 #21
0
 protected override void OnSimObjectCollision(SimObject sender, SimModel simModel, SimState simState, List <SimObject> collidingObjects)
 {
     _lastBounce = simState.MillisecondsSinceSimStart;
     GiveRandomDirection(sender, Speed);
 }