Esempio n. 1
0
    public void StartGame()
    {
        nbPlayers = int.Parse(_numberplayerDropDown.GetComponent <Dropdown>().captionText.text);
        XMLWarbotInterpreter interpreter = new XMLWarbotInterpreter();

        GameObject gameManager = GameObject.Find("GameManager");
        string     gamePath    = Application.streamingAssetsPath + "/teams/" + gameManager.GetComponent <GameManager>()._gameName + "/";

        gameManager.GetComponent <TeamManager>()._teams = new List <Team>();

        for (int i = 0; i < nbPlayers; i++)
        {
            Team team = new Team();
            team._color          = _DropDownList[i]._teamColor;
            team._name           = _DropDownList[i]._teamName;//.Replace("_", " ");
            team._unitsBehaviour = interpreter.xmlToBehavior(gamePath + team._name, gamePath);
            gameManager.GetComponent <TeamManager>()._teams.Add(team);
        }

        GameManager setting = gameManager.GetComponent <GameManager>();

        setting.SetSetting();

        //
        StartCoroutine(AsynchronousLoad(setting._gameSettings._indexSceneMap));
    }
    void Start()
    {
        string teamName = "blabla";
        string unitName = "Unit";
        string gameName = "TestBot";


        XMLWarbotInterpreter interpreter = new XMLWarbotInterpreter();
        List <Instruction>   behavior    = new List <Instruction>();

        // INSTRUCTION DE EAT DES LIGHTS
        string[] percepts1 = new string[] { "PERCEPT_FOOD_INVENTORY", "PERCEPT_LIFE_NOT_MAX" };
        string   action1   = "ACTION_EAT";

        string[] percepts2 = new string[] {};
        string   action2   = "ACTION_MOVE";


        Instruction i1 = new Instruction(percepts1, action1);
        Instruction i2 = new Instruction(percepts2, action2);

        behavior.Add(i1);
        behavior.Add(i2);

        string _teamPath = Constants.teamsDirectory + gameName + "/" + teamName + "/";

        if (!Directory.Exists(_teamPath))
        {
            //if it doesn't, create it
            Directory.CreateDirectory(_teamPath);
        }

        //check if directory doesn't exit
        if (!Directory.Exists(_teamPath))
        {
            //if it doesn't, create it
            Directory.CreateDirectory(_teamPath);
        }

        interpreter.behaviorToXml(teamName, _teamPath, unitName, behavior);
        print("Ecriture fichier XML termine.");
        System.Console.ReadLine();

        /* */

        List <Instruction> behavior2 = new List <Instruction>();

        behavior2    = interpreter.xmlToUnitBehavior(teamName, _teamPath, unitName);
        _instruction = behavior2;

        print("Construction du comportement depuis fichier XML termine.");
        System.Console.ReadLine();

        /* */
    }
Esempio n. 3
0
    public List <Instruction> getUnitsBevahiours(int teamIndex, string unitType)
    {
        string gamePath = Application.streamingAssetsPath + "/teams/" + GetComponent <GameManager>()._gameName + "/";
        XMLWarbotInterpreter interpreter = new XMLWarbotInterpreter();

        if (_teams[teamIndex]._unitsBehaviour.ContainsKey(unitType))
        {
            return(_teams[teamIndex]._unitsBehaviour[unitType]);
        }
        return(new List <Instruction>());
    }
Esempio n. 4
0
    public void createXML()
    {
        //recuperation de l'unité actuellement traitée et de l'equipe
        string teamName = team.captionText.text;
        string unitName = unit.captionText.text;
        string path     = Application.dataPath + "/StreamingAssets/" + Constants.teamsDirectory + Constants.gameModeWarBot;

        if (teamName != "")
        {
            XMLWarbotInterpreter interpreter = new XMLWarbotInterpreter();
            interpreter.behaviorToXml(teamName, path, unitName, listBehavior);
        }
    }
    static void test(string[] args)
    {
        string teamName = "TestInterpret";
        string unitName = "Light";


        XMLWarbotInterpreter interpreter = new XMLWarbotInterpreter();
        List <Instruction>   behavior    = new List <Instruction>();

        // INSTRUCTION DE EAT DES LIGHTS
        string[]        percepts = new string[] { "PERCEPT_FOOD_INVENTORY", "PERCEPT_LIFE_NOT_MAX" };
        MessageStruct[] messages = new MessageStruct[] { new MessageStruct("MESSAGE_HELP", "ALL") };
        string          action   = "ACTION_EAT";

        string[] percepts2 = new string[] { };
        string   action2   = "ACTION_MOVE";

        Instruction i  = new Instruction(percepts, messages, action);
        Instruction i2 = new Instruction(action2);

        behavior.Add(i);
        behavior.Add(i2);

        interpreter.behaviorToXml(teamName, Constants.teamsDirectory, unitName, behavior);
        System.Console.WriteLine("Ecriture fichier XML termine.");
        System.Console.ReadLine();

        /* */

        List <Instruction> behavior2 = new List <Instruction>();

        behavior2 = interpreter.xmlToUnitBehavior(teamName, Constants.teamsDirectory, unitName);
        System.Console.WriteLine("count : " + behavior2.Count);
        for (int cpt = 0; cpt < behavior2.Count; cpt++)
        {
            System.Console.WriteLine(behavior2[cpt].getStringAction());
            foreach (string s in behavior2[cpt]._listeStringPerceptsVoulus)
            {
                System.Console.WriteLine(s);
            }
            foreach (MessageStruct s in behavior2[cpt]._stringActionsNonTerminales)
            {
                System.Console.WriteLine(s._intitule + " - > " + s._destinataire);
            }
        }

        System.Console.WriteLine("Construction du comportement depuis fichier XML termine.");
        System.Console.ReadLine();

        /* */
    }
