bool eat(out SimpleFood lastFood, out int lastHunger, out Action job, out ActionsBase.UncertainEvent unc)
        {
            foreach (var s in Home.GetSurrounding(this, 1))
            {
                if (s.GetID == SimpleFood.id)
                {
                    lastFood   = (SimpleFood)s;
                    lastHunger = Hunger;

                    job = () =>
                    {
                        Hunger = Math.Min(MAXHUNGER, Hunger + MAXHUNGER / 2);
                        s.Dispose();

                        //Console.WriteLine($"I ({px},{py}) can eat ({s.PX},{s.PY})");
                    };
                    unc = new EatManager.SpawnFoodUncertain(
                        () =>
                    {
                        SimpleFood.SpawnRandomNormal(Home);
                        //Console.WriteLine("Ate something..");
                    });
                    //unc = new EatManager.SpawnFoodUncertain(() => My_FoodObj.SpawnRandom(Home));

                    return(true);
                }
            }

            job        = null; unc = null;
            lastHunger = -1;
            lastFood   = null;
            return(false);
        }
Пример #2
0
        public static SimpleFood SpawnRandomNormal(Field f)
        {
            //return null;
            const ushort pow = 1;

            //double normal(double x) => Math.Pow(x * 2 - 1, 2 * pow + 1) / 2.0 + 0.5;
            double normal(double x) => Math.Sqrt(Math.Log(1 / x));

            var me = new SimpleFood(f, normal);

            return(me);
        }