Example #1
0
        public void TestMutate()
        {
            Random.InitState(666);
            var e     = ExperienceExtensions.Load($"Assets/Scripts/Tests/Data/BasicExperience.json", true);
            var child = new Characteristics
            {
                Computation           = 50,
                Life                  = 50,
                Robustness            = 50,
                Energy                = 50,
                ReproductionCost      = 50,
                AnimalCharacteristics = new Characteristics.Types.AnimalCharacteristics
                {
                    Speed = 50,
                    RandomMovementRange = 50,
                    SightRange          = 50,
                    EatRange            = 50,
                    Metabolism          = 50,
                }
            };

            child.Mutate(e.AnimalCharacteristics, e.AnimalCharacteristics,
                         e.AnimalCharacteristicsMinimumBound, e.AnimalCharacteristicsMaximumBound);
            // The offspring should have different characteristics
            Assert.False(AreObjectFloatsEqual(child, e.AnimalCharacteristics)); // TODO: fix this assert
            // TODO: could go further: assert that it stays within a distribution while differing from the initial value
            // TODO: why ? could have hard coded stuff but mutation rate and range might change
        }
Example #2
0
        public void LoadExperience()
        {
            var e = ExperienceExtensions.Load($"Assets/Scripts/Tests/Data/BasicExperience.json", true);

            Debug.Log(e);
            Assert.NotNull(e);
        }
Example #3
0
 public IEnumerator RenderExperience() => UniTask.ToCoroutine(async() =>
 {
     Debug.Log($"Press escape to continue");
     var go = new GameObject("AnimalCharacteristics");
     var e  = ExperienceExtensions.Load($"Assets/Scripts/Tests/Data/BasicExperience.json", true);
     Assert.NotNull(e);
     Helper.RenderExperience(e);
     // TODO: assert stuff ...
     await UniTask.WaitUntil(() => Keyboard.current.escapeKey.wasPressedThisFrame);
     Object.DestroyImmediate(go);
 });
        protected override void Start()
        {
            base.Start();
            var expDir = $"{Application.persistentDataPath}/Experiences";

            if (!Directory.Exists(expDir)) // TODO: could load on Show() ...
            {
                Debug.Log($"Creating directory {expDir}");
                Directory.CreateDirectory(expDir);
            }

            var experiences = Directory.GetFiles(expDir);

            foreach (var experienceFile in experiences)
            {
                var e = ExperienceExtensions.Load(experienceFile, true);
                AddExperienceMenu(e);
            }

            newExperienceButton.OnClick.AddListener(() =>
            {
                var e = ExperienceExtensions.New();
                AddExperienceMenu(e);
            });

            async void AddCommunityExperiences()
            {
                var communityExperiences = await Sm.instance.ListExperiences();

                foreach (var experience in communityExperiences.Objects)
                {
                    var parsedExperience = Experience.Parser.ParseJson(experience.Value);
                    var result           = await Sm.instance.Client.GetUsersAsync(Sm.instance.Session, new[] { experience.UserId });

                    AddExperienceMenu(parsedExperience, result.Users.FirstOrDefault()?.Username);
                    // TODO: doesn't scale @see cursor stuff in @Sm
                }

                // Just once
                Sm.instance.ConnectionSucceed -= AddCommunityExperiences;
            }

            Sm.instance.ConnectionSucceed += AddCommunityExperiences;
        }