Esempio n. 6
0
    public void CreateDefaultBehaviour()
    {
        Debug.ClearDeveloperConsole();
        Debug.Log("Creating Default Team ...");
        List <Instruction> behavior = new List <Instruction>()
        {
            new Instruction(new string[] { "PERCEPT_ENEMY" }, new MessageStruct[] { new MessageStruct("ACTN_MESSAGE_HELP", "Light") }, "ACTION_MOVE"),
            new Instruction(new string[] { "PERCEPT_BLOCKED" }, "ACTION_MOVE_UNTIL_UNBLOCKED"),
            new Instruction(new string[] { "PERCEPT_BASE_NEAR_ALLY", "PERCEPT_BAG_NOT_EMPTY" }, "ACTION_GIVE_RESSOURCE"),
            new Instruction(new string[] { "PERCEPT_BAG_FULL" }, "ACTION_BACK_TO_BASE"),
            new Instruction(new string[] { "PERCEPT_LIFE_NOT_MAX", "PERCEPT_BAG_NOT_EMPTY" }, "ACTION_HEAL"),
            new Instruction(new string[] { "PERCEPT_BAG_NOT_FULL", "PERCEPT_FOOD_NEAR" }, "ACTION_PICK"),
            new Instruction(new string[] { "PERCEPT_BLOCKED" }, "ACTION_MOVE_UNTIL_UNBLOCKED"),
            new Instruction(new string[] { }, "ACTION_MOVE")
        };
        string gamePath = Application.streamingAssetsPath + "/teams/" + GetComponent <GameManager>()._gameName + "/";

        string teamName = "Default Team";
        XMLWarbotInterpreter interpreter = new XMLWarbotInterpreter();

        interpreter.behaviorToXml(teamName, gamePath, "Explorer", behavior);


        behavior = new List <Instruction>()
        {
            new Instruction(new string[] { "PERCEPT_IS_RELOADED", "PERCEPT_CONTRACT", "CONTRACT_ELIMINATION_TARGET_NEAR" }, "ACTION_FIRE"),
            new Instruction(new string[] { "PERCEPT_MESSAGE_ATTACK" }, new MessageStruct[] { new MessageStruct("ACTN_ADD_ELIMINATION_CONTRACT", "None") }, "ACTION_MOVE"),
            new Instruction(new string[] { "PERCEPT_LIFE_NOT_MAX", "PERCEPT_BAG_NOT_EMPTY" }, "ACTION_HEAL"),
            new Instruction(new string[] { "PERCEPT_IS_NOT_RELOADED" }, "ACTION_RELOAD"),
            //new Instruction(new string[] { "PERCEPT_IS_RELOADED", "PERCEPT_ENEMY" }, "ACTION_FIRE"),
            new Instruction(new string[] { "PERCEPT_BAG_NOT_FULL", "PERCEPT_FOOD_NEAR" }, "ACTION_PICK"),
            new Instruction(new string[] { "PERCEPT_BLOCKED" }, "ACTION_MOVE_UNTIL_UNBLOCKED"),
            new Instruction(new string[] { }, "ACTION_MOVE")
        };
        interpreter.behaviorToXml(teamName, gamePath, "Light", behavior);
        interpreter.behaviorToXml(teamName, gamePath, "Heavy", behavior);

        behavior = new List <Instruction>()
        {
            new Instruction(new string[] { "PERCEPT_LIFE_NOT_MAX", "PERCEPT_BAG_NOT_EMPTY" }, "ACTION_HEAL"),
            new Instruction(new string[] { "PERCEPT_BAG_10" }, "ACTION_CREATE_LIGHT")
        };
        interpreter.behaviorToXml(teamName, gamePath, "Base", behavior);
        Debug.Log("Creating Default Team DONE!");
    }
