public AvailableAction(PossibleAction _action, KeyCode _newActionKey, GameObject _triggerObj)
 {
     this._action    = _action;
     this._ID        = UnityEngine.Random.Range(0, 10000);
     this._actionKey = _newActionKey;
     this.triggerObj = _triggerObj;
 }
Esempio n. 2
0
 public Node Exist(PossibleAction p)
 {
     if (children != null)
     {
         foreach (var child in children)
         {
             if (child.state == p)
             {
                 return(child);
             }
         }
     }
     return(null);
 }
Esempio n. 3
0
        /// <summary>
        /// Invoke action method invokes actions on Clients Library object
        /// </summary>
        /// <param name="action"> Performed action - name of the action + direction of the move</param>
        /// <param name="currentRound"> Number of current round</param>
        void InvokeAction(PossibleAction action, int currentRound)
        {
            _history.Last().MadeMove = action.Action;
            MethodInfo method        = _cl.GetType().GetMethod(action.Action.ToString()); // INVOKE ALL ACTIONS IN QUEUE

            if (method.GetParameters().Count() == 2)
            {
                method.Invoke(_cl, new object[] { action.MoveDirection, _currentRoundNumber });
            }
            else
            {
                method.Invoke(_cl, new object[] { _currentRoundNumber });
            }
            _canMakeMove = false;
        }
    void compute(Node action, Pokemon pokemonMe, Pokemon pokemonAdv)
    {
        //Debug.Log(action.data.a + "/" + action.data.b);
        //Tant que la simulation n'est pas achevée
        while (!GameSimul.isFinished)
        {
            System.Array actions = GameSimul.GetNextPossibleAction(action);

            // Choisi une action au piff
            PossibleAction choice = (PossibleAction)GameSimul.GetRandomAction(actions);

            // Crée un node (donc une action) si elle n'existe pas encore
            // ou sinon prend celle trouvée
            Node exitanteNode = action.Exist(choice);
            if (exitanteNode == null)
            {
                Node selectedAction = action.AddChild(new Register(0, 0));
                selectedAction.parent = action;
                selectedAction.setState(choice);

                action = selectedAction;
            }
            else
            {
                action = exitanteNode;
            }
            // Lance la simulation
            GameSimul.PlayAction(action, pokemonMe, pokemonAdv);
            //Debug.Log(GameSimul.lifeAdv + " | " + GameSimul.lifeMe);
            //if(i++ > 10000) break;
        }
        // Applique des valeurs sur la feuille finale
        action.data.b = 1;
        if (GameSimul.finalSituation == 0)//gameover
        {
            action.data.a = 0;
        }
        else                    //win
        {
            action.data.a = 1;
        }

        // Retroprograpagation de l'action
        Node.Retropropagation(action);
        // Prépare le simulateur à une prochaine simulation
        GameSimul.Reset();
    }
Esempio n. 5
0
    /* TODO: CHANGE THIS SO IT WORKS WITH ABILITIES

        return value indicates if action could have been carried out
    */
    public void performAction(PossibleAction posAc)
    {
        switch (posAc)
        {
            case PossibleAction.ATTACK:
                currentState = BattleState.CALCDAMAGE;
                break;
            case PossibleAction.CHARACTER_DIED:
                currentState = BattleState.WAITING;
                break;
            default:
                break;
        }
    }
