Ejemplo n.º 1
0
        public async void ExecuteQLearning()
        {
            string result = Learning.Execute(this);

            char[] steps = result.ToCharArray();
            foreach (char step in steps)
            {
                switch (step)
                {
                case 'u':
                    if (IsUnitCanMove(GetPlayerX(), GetPlayerY(), -1, 0))
                    {
                        PlayerMoveOne(-1, 0);
                    }
                    break;

                case 'd':
                    if (IsUnitCanMove(GetPlayerX(), GetPlayerY(), 1, 0))
                    {
                        PlayerMoveOne(1, 0);
                    }
                    break;

                case 'l':
                    if (IsUnitCanMove(GetPlayerX(), GetPlayerY(), 0, -1))
                    {
                        PlayerMoveOne(0, -1);
                    }
                    break;

                case 'r':
                    if (IsUnitCanMove(GetPlayerX(), GetPlayerY(), 0, 1))
                    {
                        PlayerMoveOne(0, 1);
                    }
                    break;
                }
                await Task.Delay(TimeSpan.FromSeconds(1));
            }
        }