override public async void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        try
        {
            if (pathWalker == null)
            {
                pathWalker = animator.gameObject.GetComponent <PathWalker>();
            }
            if (behaviourDisplay == null)
            {
                behaviourDisplay = animator.gameObject.GetComponentInChildren <TextMesh>();
            }
            if (base_home == null)
            {
                base_home = GameManager.Instance.GetBase();
            }
            if (mineDetector == null)
            {
                mineDetector = animator.gameObject.GetComponentInChildren <MineDetector>();
            }

            behaviourDisplay.text = $"{ GetType() }";
            collectedGold         = animator.GetInteger("Gold");
            base_home             = GameManager.Instance.GetBase();

            SoundManager.Instance.PlaySound(Sound.Peasant_Yes_My_Lord_Sound_Effect);
            await pathWalker.WalkTo(base_home.transform.position);
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    }
    override public async void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        try
        {
            if (pathWalker == null)
            {
                pathWalker = animator.gameObject.GetComponent <PathWalker>();
            }
            if (behaviourDisplay == null)
            {
                behaviourDisplay = animator.gameObject.GetComponentInChildren <TextMesh>();
            }
            if (mineDetector == null)
            {
                mineDetector = animator.gameObject.GetComponentInChildren <MineDetector>();
            }
            if (creature == null)
            {
                creature = animator.gameObject.GetComponent <Creature>();
            }

            behaviourDisplay.text = $"{ GetType() }";
            await pathWalker.WalkTo(PathFinderManager.Instance.RandomWalkablePosition);
        }
        catch (Exception e)
        {
            Debug.LogError(e);
            OnStateEnter(animator, stateInfo, layerIndex);
        }
    }
Example #3
0
        public IEnumerable <Choice> GetChoices(IMineGame mineGame, MineDetector mineDetector)
        {
            var l = mineGame.AllCells()
                    .Where(c => !mineDetector.IsSureAMine(c) && mineGame.NeighboursMineCountAt(c) == null).ToList();
            var cellCoordinate = l[_random.Next(l.Count)];

            return(new[] { new Choice(cellCoordinate, 1) });
        }
Example #4
0
 private static IEnumerable <Choice> FindSafePlace(IMineGame mineGame, MineDetector mineDetector)
 {
     foreach (var point in mineGame.AllCells())
     {
         var neighbours  = mineGame.GetNeighbours(point).ToList();
         var minesCount1 = neighbours.Count(mineDetector.IsSureAMine);
         var minesCount2 = mineGame.NeighboursMineCountAt(point);
         if (minesCount1 == minesCount2)
         {
             foreach (var coordinate in neighbours.Where(
                          p => mineGame.NeighboursMineCountAt(p) == null && !mineDetector.IsSureAMine(p)))
             {
                 yield return(new Choice(coordinate, 0));
             }
         }
     }
 }
Example #5
0
 private void Start()
 {
     mineDetector = GetComponentInChildren <MineDetector>();
     mineDetector.checkCollisionMiner += OnCollisionDetect;
 }
Example #6
0
 public IEnumerable <Choice> GetChoices(IMineGame mineGame, MineDetector mineDetector)
 {
     return(GetCandidates(mineGame)
            .Where(c => mineGame.NeighboursMineCountAt(c) == null && !mineDetector.IsSureAMine(c))
            .Select(c => new Choice(c, 0.1)).ToList());
 }
Example #7
0
 public Core(IMineGame mineGame, MineDetector mineDetector)
 {
     Choices = FindSafePlace(mineGame, mineDetector).ToList();
 }
Example #8
0
 public IEnumerable <Choice> GetChoices(IMineGame mineGame, MineDetector mineDetector)
 {
     return(new Core(mineGame, mineDetector).Choices);
 }