Esempio n. 6
0
 internal bool isValidTarget(int playerTargetIndex, PossibleAction posAc)
 {
     bool isValidTarget;
     switch (posAc)
     {
         // For attacks, only target alive enemies
         case PossibleAction.ATTACK:
             isValidTarget = !enemies[playerTargetIndex].isDead();
             break;
         // Character died, obviously it will always succeed
         case PossibleAction.CHARACTER_DIED:
             isValidTarget = true;
             break;
         default:
             Debug.Log("Action could not be recognized");
             isValidTarget = false;
             break;
     }
     return isValidTarget;
 }
 public AvailableAction(PossibleAction _action, KeyCode _newActionKey, GameObject _triggerObj)
 {
     this._action = _action;
     this._ID = UnityEngine.Random.Range(0, 10000);
     this._actionKey = _newActionKey;
     this.triggerObj = _triggerObj;
 }
 public AvailableAction(PossibleAction _action, KeyCode _newActionKey)
 {
     this._action = _action;
     this._ID = UnityEngine.Random.Range(0, 10000);
     this._actionKey = _newActionKey;
 }
 public static System.Array GetNextPossibleAction(Node n)
 {
     return(PossibleAction.GetValues(typeof(PossibleAction)));
 }
    public override int interact(Pokemon pokemonMe, Pokemon pokemonAdv)
    {
        if (pokemonAdv != null && pokemonMe != null)
        {
            // initialise les données du simulateur
            GameSimul.lifeAdv   = pokemonAdv.getStats().Pv;
            GameSimul.lifeMe    = pokemonMe.getStats().Pv;
            GameSimul.chargeAdv = pokemonAdv.charged;
            GameSimul.chargeMe  = pokemonMe.charged;

            for (int i = 0; i < 4; i++)
            {
                if (pokemonMe.capacities[i] != null)
                {
                    GameSimul.ppMe[i] = pokemonMe.capacities[i].getPP();
                }
                if (pokemonAdv.capacities[i] != null)
                {
                    GameSimul.ppAdv[i] = pokemonAdv.capacities[i].getPP();
                }
            }

            compute(tree, pokemonMe, pokemonAdv);
        }

        // Appel horloge
        if (internalHorloge > born && thrust())
        {
            born            = FREQUENCY;
            internalHorloge = 0;

            float          max           = float.MinValue;
            PossibleAction currentAction = PossibleAction.UNDETERMINED;
            Node           n             = null;
            bool           priorityMove  = false;
            // Si une cible existe sur l'objet, on gère une priorité
            foreach (GameObject o in GameObject.FindGameObjectsWithTag("target"))
            {
                if (Vector2.Distance(o.transform.position, render.transform.position) < 2f)
                {
                    priorityMove = true;;
                }
            }

            // Cherche la meilleure action conduisant à une victoire
            foreach (Node child in tree.getPossibleAction())
            {
                if (child.state != PossibleAction.UNDETERMINED)
                {
                    if ((float)child.data.a / (float)child.data.b > max)
                    {
                        currentAction = child.state;
                        max           = (float)child.data.a / (float)child.data.b;
                        n             = child;
                    }
                }
            }

            // Si priorité de mouvement ou action ESQUIVE
            // On se déplace
            a = new int[4];
            if (priorityMove || currentAction == PossibleAction.ESQUIVE)
            {
                if (render.v.x >= 0)
                {
                    a[2] = 1;
                }
                else
                {
                    a[3] = 1;
                }

                if (render.v.y >= 0)
                {
                    a[1] = 1;
                }
                else
                {
                    a[0] = 1;
                }
            }


            int i = 0;
            if (pokemonMe != null &&
                pokemonAdv != null)
            {
                switch (currentAction)
                {
                case PossibleAction.UNDETERMINED:
                case PossibleAction.WAIT:
                    break;

                // Utilise les capacités si le MCTS le demande
                case PossibleAction.CAPACITY0:
                    i = pokemonMe.useCapacity(0, pokemonAdv, render);
                    break;

                case PossibleAction.CAPACITY1:
                    i = pokemonMe.useCapacity(1, pokemonAdv, render);
                    break;

                case PossibleAction.CAPACITY2:
                    i = pokemonMe.useCapacity(2, pokemonAdv, render);
                    break;

                case PossibleAction.CAPACITY3:
                    i = pokemonMe.useCapacity(3, pokemonAdv, render);
                    break;
                }
            }
            // IMPORTANT ! On définie le nouveau noeud de base sur le noeud choisi
            if (n != null)
            {
                tree = n;
            }

            return(i);
        }
        // Applique le mouvement
        if (pokemonMe != null)
        {
            if (a[0] >= 0.8f)
            {
                render.v.y += Time.deltaTime * SENSIBILITY;
                pokemonMe.charge(COST_MOVE);
            }
            if (a[1] >= 0.8f)
            {
                render.v.y -= Time.deltaTime * SENSIBILITY;
                pokemonMe.charge(COST_MOVE);
            }
            if (a[2] >= 0.8f)
            {
                render.v.x -= Time.deltaTime * SENSIBILITY;
                pokemonMe.charge(COST_MOVE);
            }
            if (a[3] >= 0.8f)
            {
                render.v.x += Time.deltaTime * SENSIBILITY;
                pokemonMe.charge(COST_MOVE);
            }
        }
        return(0);
    }
Esempio n. 11
0
 public void setState(PossibleAction p)
 {
     this.state = p;
 }
Esempio n. 12
0
    // Used at the last step of the menu. Both ability and target have been selected
    private void attemptFinishTurnAndSetActions(int playerTargetIndex, PossibleAction posAc) 
    {
        if (combat.isValidTarget(playerTargetIndex, posAc))
        {
            combat.playerTargetIndex = playerTargetIndex;
            combat.performAction(posAc);
            characterName.text = "";
            changeMenuState(MenuState.WAITING);
        }

    }
 public AvailableAction(PossibleAction _action, KeyCode _newActionKey)
 {
     this._action    = _action;
     this._ID        = UnityEngine.Random.Range(0, 10000);
     this._actionKey = _newActionKey;
 }