Ejemplo n.º 1
0
    public async void Play()
    {
        await Task.Delay(1000);

        Skill walking = actor.GetMoveSkills().FirstOrDefault();

        if (walking != null && walking.area is Snake snake)
        {
            var reachableTiles = BoardUtils.AllReachableTiles(piece.on, maxLength: snake.maxRange, valid: CanStepOn);
            // TODO: Think
            var pair = reachableTiles.ToList().Random();
            if (pair.Key != piece.on)
            {
                SkillArea a = new SkillArea();
                a.AddRange(pair.Value);
                await SkillHandler.WALK.Apply(piece, a);
            }
        }

        var       skills        = actor.GetCoreSkills();
        float     bestHeuristic = 0;
        Skill     bestSkill     = null;
        SkillArea bestArea      = null;

        foreach (Skill skill in skills)
        {
            if (!skill.condition.IsValid())
            {
                continue;
            }
            // Try Cone
            skill.area.launcher = piece;
            if (skill.area is Cone cone)
            {
                foreach (Direction dir in DirectionUtils.DIRECTIONS)
                {
                    SkillArea area      = cone.SkillAreaIfTarget(dir);
                    float     heuristic = skill.effect.Heuristic(skill.element, piece, area);
                    if (heuristic > bestHeuristic)
                    {
                        bestHeuristic = heuristic;
                        bestArea      = area;
                        bestSkill     = skill;
                    }
                }
            }
            // Try Target
            else if (skill.area is Target target)
            {
                foreach (Tile tile in BoardUtils.AllTiles(t => target.CanSelect(t)))
                {
                    SkillArea area      = target.SkillAreaIfTarget(tile);
                    float     heuristic = skill.effect.Heuristic(skill.element, piece, area);
                    if (heuristic > bestHeuristic)
                    {
                        bestHeuristic = heuristic;
                        bestArea      = area;
                        bestSkill     = skill;
                    }
                }
            }
        }
        if (bestSkill != null)
        {
            await bestSkill.Apply(piece, bestArea);
        }
        Global.battle.NextTurn();
    }