Esempio n. 7
0
    // Vérifie le nom d'équipe entré par l'utilisateur, pour empêcher l'utilisation de caractères spéciaux
    // Caractères acceptés : a-zA-Z0-9
    public void validateName()
    {
        string teamName = mainInputField.text;
        string path     = Application.streamingAssetsPath + "/teams/TestBot/";


        List <int> listInt = new List <int>();

        for (int i = 0; i < teamName.Length; i++)
        {
            listInt.Add(Convert.ToInt32(teamName[i]));
        }

        for (int i = 0; i < listInt.Count; i++)
        {
            int result = listInt[i];
            if ((result > 90 && result < 97) || (result < 65 && result > 57) || (result < 48 && result > 32) || result > 122)
            {
                errorText.SetActive(true);
                Text error = errorText.GetComponentInChildren <Text>();
                error.text = "Nom invalide ! (a-zA-Z0-9)";
                return;
            }
            if (listInt[0] == 32) //&& result == 32)
            {
                errorText.SetActive(true);
                Text errorSpace = errorText.GetComponentInChildren <Text>();
                errorSpace.text = "Nom invalide ! (a-zA-Z0-9)";
                return;
            }
        }

        if (listInt.Count == 0)
        {
            errorText.SetActive(true);
            Text errorSpace = errorText.GetComponentInChildren <Text>();
            errorSpace.text = "Nom invalide ! (a-zA-Z0-9)";
            return;
        }

        foreach (string file in Directory.GetFiles(path))
        {
            string res = file.Replace(path, "");
            if (res == teamName + ".wbt")
            {
                errorText.SetActive(true);
                Text error = errorText.GetComponentInChildren <Text>();
                error.text = "L'équipe existe déjà !";
                return;
            }
        }

        if (!System.IO.File.Exists(Application.streamingAssetsPath + "/ELO/" + teamName + ".elo"))
        {
            File.Create(Application.streamingAssetsPath + "/ELO/" + teamName + ".elo").Dispose();
            File.WriteAllLines(Application.streamingAssetsPath + "/ELO/" + teamName + ".elo", new string[] { 1000 + "" });
        }


        dropOption.Add(teamName);
        teamDropDown.AddOptions(dropOption);
        XMLWarbotInterpreter interpreter = new XMLWarbotInterpreter();

        interpreter.generateEmptyFile(teamName, path);
        dropOption.Clear();
        errorText.SetActive(false);
        window.SetActive(false);
    }
