private List <AgentAction> GetPossibleActions(AgentAction current = null)
        {
            var                 actions = new List <AgentAction>();
            Vector2             playerPos;
            InteractorSimulated interactor;

            if (current == null)
            {
                playerPos  = playerMcts.transform.position;
                interactor = new InteractorSimulated();
            }
            else
            {
                playerPos  = current.Position;
                interactor = current.InteractorSimulated;
            }
            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    var dir = new Vector2Int(i, j);
                    actions.Add(new ActionMove(playerPos, dir, playerMcts.baseMvt, interactor));
                    actions.Add(new ActionInteract(playerPos, dir, playerMcts.baseMvt, interactor));
                }
            }

            return(actions);
        }
Пример #2
0
 protected void Init(Vector2 position, Vector2Int dir, BaseMovement baseMvt, InteractorSimulated interactor)
 {
     Position                     = position;
     Direction                    = dir;
     baseMovement                 = baseMvt;
     InteractorSimulated          = interactor;
     InteractorSimulated.Position = position;
 }
 public void Init()
 {
     scoreTime = new SimulateScoreTime();
     scoreTime.Init(GameManager.Instance.timer.CurrentTime);
     scoreTime.LScore  = _stadium.LPlayerScore.GetScore();
     scoreTime.RScore  = _stadium.RPlayerScore.GetScore();
     _frisbeeSimulated = new FrisbeeSimulated {
         Position       = _frisbee.transform.position,
         ColliderRadius = _frisbee.circleCollider.radius,
         Direction      = _frisbee.Direction,
         Force          = _frisbee.Force
     };
     opponentPos                 = opponent.transform.position;
     opponentInteractor          = new InteractorSimulated();
     opponentInteractor.Position = opponentPos;
 }
        // une simulation = 1 win | 0 lose
        private float SimulateResult(AgentAction possibleAction)
        {
            Vector2             opponentSimulatedPos        = opponentPos;
            InteractorSimulated opponentInteractorSimulated = opponentInteractor;
            //return scoreCharacter.Result();
            int         crashHandler   = 10000;
            AgentAction selectedAction = null;

            while (!IsFinished() && crashHandler > 0) //Attention votre jeu doit être finit !
            {
                --crashHandler;
                List <AgentAction> actions;
                if (selectedAction == null)
                {
                    actions = GetPossibleActions(possibleAction);
                }
                else
                {
                    actions = GetPossibleActions(selectedAction);
                }

                selectedAction = GetRandomAction(actions);

                selectedAction.PlayAction();
                scoreTime.UpdateTimer();
                _frisbeeSimulated.UpdateFrisbee();
                opponentSimulatedPos = RandomActionOpponent(opponentSimulatedPos);
                int result = _frisbeeSimulated.HandleCollisionWithPlayer(selectedAction.Position, opponentSimulatedPos, opponent.selfCollider.radius);
                if (result != 0)
                {
                    if (result == 1)
                    {
                        selectedAction.InteractorSimulated.Frisbee = _frisbeeSimulated;
                        _frisbeeSimulated.UpdateOffset(selectedAction.baseMovement.offsetFrisbee);
                    }
                    else if (result == 2)
                    {
                        opponentInteractorSimulated.Frisbee = _frisbeeSimulated;
                        _frisbeeSimulated.UpdateOffset(opponent.offsetFrisbee);
                    }
                }
            }
            return(Result()); //0 si perdu 1 si win*/
        }
Пример #5
0
 public override void PlayAction()
 {
     InteractorSimulated.Interact(Direction);
 }
Пример #6
0
 public ActionInteract(Vector2 position, Vector2Int dir, BaseMovement baseMvt, InteractorSimulated interactor)
 {
     Init(position, dir, baseMvt, interactor);
 }