Пример #1
0
 public NodeGene(NODETYPE nodeType, int id, int layer, float bias, ACTIVATION_FUNCTION activationFunction)
 {
     this.nodeType           = nodeType;
     this.id                 = id;
     this.layer              = layer;
     this.bias               = bias;
     this.activationFunction = activationFunction;
 }
Пример #2
0
 public void RemoveNode(NodeGraph node)
 {
     Nodes.Remove(node);
     if (Nodes.Count == 0)
     {
         Type = NODETYPE.ACTION;
     }
 }
Пример #3
0
 public void AddNode(NodeGraph node)
 {
     node.Parent = this;
     Nodes.Add(node);
     if (Type == NODETYPE.ACTION)
     {
         Type = NODETYPE.SEQUENCE;
     }
 }
Пример #4
0
        /// <summary>
        /// 将数据持久到数据库
        /// </summary>
        public void Persistent()
        {
            string sql = "INSERT INTO T_PROCESS(NID,ORIGIN,DESTINATION,TRANSITIONID,INSTANCEID,NODETYPE,RNID,OPERATION) VALUES(@NID,@ORIGIN,@DESTINATION,@TRANSITIONID,@INSTANCEID,@NODETYPE,@RNID,@OPERATION)";

            Connection.Execute(sql, new
            {
                NID          = Guid.NewGuid().ToString(),
                ORIGIN       = ORIGIN,
                DESTINATION  = DESTINATION,
                TRANSITIONID = TRANSITIONID,
                INSTANCEID   = INSTANCEID,
                NODETYPE     = NODETYPE.ToString(),
                RNID         = RNID,
                OPERATION    = OPERATION
            });
        }
Пример #5
0
 public NodeGene(NODETYPE nodeType, int id, int layer, bool biasExpressed, ACTIVATION_FUNCTION activationFunction)
 {
     this.nodeType = nodeType;
     this.id       = id;
     this.layer    = layer;
     neat          = GameObject.Find("Scripts").GetComponent <Neat>();
     if (biasExpressed)
     {
         bias = Random.Range(-neat.weightRange, neat.weightRange);
     }
     else
     {
         bias = 0;
     }
     this.activationFunction = activationFunction;
 }
Пример #6
0
 public ListNode(NODETYPE data, ListNode nextPtr, ListNode prevPtr)
 {
     m_NextPtr = nextPtr;
     m_PrevPtr = prevPtr;
     m_Data    = Object.ReferenceEquals(data as ValueType, null) ? (NODETYPE)(((ICloneable)data).Clone()) : data;
 }
Пример #7
0
 public ListNode(NODETYPE data, ListNode nextPtr)
 {
     m_NextPtr = nextPtr;
     m_Data    = data;
 }
Пример #8
0
 public ListNode(ListNode prevPtr, NODETYPE data)
 {
     m_PrevPtr = prevPtr;
     m_Data    = data;
 }
Пример #9
0
 public ListNode(NODETYPE data)
 {
     m_Data = data;
 }
