示例#1
0
        /// <summary>
        /// Builds a new life form.
        /// </summary>
        /// <param name="lifeFormType">The life form type to build.</param>
        /// <returns>A newly instantiated life form object.</returns>
        public static LifeFormBase Build(LifeForm lifeFormType)
        {
            LifeFormBase lifeForm = null;

            switch (lifeFormType)
            {
            case LifeForm.Empty:
                lifeForm = new Empty();
                break;

            case LifeForm.Acorn:
                lifeForm = new Acorn();
                break;

            case LifeForm.AircraftCarrier:
                lifeForm = new AircraftCarrier();
                break;

            case LifeForm.FivePoint:
                lifeForm = new FivePoint();
                break;

            default:
                lifeForm = new RandomPattern(
                    rows: RANDOMPATTERNHEIGHT,
                    cols: RANDOMPATTERNWIDTH);
                break;
            }

            return(lifeForm);
        }
示例#2
0
        /// <summary>
        /// Builds a new life form.
        /// </summary>
        /// <param name="lifeFormType">The life form type to build.</param>
        /// <returns>A newly instantiated life form object.</returns>
        public static LifeFormBase Build(LifeForm lifeFormType)
        {
            LifeFormBase lifeForm = null;
            switch (lifeFormType)
            {
                case LifeForm.Empty:
                    lifeForm = new Empty();
                    break;

                case LifeForm.Acorn:
                    lifeForm = new Acorn();
                    break;

                case LifeForm.AircraftCarrier:
                    lifeForm = new AircraftCarrier();
                    break;

                case LifeForm.FivePoint:
                    lifeForm = new FivePoint();
                    break;

                default:
                    lifeForm = new RandomPattern(
                        rows: RANDOMPATTERNHEIGHT,
                        cols: RANDOMPATTERNWIDTH);
                    break;
            }

            return lifeForm;
        }
示例#3
0
 public void Mutate(SkillTypes aSkillType, Int32 aNewValue, LifeForm aLifeForm)
 {
     if ((aLifeForm.LfType == LifeFormTypes.MasterEntity) || (aLifeForm.LfType == LifeFormTypes.EnvironmentEntity))
     {
         Mutate(aSkillType, aNewValue);
     }
 }
示例#4
0
 //LifeformDied callback
 private void OnLifeformDied(LifeForm lifeform)
 {
     LifeformsAliveCount--;
     if (LifeformsAliveCount == 0 && AllLifeformsDead != null)
     {
         AllLifeformsDead();
     }
 }
示例#5
0
    void Start()
    {
        this.lifeForm = this.GetComponentInChildren <LifeForm>();
        this.sr       = this.GetComponentInChildren <SpriteRenderer>();

        this.lifeForm.deathEvent += Die;

        ResetState();
    }
示例#6
0
        public GameOfLife(int worldSize, Pattern lifePattern, int numOfGenerations, int consolePrintSleep)
        {
            var world = new World(worldSize)
                        .SetPattern(lifePattern);

            life = new LifeForm(world);

            this.numOfGenerations  = numOfGenerations;
            this.consolePrintSleep = consolePrintSleep;
        }
        public override Task <Location> BeamDown(LifeForm request, ServerCallContext context)
        {
            // Uncomment to test the client deadline.
            // Task.Delay(60000).Wait();

            return(Task.FromResult(new Location
            {
                Description = Data.Locations.WhereEver()
            }));
        }
示例#8
0
    void Start()
    {
        this.sr       = this.GetComponent <SpriteRenderer>();
        this.lifeForm = this.GetComponent <LifeForm>();

        this.mapManager = MapManager.GetMapManager();

        this.lifeForm.deathEvent += Die;

        StartCoroutine(Spread());
    }
        public override Task <LifeForm> BeamUp(Location request, ServerCallContext context)
        {
            var whoEver = Data.LifeForms.WhoEver();
            var result  = new LifeForm
            {
                Species = whoEver.Item1,
                Name    = whoEver.Item2,
                Rank    = whoEver.Item3
            };

            return(Task.FromResult(result));
        }
