public void ProcessIntent(FSM.Event _event)
    {
        //print(Time.time +"- ID:" + id +"- From: " + position + " Called Intent: (" + _event + "), alone?: " + isAlone);
        //FSM.Event _event = supervisorio.eventsConteiner[eventID];
        if (_event == null)
        {
            return;
        }

        Coord dest = position;

        switch (_event.type)
        {
        case "typeMovement":
            switch (_event.label)
            {
            case "u":
                dest = position + Coord.left; break;

            case "d":
                dest = position + Coord.right; break;

            case "l":
                dest = position + Coord.down; break;

            case "r":
                dest = position + Coord.up; break;
            }
            break;

        case "typeMovementIO":

            if (_event.label == "out")
            {
                dest = Coord.origin;
            }
            else if (_event.label == "in")
            {
                dest = new Coord(1, 1);
            }
            else
            {
                dest = new Coord((int)Char.GetNumericValue(_event.label[2]), (int)Char.GetNumericValue(_event.label[3]));
            }

            break;

        case "typePlace":
            dest = new Coord((int)Char.GetNumericValue(_event.label[1]), (int)Char.GetNumericValue(_event.label[2]));
            break;
        }

        communicationComponent.CallIntent(_event.id, dest);
    }
Ejemplo n.º 2
0
    public void StartTransition(int eventID, Coord dest)
    {
        //print(Time.time + "- Started Transition: " + dest + " e " + brain.position);

        _event = brain.supervisorio.eventsConteiner[eventID];

        // START TRANSITION
        reservedDest    = dest;
        IsTransitioning = true;



        // START ANIMATION
        animationComponent.StartAnimation(eventID);
    }
Ejemplo n.º 3
0
    public void NotifyTransistionEnd(GameObject source, FSM.Event _event)
    {
        externalEvents.Add(_event);

        foreach (var bot in botList)
        {
            if (bot == source)
            {
            }
            else
            {
                bot.GetComponent <TermiteCommunicationComponent>().unknownEventsBuffer.Add(_event);
            }
        }
    }
Ejemplo n.º 4
0
    Dictionary <int, FSM.Event> LoadEvents(IEnumerable events)
    {
        Dictionary <int, FSM.Event> eventsContainer = new Dictionary <int, FSM.Event>();

        //Carrega o dicionário de eventos
        foreach (XElement eventData in events)
        {
            int    eventId    = (int)eventData.Attribute("id");
            string eventLabel = (string)eventData.Attribute("label");

            FSM.Event eventCaster = new FSM.Event(eventId, eventLabel);
            eventsContainer.Add(eventId, eventCaster);
        }

        return(eventsContainer);
    }
Ejemplo n.º 5
0
    // Start a transition if all other bots allow and the intended event is still possible
    public void CallIntent(int eventID, Coord destination)
    {
        FSM.Event _event = brain.supervisorio.eventsConteiner[eventID];


        if (centralController.RequestIntent(gameObject, destination, _event))
        {
            if (brain.supervisorio.FeasibleEvents().Contains(_event))
            {
                StartTransition(eventID, destination);
            }
        }
        else
        {
            brain.ActionDenied();
        }
    }
Ejemplo n.º 6
0
    // MultiBot (TermiteFSM) Functions
    public bool RequestIntent(GameObject source, Coord dest, FSM.Event _event)
    {
        bool permission = true;

        foreach (var bot in botList)
        {
            if (bot != source)
            {
                if (!bot.GetComponent <TermiteFSMBrain>().communicationComponent.Allow(dest, _event))
                {
                    permission = false;
                }
            }
        }

        return(permission);
    }
Ejemplo n.º 7
0
    // Allows other bots intention to occur
    public bool Allow(Coord dest, FSM.Event _event)
    {
        // If is an external event, check if it is feasible
        if (brain.supervisorio.AltEvent(_event) != null)
        {
            bool feasible = false;

            foreach (var e in brain.supervisorio.FeasibleEvents())
            {
                if (e.id == brain.supervisorio.AltEvent(_event).id)
                {
                    feasible = true;
                }
            }

            if (!feasible)
            {
                return(false);
            }
        }



        if (brain.position == dest && dest != Coord.origin)
        {
            return(false);
        }
        else if (IsTransitioning && reservedDest == dest)
        {
            return(false);
        }
        else
        {
            return(true);
        }
    }
    private void PlanAction(int steps = 5, int tries = 5)
    {
        List <FSM.Event> eventPlan = new List <FSM.Event>();
        int maxScore = -1;

        for (int i = 0; i < tries; i++)
        {
            FSM.State        imaginaryState = supervisorio.currentState;
            List <FSM.Event> tryPlan        = new List <FSM.Event>();

            for (int j = 0; j < steps; j++)
            {
                //print(i + "" + j + " Started--- "+ imaginaryState);
                List <FSM.Event> feasible = supervisorio.FeasibleEvents(imaginaryState, true);

                if (feasible.Count > 0)
                {
                    FSM.Event tryEvent = feasible[UnityEngine.Random.Range(0, feasible.Count)];
                    //print(i + "" + j + " Did--- " + tryEvent);

                    tryPlan.Add(tryEvent);

                    imaginaryState = supervisorio.ImagineEvent(tryEvent, imaginaryState);
                    //print(i + "" + j + " Ended--- " + imaginaryState);
                }
            }

            if (EvaluatePlan(tryPlan, steps) > maxScore)
            {
                maxScore  = EvaluatePlan(tryPlan, steps);
                eventPlan = tryPlan;
            }
        }
        //print("Score: " + maxScore);
        myPlan = eventPlan;
    }
    public void StartAnimation(int eventID)
    {
        //OBS: Still needs refactoring

        IsAnimating = true;

        FSM.Event _event    = brain.supervisorio.eventsConteiner[eventID];
        string    eventType = _event.type;

        switch (eventType)
        {
        case "typeGet":
            animationBuffer.Add(GrabTile);
            break;

        case "typePlace":

            int x = int.Parse(_event.label[1].ToString());
            int y = int.Parse(_event.label[2].ToString());

            if (brain.position.y < y)
            {
                animationBuffer.Add(() => TurnTo(0));
            }
            else if (brain.position.y > y)
            {
                animationBuffer.Add(() => TurnTo(2));
            }
            else if (brain.position.x < x)
            {
                animationBuffer.Add(() => TurnTo(3));
            }
            else
            {
                animationBuffer.Add(() => TurnTo(1));
            }
            animationBuffer.Add(PlaceTile);

            break;

        case "typeMovement":

            switch (_event.label)
            {
            case "u":
                animationBuffer.Add(() => TurnTo(1));
                break;

            case "d":
                animationBuffer.Add(() => TurnTo(3));
                break;

            case "l":
                animationBuffer.Add(() => TurnTo(2));
                break;

            case "r":
                animationBuffer.Add(() => TurnTo(0));
                break;
            }
            animationBuffer.Add(GoFoward);
            break;

        case "typeMovementIO":

            if (_event.label == "out")
            {
                coreTransform.position    = new Vector3(-27.5f * 1.5f, 5f, -27.5f * 1.5f);
                coreTransform.eulerAngles = compass[3];
            }
            else if (_event.label == "in")
            {
                coreTransform.position    = tileSystem.centreMap[new Coord(1, 1)];
                coreTransform.eulerAngles = compass[3];
            }
            break;
        }
    }