Пример #10
0
        public bool parseContent()
        {
            _nCurNodeType = NODETYPE.NODETYPE_NA;

            int i    = (int)_nCursor;
            int imax = _strContent.Length - 1;

            if (i > imax)
            {
                _nCursor = -1;                 // force next string to be read from file
                return(true);
            }

            string strTemp = _strContent + i;

            // pass spaces if we are inside a <...> and not yet processing an attribute value
            while ((i <= imax) &&
                   (_bCurInsideNode && !_bCurInsideAttrib) &&
                   (_strContent[i] == ' ' || _strContent[i] == 0x0A || _strContent[i] == 0x0D))
            {
                i++;
            }

            if (i > imax)
            {
                _nCursor = -1;                 // force next string to be read from file
                return(true);
            }

            // are we inside a comment ?
            if (_bCurInsideComment)
            {
                while ((i <= imax - 2) &&
                       !(_strContent[i] == '-' && _strContent[i + 1] == '-' && _strContent[i + 2] == '>'))
                {
                    i++;
                }

                if (i <= imax - 2)                        // found an end-comment
                {
                    _nCurNodeType = NODETYPE.NODETYPE_NA; // tell user we have nothing to provide him with
                    _nCursor      = i + 2 + 1;

                    // after '-->' we are automatically within a content
                    _bCurInsideNode    = _bCurInsideAttrib = _bCurInsideComment = _bCurInsideCDATA = false;
                    _bCurInsideContent = true;
                    _strCurNodeContent = "";

                    return(true);
                }
                else                 // we still are inside an comment
                {
                    _nCurNodeType = NODETYPE.NODETYPE_COMMENT;
                    _nCursor      = imax + 1;              // force next string to be read
                    return(true);
                }
            }


            // are we inside a CDATA section ?
            if (_bCurInsideCDATA)
            {
                while ((i <= imax - 2) &&
                       !(_strContent[i] == ']' && _strContent[i + 1] == ']' && _strContent[i + 2] == '>'))
                {
                    i++;
                }

                if (i <= imax - 2)                        // found an end-comment
                {
                    _nCurNodeType = NODETYPE.NODETYPE_NA; // tell user we have nothing to provide him with
                    _nCursor      = i + 2 + 1;

                    // after ']]>' we are automatically within a content
                    _bCurInsideNode    = _bCurInsideAttrib = _bCurInsideComment = _bCurInsideCDATA = false;
                    _bCurInsideContent = true;
                    _strCurNodeContent = "";

                    return(true);
                }
                else                 // we still are inside an CDATA section
                {
                    _nCurNodeType = NODETYPE.NODETYPE_CDATA;
                    _nCursor      = imax + 1;              // force next string to be read
                    return(true);
                }
            }


            if (_bCurInsideAttrib)             // extracting the attrib value, possibly in multiple passes
            {
                if (_strCurAttribValue.Length == 0)
                {
                    // pass EOL
                    while ((i <= imax) && (_strContent[i] == ' ' || _strContent[i] == 0x0A || _strContent[i] == 0x0D))
                    {
                        i++;
                    }

                    if (i > imax)
                    {
                        _nCurNodeType = NODETYPE.NODETYPE_NA;
                        _nCursor      = i;
                        return(true);
                    }

                    char quotechar = _strContent[i++];

                    _strCurAttribValue += quotechar;                     // start with something whatsoever!
                    // in fact, we don't check the quotechar is an actual quotechar, ie " or '

                    _nCurNodeType = NODETYPE.NODETYPE_NA;
                    _nCursor      = i;
                    return(true);
                }
                else
                {
                    long ibegin = i;

                    // pass until we find spaces or EOL or >
                    while ((i <= imax) && _strContent[i] != '\"' &&
                           _strContent[i] != '\'' &&
                           _strContent[i] != 0x0A &&
                           _strContent[i] != 0x0D &&
                           _strContent[i] != '>')
                    {
                        i++;
                    }

                    // TODO : properly manage the case of a multiple-line attrib-value
                    // (we should in this case return a N/A nodetype as long as we haven't
                    // encountered the ending quotechar, while buffering all the chars in
                    // the strAttribValue member).

                    long iend = i;

                    _strCurAttribValue += _strContent.Substring((int)ibegin, (int)(iend - ibegin));

                    if (i > imax)
                    {                     // don't forget to add the EOL as well
                        _strCurAttribValue += "\r\n";

                        _nCurNodeType = NODETYPE.NODETYPE_NA;
                        _nCursor      = i;
                        return(true);
                    }

                    // and remove the prefixed quote char
                    while (_strCurAttribValue.Length != 0 &&
                           (_strCurAttribValue[0] == '\"' || _strCurAttribValue[0] == '\''))
                    {
                        _strCurAttribValue = _strCurAttribValue.Substring(1);
                    }

                    _nCurNodeType     = NODETYPE.NODETYPE_ATTRIB;
                    _bCurInsideAttrib = false;

                    if (_strContent[i] != '>')
                    {
                        i++;                         // pass ending quote char
                    }
                    _nCursor = i;
                    return(true);
                }
            }             // end if _bCurInsideAttrib==true


            if (_bCurInsideContent)
            {
                long ibegin = i;

                // pass until we find spaces or EOL or >
                while ((i <= imax) && _strContent[i] != 0x0A &&
                       _strContent[i] != 0x0D &&
                       _strContent[i] != '<')
                {
                    i++;
                }

                long iend = i;

                if ((i <= imax) && _strContent[i] == '<')
                {
                    _bCurInsideContent = false;
                }

                _strCurNodeContent = _strContent.Substring((int)ibegin, (int)(iend - ibegin));
                if (_strCurNodeContent.Length == 0)
                {
                    _nCurNodeType = NODETYPE.NODETYPE_NA;
                }
                else
                {
                    _nCurNodeType = NODETYPE.NODETYPE_CONTENT;
                }

                _nCursor = i;
                return(true);
            }             // end if (_bCurInsideContent)

            //
            char c = _strContent[i];

            // a node ?
            if (c == '<')
            {
                if (_bCurInsideNode)                 // error, we were already inside one
                {
                    _strLastError = IDS_BADBEGINNODESYMBOL;
                    return(false);
                }

                _bCurInsideNode   = true;
                _bCurInsideAttrib = _bCurInsideContent = _bCurInsideComment = _bCurInsideCDATA = false;

                i++;

                // pass spaces
                while (_strContent[i] == ' ' || _strContent[i] == 0x0A || _strContent[i] == 0x0D)
                {
                    i++;
                }

                if (i > imax)
                {
                    _strLastError = IDS_NOBEGINNODESYMBOLINEOL;
                    return(false);
                }

                // here we have either a node name, a PI, or a begin comment
                if (imax - i >= 2)             // is it a begin comment ? ( <!-- )
                {
                    if (_strContent[i + 0] == '!' &&
                        _strContent[i + 1] == '-' &&
                        _strContent[i + 2] == '-')
                    {
                        _nCurNodeType      = NODETYPE.NODETYPE_COMMENT;
                        _bCurInsideComment = true;

                        i += 3;                       // go to actual comment content

                        _nCursor = i;
                        return(true);
                    }
                }

                if (imax - i >= 7)             // is it a begin cdatasection ? ( <![CDATA[ )
                {
                    if (_strContent[i + 0] == '!' &&
                        _strContent[i + 1] == '[' &&
                        _strContent[i + 2] == 'C' &&
                        _strContent[i + 3] == 'D' &&
                        _strContent[i + 4] == 'A' &&
                        _strContent[i + 5] == 'T' &&
                        _strContent[i + 6] == 'A' &&
                        _strContent[i + 7] == '[')
                    {
                        _nCurNodeType    = NODETYPE.NODETYPE_CDATA;
                        _bCurInsideCDATA = true;

                        i += 8;                       // go to actual cdata section content

                        _nCursor = i;
                        return(true);
                    }
                }


                // the node name begins at position i
                long ibegin = i;

                // pass until we find spaces or EOL or >
                while ((i <= imax) && _strContent[i] != ' ' &&
                       _strContent[i] != 0x0A &&
                       _strContent[i] != 0x0D &&
                       (_strContent[i] != '/' || (i == ibegin)) &&      // don't forget empty elements (for instance <br/>)
                       _strContent[i] != '>')
                {
                    i++;
                }

                long iend = i;

                _strCurNodeName = _strContent.Substring((int)ibegin, (int)(iend - ibegin));
                if (_strCurNodeName.Length == 0)
                {
                    _strLastError = IDS_EMPTYELEMENTNAME;
                    return(false);
                }


                if (_strCurNodeName[0] == '?' || _strCurNodeName[0] == '!')
                {
                    _nCurNodeType       = NODETYPE.NODETYPE_PI;
                    _strCurPInstruction = _strCurNodeName;
                    _strCurNodeName     = "";                 // erase the PI instruction so it does not appear as a node name
                }
                else if (_strCurNodeName[0] == '/')
                {
                    _nCurNodeType   = NODETYPE.NODETYPE_ENDELEMENT;
                    _strCurNodeName = _strCurNodeName.Substring(1);                     // remove /
                }
                else
                {
                    _nCurNodeType = NODETYPE.NODETYPE_BEGINELEMENT;
                }

                _nCursor = i;
                return(true);
            }
            else             // >, or ?, or content or attribute
            {
                if (c == '?')
                {
                    _nCurNodeType = NODETYPE.NODETYPE_NA;
                    _nCursor      = i + 1;
                    return(true);
                }
                else if (c == '/')
                {
                    i++;

                    // pass node name
                    long ibegin = i;

                    // pass until we find spaces or EOL or >
                    while ((i <= imax) && _strContent[i] != ' ' &&
                           _strContent[i] != 0x0A &&
                           _strContent[i] != 0x0D &&
                           _strContent[i] != '>')
                    {
                        i++;
                    }

                    long iend = i;

                    _nCurNodeType = NODETYPE.NODETYPE_ENDELEMENT;

                    _nCursor = i;
                    return(true);
                }
                else if (c == '>')
                {
                    _bCurInsideNode    = _bCurInsideAttrib = false;
                    _bCurInsideContent = true;
                    _strCurNodeContent = "";
                    _nCurNodeType      = NODETYPE.NODETYPE_NA;
                    _nCursor           = i + 1;
                    return(true);
                }

                if (_bCurInsideNode)                 // attributes
                {
                    if (!_bCurInsideAttrib)
                    {
                        if (c == '=')
                        {
                            _nCurNodeType     = NODETYPE.NODETYPE_NA;
                            _bCurInsideAttrib = true;        // enable extraction of the associated attribute value

                            i++;                             // pass '=' symbol

                            _nCursor = i;
                            return(true);
                        }

                        // get attribute name
                        long ibegin = i;

                        // pass until we find spaces or EOL or >
                        while ((i <= imax) && _strContent[i] != ' ' &&
                               _strContent[i] != 0x0A &&
                               _strContent[i] != 0x0D &&
                               _strContent[i] != '=' &&
                               _strContent[i] != '>')                           // check against > is just for safety
                        {
                            i++;
                        }

                        long iend = i;

                        _strCurAttribName = _strContent.Substring((int)ibegin, (int)(iend - ibegin));
                        if (_strCurAttribName.Length == 0)
                        {
                            _strLastError = IDS_MISSINGATTRIBNAME;
                            return(false);
                        }

                        _strCurAttribValue = "";                         // make sure the attrib value is empty for the moment
                        _nCurNodeType      = NODETYPE.NODETYPE_NA;

                        _nCursor = i;
                        return(true);
                    }
                }
            }

            // this code never executes
            _strLastError = IDS_GENERICSYNTAXERROR;
            return(false);
        }