示例#10
0
 public override void ManageMasterNotification(NotificationType aNotifyType, LifeForm aLifeForm)
 {
     switch (aNotifyType)
     {
         case Life.NotificationType.Born:
             if (!ManagedOnes.ContainsValue(aLifeForm))
                 ManagedOnes.Add(aLifeForm.dna.Id, aLifeForm);
             break;
         case Life.NotificationType.Dead:
             if (ManagedOnes.ContainsValue(aLifeForm))
                 ManagedOnes.Remove(aLifeForm.dna.Id);
             break;
     }
 }
示例#11
0
        private async void ReplaceParty_Click(object sender, RoutedEventArgs e)
        {
            // Creating a party.
            var rnd       = _rnd.Next(2, 5);
            var lifeForms = new List <LifeForm>();

            for (int i = 0; i < rnd; i++)
            {
                var whoEver  = Data.LifeForms.WhoEver();
                var lifeForm = new LifeForm
                {
                    Species = whoEver.Item1,
                    Name    = whoEver.Item2,
                    Rank    = whoEver.Item3
                };

                lifeForms.Add(lifeForm);
            }

            WriteLog($"Replacing a party.");
            using (var call = _client.ReplaceParty())
            {
                var responseReaderTask = Task.Run(async() =>
                {
                    while (await call.ResponseStream.MoveNext())
                    {
                        var beamedDown = call.ResponseStream.Current;
                        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                        {
                            WriteLog($"- Beamed down {beamedDown.Rank} {beamedDown.Name} ({beamedDown.Species}).");
                        });
                    }
                });

                foreach (var request in lifeForms)
                {
                    await call.RequestStream.WriteAsync(request);

                    WriteLog($"- Beamed up {request.Rank} {request.Name} ({request.Species}).");
                }
                ;

                await call.RequestStream.CompleteAsync();

                await responseReaderTask;
            }

            WriteLog($"- Party replaced.");
        }
示例#12
0
    void Start()
    {
        this.cpu      = this.GetComponent <CPU>();
        this.rb       = this.GetComponent <Rigidbody2D>();
        this.sr       = this.GetComponent <SpriteRenderer>();
        this.lifeForm = this.GetComponent <LifeForm>();
        this.toc      = this.GetComponent <TriggerObservationCompiler>();

        this.mapManager = MapManager.GetMapManager();
        this.opm        = ObjectPoolManager.GetObjectPoolManager();

        this.lifeForm.deathEvent += Die;

        ResetState();
    }
示例#13
0
        public override void Execute()
        {
            using (LifeForm frm = new LifeForm()) {
                frm.Viewer.Options.LS_LifeGame = fLangMan.LS(PLS.LSID_LifeGame);
                frm.Viewer.Options.LS_Step     = fLangMan.LS(PLS.LSID_Step);
                frm.Viewer.Options.LS_Start    = fLangMan.LS(PLS.LSID_Start);
                frm.Viewer.Options.LS_Stop     = fLangMan.LS(PLS.LSID_Stop);
                frm.Viewer.Options.LS_SetCells = fLangMan.LS(PLS.LSID_SetCells);
                frm.Viewer.Options.LS_Clear    = fLangMan.LS(PLS.LSID_Clear);
                frm.Viewer.Options.LS_Random   = fLangMan.LS(PLS.LSID_Random);
                frm.Viewer.Options.LS_Options  = fLangMan.LS(PLS.LSID_Options);

                frm.ShowDialog();
            }
        }
示例#14
0
        private async void BeamDownOne_Click(object sender, RoutedEventArgs e)
        {
            var whoEver  = Data.LifeForms.WhoEver();
            var lifeForm = new LifeForm
            {
                Species = whoEver.Item1,
                Name    = whoEver.Item2,
                Rank    = whoEver.Item3
            };

            // var location = _client.BeamDown(lifeForm);
            // Uncomment the delay in the Service method to test the deadline.
            var location = await _client.BeamDownAsync(lifeForm, deadline : DateTime.UtcNow.AddSeconds(5));

            WriteLog($"Beamed down {lifeForm.Rank} {lifeForm.Name} ({lifeForm.Species}) to {location.Description}.");
        }
