Esempio n. 1
0
        public override double AIScore(TurnContext context, ActionSelectionAI weights)
        {
            Element self = context.Element;
            var     mDS  = self?.GetData <MapData>();
            var     mA   = self.GetData <MapAwareness>();

            // TEMP:
            Element target = ((RLState)context.State).Controlled;
            var     mDT    = target?.GetData <MapData>();

            if (mDT != null && !target.IsDeleted && mA.AwarenessOfCell(mDT.MapCell.Index) > 0)
            {
                // Distance calculation:
                double manDist = mDS.Position.DistanceTo(mDT.Position);
                // Works for sword slash, but need more detail for other things:
                if (manDist < 2) //TEMP
                {
                    return(1.5); // 0.5 + context.RNG.NextDouble() * 1;
                }
            }
            return(-0.5);
        }
Esempio n. 2
0
        /// <summary>
        /// Process the start of the turn
        /// </summary>
        /// <param name="element"></param>
        public void StartTurnOf(Element element)
        {
            var context = new TurnContext(this, Stage, element, RNG);

            Active = element;
            for (int i = 0; i < element.Data.Count; i++)
            {
                IElementDataComponent dC = element.Data[i];
                if (dC is IStartOfTurn)
                {
                    ((IStartOfTurn)dC).StartOfTurn(context);
                }
                if (dC is IDeletable && ((IDeletable)dC).IsDeleted)
                {
                    element.Data.RemoveAt(i);
                    i--;
                }
            }

            if (element != Controlled)
            {
                var        ai      = new ActionSelectionAI(); //TEMP?
                var        actions = element.GetData <AvailableActions>();
                GameAction tAction = ai.SelectAction(context, actions.Actions);

                tAction.Enact(Log, new EffectContext(element, this));
                EndTurnOf(element);
            }
            else
            {
                var actions = element.GetData <AvailableActions>();
                if (actions == null || actions.Actions.Count == 0)
                {
                    EndTurnOf(element);
                }
            }
        }
Esempio n. 3
0
        public override double AIScore(TurnContext context, ActionSelectionAI weights)
        {
            Element self = context.Element;
            var     mDS  = self?.GetData <MapData>();
            var     mA   = self.GetData <MapAwareness>();

            // TEMP:
            Element target = ((RLState)context.State).Controlled;
            var     mDT    = target?.GetData <MapData>();

            if (mDT != null && !target.IsDeleted && mA.AwarenessOfCell(mDT.MapCell.Index) > 0)
            {
                // Manhatten distance calculation:
                Vector newPos = context.Stage.Map.CellPosition(_CellIndex);
                return(mDS.Position.ManhattenDistanceTo(mDT.Position)
                       - newPos.ManhattenDistanceTo(mDT.Position) + 0.05);
            }
            else
            {
                return(context.RNG.NextDouble());
            }

            // TODO: Employ influence maps
        }
Esempio n. 4
0
        public override double AIScore(TurnContext context, ActionSelectionAI weights)
        {
            double result = 0;

            foreach (MapCell cell in Target)
            {
                // Create a copy so that modifications to cell contents
                // don't screw up the enumeration:
                var elements = cell.Contents.ToList();

                foreach (var element in elements)
                {
                    if (context.Element?.GetData <Faction>()?.IsEnemy(element?.GetData <Faction>()) ?? false)
                    {
                        result += 10;
                    }
                    if (context.Element?.GetData <Faction>()?.IsAlly(element?.GetData <Faction>()) ?? false)
                    {
                        result -= context.RNG.NextDouble();
                    }
                }
            }
            return(result);
        }
Esempio n. 5
0
 public override double AIScore(TurnContext context, ActionSelectionAI weights)
 {
     return(0);
 }
Esempio n. 6
0
 /// <summary>
 /// Generate a score for this action based on the specified
 /// set of weightings
 /// </summary>
 /// <param name="weights"></param>
 /// <returns></returns>
 public virtual double AIScore(TurnContext context, ActionSelectionAI weights)
 {
     return(1.0);
 }