Пример #11
0
    float moveByPanel(string panelName)
    {
        GraphNode node = null;
        NODETYPE  type = NODETYPE.NOTEXIST;

        if ((panelName.CompareTo("Go") == 0 || panelName.CompareTo("Jump") == 0 || panelName.CompareTo("Action") == 0))
        {
            node = findFrontNode(curNode.Neighbour);
            if (node != null)
            {
                type = getNodeType(node);
            }
        }
        for (int i = 0; i < selectedRobot.transform.GetChild(0).childCount; i++)
        {
            AnimationAgent.Instance.Animators[selectedRobot.transform.GetChild(0).GetChild(i).name].speed = Constants.Time * speed;
        }

        float time = AnimationAgent.Instance.Animators[selectedRobot.transform.GetChild(0).GetChild(0).name].GetCurrentAnimatorClipInfo(0)[0].clip.length;

        selectedRobot.transform.position = curNode.BoxData.Position + new Vector3(0, 0.23f, 0);

        switch (panelName)
        {
        case "Go":
            for (int i = 0; i < selectedRobot.transform.GetChild(0).childCount; i++)
            {
                AnimationAgent.Instance.setInteger(selectedRobot.transform.GetChild(0).GetChild(i).name, "State", 2);
            }

            time = ResourcesManager.Instance.animationClips["robot_walk"].length - 0.1f;

            if (node != null && !node.Equals(curNode) && type == NODETYPE.MID && node.BoxData.Traversable == true)
            {
                MoveAgent.Instance.MoveTo(selectedRobot.gameObject, node.BoxData.Position, time / speed);
                curNode = node;
            }
            break;

        case "Jump":
            if (node != null && node.BoxData.Traversable == true)
            {
                if (type == NODETYPE.TOP)
                {
                    for (int i = 0; i < selectedRobot.transform.GetChild(0).childCount; i++)
                    {
                        AnimationAgent.Instance.setInteger(selectedRobot.transform.GetChild(0).GetChild(i).name, "State", 4);
                    }

                    AnimationAgent.Instance.Animators[selectedRobot.name].speed = Constants.Time * speed;
                    AnimationAgent.Instance.Animators[selectedRobot.name].Play("JumpUp", 0, 0);


                    time = ResourcesManager.Instance.animationClips["JumpUp"].length;

                    curNode = node;
                }
                else if (type == NODETYPE.BOTTOM)
                {
                    for (int i = 0; i < selectedRobot.transform.GetChild(0).childCount; i++)
                    {
                        AnimationAgent.Instance.setInteger(selectedRobot.transform.GetChild(0).GetChild(i).name, "State", 3);
                    }

                    AnimationAgent.Instance.Animators[selectedRobot.name].speed = Constants.Time * speed;
                    AnimationAgent.Instance.Animators[selectedRobot.name].Play("JumpDown", 0, 0);

                    time = ResourcesManager.Instance.animationClips["JumpDown"].length;

                    curNode = node;
                }
            }

            break;

        case "Left":
            for (int i = 0; i < selectedRobot.transform.GetChild(0).childCount; i++)
            {
                AnimationAgent.Instance.setInteger(selectedRobot.transform.GetChild(0).GetChild(i).name, "State", 5);
            }

            time = ResourcesManager.Instance.animationClips["robot_turn_L"].length - 0.1f;
            StartCoroutine(MoveAgent.Instance.turnLeft(selectedRobot, time / speed));
            break;

        case "Right":
            for (int i = 0; i < selectedRobot.transform.GetChild(0).childCount; i++)
            {
                AnimationAgent.Instance.setInteger(selectedRobot.transform.GetChild(0).GetChild(i).name, "State", 6);
            }

            time = ResourcesManager.Instance.animationClips["robot_turn_R"].length - 0.1f;
            StartCoroutine(MoveAgent.Instance.turnRight(selectedRobot, time / speed));

            break;

        case "Action":
            for (int i = 0; i < selectedRobot.transform.GetChild(0).childCount; i++)
            {
                AnimationAgent.Instance.setInteger(selectedRobot.transform.GetChild(0).GetChild(i).name, "State", 0);
            }

            time = ResourcesManager.Instance.animationClips["robot_idle1"].length;

            if (type != NODETYPE.NOTEXIST && node != null && !curNode.BoxData.Name.Contains("warp"))
            {
                if (!node.BoxData.Name.Contains("pollution"))
                {
                    GameObject oilTank = null;
                    for (int i = 0; i < objectsParent.transform.childCount; i++)
                    {
                        var child = objectsParent.transform.GetChild(i);
                        if (!child.name.Contains("BoringMachine"))
                        {
                            continue;
                        }

                        if (node.BoxData.Position + new Vector3(0, 0.55f, 0) == child.position)
                        {
                            oilTank = child.gameObject;
                        }
                    }

                    if (oilTank != null && oilTank.transform.GetChild(1).gameObject.activeSelf)
                    {
                        Utility.Instance.delayAction(0.5f, () => oilTank.transform.GetChild(1).GetComponent <Boringmachine>().playAnimation(speed));

                        for (int i = 0; i < selectedRobot.transform.GetChild(0).childCount; i++)
                        {
                            AnimationAgent.Instance.setInteger(selectedRobot.transform.GetChild(0).GetChild(i).name, "State", 7);
                        }

                        //time = ResourcesManager.Instance.animationClips["robot_attack"].length - 0.1f;
                        time = 1.5f;
                        level.Count--;
                        //curNode = node;
                        node.BoxData.Traversable = true;
                    }
                }
                else if (node.BoxData.Name.Contains("pollution") && !listOfEnemy.Contains(node.BoxData))
                {
                    for (int i = 0; i < selectedRobot.transform.GetChild(0).childCount; i++)
                    {
                        AnimationAgent.Instance.setInteger(selectedRobot.transform.GetChild(0).GetChild(i).name, "State", 8);
                    }

                    time = ResourcesManager.Instance.animationClips["robot_spell2"].length + ResourcesManager.Instance.animationClips["robot_spell2"].length - 0.1f;


                    node.BoxData.Traversable = true;
                    level.Count--;
                    for (int i = 0; i < boxParent.transform.childCount; i++)
                    {
                        var box = boxParent.transform.GetChild(i);
                        if (box.position == node.BoxData.Position)
                        {
                            Utility.Instance.delayAction(time / speed, () =>
                            {
                                box.GetComponent <Renderer>().material.mainTexture = ResourcesManager.Instance.sprites["box_basic"].texture;
                            });
                        }
                    }
                    listOfEnemy.Add(node.BoxData);
                }
            }
            else if (curNode.BoxData.Name.Contains("warp"))
            {
                Debug.Log("warp");

                for (int i = 0; i < selectedRobot.transform.GetChild(0).childCount; i++)
                {
                    AnimationAgent.Instance.setInteger(selectedRobot.transform.GetChild(0).GetChild(i).name, "State", 1);
                }

                time = ResourcesManager.Instance.animationClips["robot_idle1"].length - 0.1f;

                if (step == 1 && stage == 3)
                {
                    level.Count--;
                }
                for (int j = 0; j < curNode.Neighbour.Count; j++)
                {
                    var neighbour = curNode.Neighbour[j];

                    if (curNode.BoxData.Position == neighbour.BoxData.Position || curNode.BoxData.Name.CompareTo(neighbour.BoxData.Name) != 0)
                    {
                        continue;
                    }

                    Debug.Log(neighbour.BoxData.Position);
                    Debug.Log(neighbour.BoxData.Name);

                    curNode = neighbour;
                }
            }
            else
            {
                GameObject oilTank = null;
                for (int i = 0; i < objectsParent.transform.childCount; i++)
                {
                    var child = objectsParent.transform.GetChild(i);
                    if (!child.name.Contains("BoringMachine"))
                    {
                        continue;
                    }

                    int rotationY = (int)Mathf.Round(selectedRobot.transform.localEulerAngles.y / 10) * 10;
                    switch (rotationY)
                    {
                    case 0:
                        if (child.position == selectedRobot.transform.position + new Vector3(0, 0.07f, -0.25f) ||
                            child.position == selectedRobot.transform.position + new Vector3(0, -0.18f, -0.25f) ||
                            child.position == selectedRobot.transform.position + new Vector3(0, 0.32f, -0.25f))
                        {
                            oilTank = child.gameObject;
                        }
                        break;

                    case 90:
                        if (child.position == selectedRobot.transform.position + new Vector3(-0.25f, 0.07f, 0) ||
                            child.position == selectedRobot.transform.position + new Vector3(-0.25f, -0.18f, 0) ||
                            child.position == selectedRobot.transform.position + new Vector3(-0.25f, 0.32f, 0))
                        {
                            oilTank = child.gameObject;
                        }
                        break;

                    case 180:
                        if (child.position == selectedRobot.transform.position + new Vector3(0, 0.07f, 0.25f) ||
                            child.position == selectedRobot.transform.position + new Vector3(0, -0.18f, 0.25f) ||
                            child.position == selectedRobot.transform.position + new Vector3(0, 0.32f, 0.25f))
                        {
                            oilTank = child.gameObject;
                        }
                        break;

                    case 270:
                        if (child.position == selectedRobot.transform.position + new Vector3(0.25f, 0.07f, 0) ||
                            child.position == selectedRobot.transform.position + new Vector3(0.25f, -0.18f, 0) ||
                            child.position == selectedRobot.transform.position + new Vector3(0.25f, 0.32f, 0))
                        {
                            oilTank = child.gameObject;
                        }
                        break;
                    }
                }

                if (oilTank != null && oilTank.transform.GetChild(1).gameObject.activeSelf)
                {
                    Debug.Log(oilTank.transform.position);
                    Utility.Instance.delayAction(0.5f, () => oilTank.transform.GetChild(1).GetComponent <Boringmachine>().playAnimation(speed));

                    for (int i = 0; i < selectedRobot.transform.GetChild(0).childCount; i++)
                    {
                        AnimationAgent.Instance.setInteger(selectedRobot.transform.GetChild(0).GetChild(i).name, "State", 7);
                    }

                    time = 1.5f;
                    level.Count--;
                }
            }
            break;
        }

        return(time / speed);
    }