示例#15
0
    void Reproduce()
    {
        LifeForm offspring = (LifeForm)Instantiate(this, GetOffspringPosition(), Quaternion.identity);//Todo Make an entity

        if (Random.Range(0f, 100f) < mutationChance)
        {
            //Spawn another LifeForm with a varied stat
            int rand = Random.Range(1, 7);

            switch (rand)
            {
            case 1:
                offspring.MutateReproductionRate();
                break;

            case 2:
                offspring.MutateDeathRate();
                break;

            case 3:
                offspring.MutateMutationChance();
                break;

            case 4:
                offspring.MutateMoveSpeed();
                break;

            case 5:
                offspring.MutateVision();
                break;

            case 6:
                offspring.MutateSize();
                break;

            case 7:
                offspring.MutateEatRange();
                break;

            default:
                break;
            }

            offspring.MutateColor();
        }
        WorldProperties.world.newBornQueue.Add(offspring);
    }
        public override async Task BeamUpParty(Location request, IServerStreamWriter <LifeForm> responseStream, ServerCallContext context)
        {
            var rnd = _rnd.Next(2, 5);

            for (int i = 0; i < rnd; i++)
            {
                var whoEver = Data.LifeForms.WhoEver();
                var result  = new LifeForm
                {
                    Species = whoEver.Item1,
                    Name    = whoEver.Item2,
                    Rank    = whoEver.Item3
                };

                await responseStream.WriteAsync(result);
            }
        }
示例#17
0
        public override void ManageMasterNotification(NotificationType aNotifyType, LifeForm aLifeForm)
        {
            switch (aNotifyType)
            {
            case Life.NotificationType.Born:
                if (!LivingOnes.ContainsValue(aLifeForm))
                {
                    LivingOnes.Add(aLifeForm.dna.Id, aLifeForm);
                }
                break;

            case Life.NotificationType.Dead:
                if (LivingOnes.ContainsValue(aLifeForm))
                {
                    LivingOnes.Remove(aLifeForm.dna.Id);
                    DeadOnes.Add(aLifeForm.dna.Id, aLifeForm);
                }
                break;
            }
        }
示例#18
0
        private async void BeamDownParty_Click(object sender, RoutedEventArgs e)
        {
            var rnd       = _rnd.Next(2, 5);
            var lifeForms = new List <LifeForm>();

            for (int i = 0; i < rnd; i++)
            {
                var whoEver  = Data.LifeForms.WhoEver();
                var lifeForm = new LifeForm
                {
                    Species = whoEver.Item1,
                    Name    = whoEver.Item2,
                    Rank    = whoEver.Item3
                };

                lifeForms.Add(lifeForm);
            }

            WriteLog($"Beaming down a party.");

            using (var call = _client.BeamDownParty())
            {
                foreach (var lifeForm in lifeForms)
                {
                    await call.RequestStream.WriteAsync(lifeForm);

                    WriteLog($"- Beamed down {lifeForm.Rank} {lifeForm.Name} ({lifeForm.Species}).");
                }

                await call.RequestStream.CompleteAsync();

                var location = await call.ResponseAsync;

                WriteLog($"- Party beamed down to {location.Description}.");
            }
        }
示例#19
0
 public FoodLifeForm(LifeForm aMaster)
     : base(aMaster, LifeFormTypes.FoodTypeLifeForm)
 {
     FoodValue = GetAttribute(SkillTypes.FoodProductionRate);
     BeginMainTask();
 }
示例#20
0
 public EnvironmentLifeForm(LifeForm aMaster)
     : base(aMaster, LifeFormTypes.EnvironmentEntity)
 {
     BeginMainTask();
 }
示例#21
0
 public EnvironmentLifeForm(LifeForm aMaster, LifeFormTypes aLifeFormType)
     : base(aMaster, aLifeFormType)
 {
     BeginMainTask();
 }
示例#22
0
 public EnvironmentLifeForm(LifeForm aMaster, LifeFormTypes aLifeFormType, DNASequence aDna)
     : base(aMaster, aLifeFormType, aDna)
 {
     BeginMainTask();
 }
示例#23
0
 public override void NotifyMasterLifeForm(NotificationType aNotifyType, LifeForm aLifeForm)
 {
     ManageMasterNotification(aNotifyType, aLifeForm);
     base.NotifyMasterLifeForm(aNotifyType, aLifeForm);
 }
示例#24
0
 public static GenerationSet NewField(LifeForm[] Olds)
 {
     return null;
 }
示例#25
0
 public FoodLifeForm(LifeForm aMaster, LifeFormTypes aLifeFormType, DNASequence aDna)
     : base(aMaster, aLifeFormType, aDna)
 {
     FoodValue = GetAttribute(SkillTypes.FoodProductionRate);
     BeginMainTask();
 }