Esempio n. 8
0
    // Lit un fichier .xml, et crée le comportement correspondant
    public void createBehaviorFromXML()
    {
        clear = new NewFile();
        clear.clearEditor();
        string               teamName                     = team.captionText.text;
        string               unitName                     = unit.captionText.text;
        string               path                         = Application.dataPath + "/StreamingAssets/" + Constants.teamsDirectory + Constants.gameModeWarBot;
        Transform            editeurTransform             = GameObject.Find("Editeur").transform;
        XMLWarbotInterpreter interpreter                  = new XMLWarbotInterpreter();
        Dictionary <string, List <Instruction> > behavior = interpreter.xmlToBehavior(teamName, path);
        Vector2 delta = new Vector2(0, -1);

        if (behavior.ContainsKey(unitName) && behavior[unitName].Count != 0)
        {
            GameObject.Find("StartPuzzle").GetComponent <ManageDragAndDrop>().UpdateGridPosition();
            GameObject.Find("StartPuzzle").GetComponent <StartPuzzleScript>().UpdateAllValidPuzzles();
            float   widthPuzzle  = GameObject.Find("StartPuzzle").GetComponent <ManageDragAndDrop>().sizePuzzleX;
            float   heightPuzzle = GameObject.Find("StartPuzzle").GetComponent <ManageDragAndDrop>().sizePuzzleY;
            float   newX         = GameObject.Find("StartPuzzle").GetComponent <ManageDragAndDrop>().posGridX *widthPuzzle;
            float   newY         = GameObject.Find("StartPuzzle").GetComponent <ManageDragAndDrop>().posGridY *heightPuzzle;
            Vector3 newPos       = new Vector3(newX, newY, 10);
            GameObject.Find("StartPuzzle").GetComponent <RectTransform>().localPosition = newPos;
            GameObject currentIf      = GameObject.Find("StartPuzzle");
            GameObject currentPercept = GameObject.Find("StartPuzzle");
            GameObject currentAction  = GameObject.Find("StartPuzzle");

            foreach (Instruction I in behavior[unitName])
            {
                GameObject _ifPuzzle = Instantiate(ifPuzzle, editeurTransform);
                _ifPuzzle.GetComponent <ManageDragAndDrop>().setGridPosition(currentIf.GetComponent <ManageDragAndDrop>().getGridPosition() + delta);
                _ifPuzzle.GetComponent <ManageDragAndDrop>().UpdateGridPosition();
                GameObject.Find("StartPuzzle").GetComponent <StartPuzzleScript>().UpdateAllValidPuzzles();
                widthPuzzle  = _ifPuzzle.GetComponent <ManageDragAndDrop>().sizePuzzleX;
                heightPuzzle = _ifPuzzle.GetComponent <ManageDragAndDrop>().sizePuzzleY;
                newX         = _ifPuzzle.GetComponent <ManageDragAndDrop>().posGridX *widthPuzzle;
                newY         = _ifPuzzle.GetComponent <ManageDragAndDrop>().posGridY *heightPuzzle;
                newPos       = new Vector3(newX, newY, 10);

                _ifPuzzle.GetComponent <RectTransform>().localPosition = newPos;
                currentIf      = _ifPuzzle;
                delta          = new Vector2(1, 0);
                currentPercept = currentIf;

                foreach (string s in I._listeStringPerceptsVoulus)
                {
                    GameObject _condPuzzle = Instantiate(condPuzzle, editeurTransform);
                    _condPuzzle.GetComponent <ManageDragAndDrop>().setGridPosition(currentPercept.GetComponent <ManageDragAndDrop>().getGridPosition() + delta);
                    currentPercept = _condPuzzle;
                    _condPuzzle.GetComponent <PuzzleScript>()._value = s;
                    if (s.Contains("NOT_"))
                    {
                        _condPuzzle.GetComponent <PuzzleScript>().NegationBoutton();
                    }
                    delta = new Vector2(2, 0);
                }
                delta         = new Vector2(1, -1);
                currentAction = currentIf;
                if (I._stringActionsNonTerminales.Length != 0)
                {
                    foreach (MessageStruct s in I._stringActionsNonTerminales)
                    {
                        GameObject _messPuzzle = null;
                        if (s._intitule.Contains("ACTN"))
                        {
                            _messPuzzle = Instantiate(antPuzzle, editeurTransform);
                        }
                        if (s._intitule.Contains("ACTN_MESSAGE_"))
                        {
                            _messPuzzle = Instantiate(messagePuzzle, editeurTransform);
                        }
                        //print(s._intitule);
                        if (_messPuzzle != null)
                        {
                            _messPuzzle.GetComponent <ManageDragAndDrop>().setGridPosition(currentAction.GetComponent <ManageDragAndDrop>().getGridPosition() + delta);
                            currentAction = _messPuzzle;
                            _messPuzzle.GetComponent <PuzzleScript>()._value = s._intitule;
                            //print("A Dest : " + s._destinataire);
                            if (_messPuzzle.GetComponent <PuzzleScript>().messageDropDown)
                            {
                                _messPuzzle.GetComponent <PuzzleScript>().DropDownUpdate();
                                for (int i = 0; i < _messPuzzle.GetComponent <PuzzleScript>().messageDropDown.options.Count; i++)
                                {
                                    // print("B " + _messPuzzle.GetComponent<PuzzleScript>().messageDropDown.options[i].text + " >< " + s._destinataire);
                                    if (_messPuzzle.GetComponent <PuzzleScript>().messageDropDown.options[i].text == s._destinataire)
                                    {
                                        //print("B Dest : " + s._destinataire);
                                        _messPuzzle.GetComponent <PuzzleScript>().messageDropDown.value = i;
                                        _messPuzzle.GetComponent <PuzzleScript>().messageDropDown.Select();
                                        _messPuzzle.GetComponent <PuzzleScript>().messageDropDown.RefreshShownValue();
                                        break;
                                    }
                                }
                            }
                            delta = new Vector2(2, 0);
                        }
                    }
                }
                else
                {
                    delta = new Vector2(1, -1);
                }
                if (I._stringAction != "")
                {
                    GameObject _actPuzzle = Instantiate(actionPuzzle, editeurTransform);
                    _actPuzzle.GetComponent <ManageDragAndDrop>().setGridPosition(currentAction.GetComponent <ManageDragAndDrop>().getGridPosition() + delta);
                    _actPuzzle.GetComponent <PuzzleScript>()._value = I._stringAction;
                }
                delta = new Vector2(0, -2);
            }
        }
        GameObject.Find("StartPuzzle").GetComponent <StartPuzzleScript>().UpdateAllValidPuzzles();
        ResetScrollBarEditorPosition();
    }