public float[] ExpertDecide(List <float> vectorObs)
    {
        System.Random r = new System.Random();

        if (r.NextDouble() < noise)
        {
            return(new float[] { r.Next(0, 5) });
        }

        MLInput input = new MLInput(vectorObs.ToArray());

        if (input.GetOpponentAction() == MLAction.DODGE_LEFT)
        {
            return(MLActionFactory.GetVectorAction(MLAction.PUNCH_RIGHT));
        }

        if (input.GetOpponentAction() == MLAction.DODGE_RIGHT)
        {
            return(MLActionFactory.GetVectorAction(MLAction.PUNCH_LEFT));
        }

        if (input.GetOpponentAction() == MLAction.PUNCH_LEFT)
        {
            return(MLActionFactory.GetVectorAction(MLAction.DODGE_LEFT));
        }

        if (input.GetOpponentAction() == MLAction.PUNCH_RIGHT)
        {
            return(MLActionFactory.GetVectorAction(MLAction.DODGE_RIGHT));
        }

        return(new float[] { 0f });
    }
Exemple #2
0
    public override float[] Decide(List <float> vectorObs, List <Texture2D> visualObs, float reward, bool done, List <float> memory)
    {
        if (done)
        {
            moveIdx = 0;
            return(NOTHING);
        }

        MLInput input = new MLInput(vectorObs.ToArray());

        if (input.GetMyMove() == MLAction.NOTHING && input.IsDodgeReady()) // Can dodge
        {
            if (input.GetOpponentAction() == MLAction.PUNCH_LEFT)
            {
                int rand = Random.Range(0, 100);
                if (rand <= 30)
                {
                    return(LEFT_DODGE);
                }
                else if (rand <= 50)
                {
                    return(RIGHT_DODGE);
                }
                else
                {
                    // Run the normal moves
                }
            }
            if (input.GetOpponentAction() == MLAction.PUNCH_RIGHT)
            {
                int rand = Random.Range(0, 100);
                if (rand <= 30)
                {
                    return(RIGHT_DODGE);
                }
                else if (rand <= 50)
                {
                    return(LEFT_DODGE);
                }
                else
                {
                    // Run the normal moves
                }
            }
        }

        return(MLActionFactory.GetVectorAction(runMoves(vectorObs, moves)));
    }
    public float[] OnlyDoAndDodge(List <float> vectorObs, MLAction action)
    {
        MLInput input = new MLInput(vectorObs.ToArray());

        if (lastAction != input.GetOpponentAction() && input.GetOpponentAction() == MLAction.PUNCH_LEFT)
        {
            lastAction = input.GetOpponentAction();
            return(MLActionFactory.GetVectorAction(MLAction.DODGE_RIGHT));
        }

        if (lastAction != input.GetOpponentAction() && input.GetOpponentAction() == MLAction.PUNCH_RIGHT)
        {
            lastAction = input.GetOpponentAction();
            return(MLActionFactory.GetVectorAction(MLAction.DODGE_LEFT));
        }

        lastAction = input.GetOpponentAction();

        return(MLActionFactory.GetVectorAction(action));
    }
    public float[] RepeatActions(List <float> vectorObs, List <MLAction> actions, bool shouldDodge)
    {
        MLInput input = new MLInput(vectorObs.ToArray());

        // Sequence
        if (input.IsDodgeReady()) // Can punch / dodge
        {
            // Dodging
            if (shouldDodge && lastAction != input.GetOpponentAction() && input.GetOpponentAction() == MLAction.PUNCH_LEFT)
            {
                lastAction = input.GetOpponentAction();
                actionIdx  = 0;
                return(MLActionFactory.GetVectorAction(MLAction.DODGE_RIGHT));
            }

            if (shouldDodge && lastAction != input.GetOpponentAction() && input.GetOpponentAction() == MLAction.PUNCH_RIGHT)
            {
                lastAction = input.GetOpponentAction();
                actionIdx  = 0;
                return(MLActionFactory.GetVectorAction(MLAction.DODGE_LEFT));
            }

            lastAction = input.GetOpponentAction();
        }

        if (input.IsPunchReady())
        {
            int myComboState = input.GetMyComboState();
            if (actions.Count == 2)
            {
                switch (myComboState)
                {
                case 0: return(MLActionFactory.GetVectorAction(actions[0]));

                case 1: return(MLActionFactory.GetVectorAction(actions[1]));

                case 2: return(MLActionFactory.GetVectorAction(actions[1]));

                default: return(MLActionFactory.GetVectorAction(MLAction.NOTHING));
                }
            }
            if (actions.Count == 3)
            {
                switch (myComboState)
                {
                case 0: return(MLActionFactory.GetVectorAction(actions[0]));

                case 1: return(MLActionFactory.GetVectorAction(actions[1]));

                case 2: return(MLActionFactory.GetVectorAction(actions[1]));

                case 3: return(MLActionFactory.GetVectorAction(actions[2]));

                case 4: return(MLActionFactory.GetVectorAction(actions[2]));

                default: return(MLActionFactory.GetVectorAction(MLAction.NOTHING));
                }
            }
            return(MLActionFactory.GetVectorAction(actions[0]));
        }

        return(MLActionFactory.GetVectorAction(MLAction.NOTHING));
    }