Example #1
0
 public void PerformAction(Point from, Point to, int actionId)
 {
     if (actionId == EndTurnAction.ID)
     {
         var endTurnAction = EndTurnAction.createNew();
         WaitingPlayer.ProcessOpponentAction(endTurnAction);
         PerformAction(endTurnAction);
     }
     else if (actionId == MoveAction.ID)
     {
         var moveAction = GetTargetableAction <MoveAction>(from, to);
         WaitingPlayer.ProcessOpponentAction(moveAction);
         PerformAction(moveAction);
     }
     else if (actionId == AttackAction.ID)
     {
         var attackAction = GetTargetableAction <AttackAction>(from, to);
         WaitingPlayer.ProcessOpponentAction(attackAction);
         PerformAction(attackAction);
     }
     else if (actionId == HealAction.ID)
     {
         var healAction = GetTargetableAction <HealAction>(from, to);
         WaitingPlayer.ProcessOpponentAction(healAction);
         PerformAction(healAction);
     }
 }
Example #2
0
        private Tuple <int, Action> ShallowMinimax(Kernel kernel, Action lastAction)
        {
            UnityEngine.Debug.Log("action = " + lastAction);
            if (kernel.currentState.get_activePlayer().id != ID)
            {
                int rating = ComputeGameStateValue(kernel.currentState);
                UnityEngine.Debug.Log("action: " + lastAction + " rating: " + rating);
                return(new Tuple <int, Action>(rating, null));
            }

            List <Action> availableActions;

            if (lastAction != null)
            {
                if (lastAction.getId() == MoveAction.ID)
                {
                    availableActions = kernel.getAllValidActionsFrom(((MoveAction)lastAction).getContext().target).CastToList <Action>();
                }
                else
                {
                    int rating = ComputeGameStateValue(kernel.currentState);
                    UnityEngine.Debug.Log("action: " + lastAction + " rating: " + rating);
                    return(new Tuple <int, Action>(rating, EndTurnAction.createNew()));
                }
            }
            else
            {
                availableActions = kernel.getAllValidActions().CastToList <Action>();
            }

            SortedDictionary <int, Action> actionsRatings = new SortedDictionary <int, Action>();

            foreach (Action availableAction in availableActions)
            {
                Kernel kernelCopy = kernel.clone();
                kernelCopy.performAction(availableAction);
                Tuple <int, Action> lowerLevelResult = ShallowMinimax(kernelCopy, availableAction);
                actionsRatings[lowerLevelResult.First] = availableAction;
            }
            var result = new Tuple <int, Action>(actionsRatings.Keys.Last(), actionsRatings.Values.Last());

            return(result);
        }
Example #3
0
 private void PassiveLogic()
 {
     PerformAction(EndTurnAction.createNew());
 }