コード例 #1
0
    public override NeuTreeCB Run(IBlackBoard _blackboard)
    {
        blackboard = new Blackboard ();

        NeuTreeCB answer = new NeuTreeCB();
        answer.blackboard = blackboard;
        blackboard.Project(_blackboard);
        NeuTreeCB lowerAnswer = new NeuTreeCB ();
        for (int i = 0; i < lowerNodes.Count; i++) {
            lowerAnswer = lowerNodes[i].Run(blackboard);
            float fv = lowerAnswer.fireVal;
            if(lowerAnswer.replyFire == ReplyFire.Fail){
                answer.replyFire = ReplyFire.Fail;
                return answer;
            }
            else{
        //				for (int p = 0; p < lowerAnswer.blackboard.baseElementsPriority.Length; p++) {
        //					Debug.Log("before Lower AND Pririty "+lowerAnswer.blackboard.baseElementsPriority[p]);
        //				}
        //				for (int p = 0; p < blackboard.baseElementsPriority.Length; p++) {
        //					Debug.Log("before AND Pririty "+blackboard.baseElementsPriority[p]);
        //				}
                blackboard.Blend(lowerAnswer.blackboard, 1.0f);
        //				for (int p = 0; p < blackboard.baseElementsPriority.Length; p++) {
        //					Debug.Log("AND Pririty "+blackboard.baseElementsPriority[p]);
        //				}
            }
        }
        answer.replyFire = ReplyFire.Success;
        //		Debug.Log ("AND operator answer "+answer.replyFire);
        return answer;
    }
コード例 #2
0
    public override NeuTreeCB Run(IBlackBoard _blackboard)
    {
        blackboard = new Blackboard ();

        NeuTreeCB answer = new NeuTreeCB();
        answer.blackboard = blackboard;
        blackboard.Project(_blackboard);
        NeuTreeCB lowerAnswer = new NeuTreeCB ();
        blackboard.GetFunction(functionType).val += 1.0f * inputThreshold;
        answer.replyFire = ReplyFire.Success;
        return answer;
    }
コード例 #3
0
    public override NeuTreeCB Run(IBlackBoard _blackboard)
    {
        blackboard = new Blackboard ();

        NeuTreeCB answer = new NeuTreeCB();
        answer.blackboard = blackboard;
        blackboard.Project(_blackboard);
        NeuTreeCB lowerAnswer = new NeuTreeCB ();

        float nomDist = Mathf.ClosestPowerOfTwo(blackboard.subject.elProperties[PropertyType.Range].val);
        bool success = false;
        float thresholld = 0.01f;
        if (upperNode != null)
            thresholld = upperNode.inputThreshold;

        Debug.Log ("Checking distance of " + blackboard.functionStimuls[FunctionType.Movement].Keys.Count);
        List <int> el = new List<int> (blackboard.functionStimuls[FunctionType.Movement].Keys);

        for (int i = 0; i < el.Count; i++) {
            float dist  = Vector3.Magnitude(ElementsManager.gameElements[el[i]].transform.position - blackboard.subject.transform.position) / nomDist;

            Debug.Log("element id "+el[i]+" didtance to element "+dist+" threshold value "+thresholld);

            if(dist <= thresholld){
                blackboard.functionStimuls[FunctionType.Movement][el[i]] = 1 - dist;
                success = true;
            }
        }

        //		for (int p = 0; p < blackboard.baseElementsPriority.Length; p++) {
        //			Debug.Log("Distance Pririty "+blackboard.baseElementsPriority[p]);
        //		}

        if(!success){
            answer.replyFire = ReplyFire.Fail;
        }
        else{
            answer.replyFire = ReplyFire.Success;
        }
        //		Debug.Log ("Diastance filter answer "+answer.replyFire);
        return answer;
    }
コード例 #4
0
 public override NeuTreeCB Run(IBlackBoard _blackboard)
 {
     NeuTreeCB answer = new NeuTreeCB();
     answer.blackboard = blackboard;
     blackboard.Project(_blackboard);
     NeuTreeCB lowerAnswer = new NeuTreeCB ();
     for (int i = 0; i < lowerNodes.Count; i++) {
         lowerAnswer = lowerNodes[i].Run(blackboard);
         float fv = lowerAnswer.fireVal;
         if(fv < inputThreshold){
             answer.replyFire = ReplyFire.Fail;
             return answer;
         }
         else{
             blackboard.Blend(lowerAnswer.blackboard, 1.0f);
         }
     }
     answer.replyFire = ReplyFire.Success;
     return answer;
 }
コード例 #5
0
	public void Project (IBlackBoard other)	{

		Debug.Log ("Keys before");
		foreach (var item in other.functionStimuls.Keys) {
			Debug.Log("in "+item+" array there are "+other.functionStimuls[item].Keys.Count);			
		}

		functionStimuls.Clear ();
		functionStimuls = new Dictionary<FunctionType, Dictionary <int, float>> (other.functionStimuls);

		functions.Clear();
		for (int i = 0; i < other.functions.Count; i++) {
			functions.Add(new FunctionPower(other.functions[i].fType, 0.0f));
		}
		subject = other.subject;

		Debug.Log ("Keys after");
		foreach (var item in _functionStimuls.Keys) {
			Debug.Log("in "+item+" array there are "+_functionStimuls[item].Keys.Count);			
		}
	}
コード例 #6
0
    public override NeuTreeCB Run(IBlackBoard _blackboard)
    {
        blackboard = new Blackboard ();

        NeuTreeCB answer = new NeuTreeCB();
        answer.blackboard = blackboard;
        blackboard.Project(_blackboard);
        NeuTreeCB lowerAnswer = new NeuTreeCB ();

        float nomDist = Mathf.ClosestPowerOfTwo(blackboard.subject.elProperties[PropertyType.Range].val);
        bool success = false;
        float thresholld = 0.01f;
        if (upperNode != null)
            thresholld = upperNode.inputThreshold;
        for (int i = 0; i < blackboard.baseElements.Count; i++) {
            float dist  = Vector3.Magnitude(blackboard.baseElements[i].transform.position - blackboard.subject.transform.position) / nomDist;
            //			Debug.Log(blackboard.baseElements[i].gameObject.name+" "+dist+" "+thresholld);
            if(dist <= thresholld){
                blackboard.baseElementsPriority[i] = 1 - dist;
                success = true;
            }
        }

        //		for (int p = 0; p < blackboard.baseElementsPriority.Length; p++) {
        //			Debug.Log("Distance Pririty "+blackboard.baseElementsPriority[p]);
        //		}

        if(!success){
            answer.replyFire = ReplyFire.Fail;
        }
        else{
            answer.replyFire = ReplyFire.Success;
        }
        //		Debug.Log ("Diastance filter answer "+answer.replyFire);
        return answer;
    }
コード例 #7
0
	public void Blend (IBlackBoard other, float share)	{
		foreach (var item in other.functionStimuls.Keys) {
			if(functionStimuls.ContainsKey(item)){
				List <int> el = new List<int> (other.functionStimuls[item].Keys);
				for (int i = 0; i < el.Count; i++) {
					if(functionStimuls[item].ContainsKey(el[i])){
						functionStimuls[item][el[i]] = other.functionStimuls[item][el[i]] * share;
					}
				}
			}
		}

		for (int i = 0; i < functions.Count; i++) {
			functions[i].val += other.functions[i].val * share;
		}
	}
コード例 #8
0
 public Parallel(IBlackBoard bb, Policy sucPolicy = Policy.Ignore, Policy failPolicy = Policy.One)
 {
     successPolicy = sucPolicy;
     failurePolicy = failPolicy;
     blackBoard    = bb;
 }
コード例 #9
0
        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="blackBoard"></param>
        public void OnceFrame(long frame, IBlackBoard blackBoard)
        {
            actionFrame = frame;

            // 检查是否死亡
            if (Hp <= 0)
            {
                MemberManager.Remove(this);
                Debug.Log("单位死亡Id:" + Id);
                return;
            }
            if (IsLocal && IsAI)
            {
                if (pathList != null && pathList.Count > 0)
                {
                    // 继续前进
                    var nextNode = pathList.Pop();
                    Debug.Log("继续前进:" + nextNode.X + "," + nextNode.Y);
                    // 跑出显示命令, 并等待显示部分反馈的帧数
                    SendCmd(new Commend(MemberManager.FrameCount, Id, OptionType.Move)
                    {
                        Param = new Dictionary <string, string>()
                        {
                            { "fromX", "" + X },
                            { "fromY", "" + Y },
                            { "toX", "" + nextNode.X },
                            { "toY", "" + nextNode.Y },
                        }
                    });
                }
                else
                {
                    var width  = blackBoard.MapBase.MapWidth;
                    var height = blackBoard.MapBase.MapHeight;

                    var couldNotPass = true;
                    int targetX      = 0;
                    int targetY      = 0;

                    while (couldNotPass)
                    {
                        // 随机获取目标位置
                        targetX = RandomPacker.Single.GetRangeI(0, width);
                        targetY = RandomPacker.Single.GetRangeI(0, height);


                        var path = AStarPathFinding.SearchRoad(
                            BlackBoard.Single.MapBase.GetMapArray(MapManager.MapObstacleLayer),
                            X, Y,
                            targetX, targetY, 1, 1);

                        if (path != null && path.Count > 0)
                        {
                            couldNotPass = false;
                            pathList     = new Stack <Node>(path.ToArray());
                        }

                        var index = RandomPacker.Single.GetRangeI(0, MemberManager.MemberCount);

                        // 随机攻击一个目标
                        var targetMember = MemberManager.Get(index);
                        if (targetMember != null)
                        {
                            SendCmd(new Commend(MemberManager.FrameCount, targetMember.Id, OptionType.Attack)
                            {
                                Param = new Dictionary <string, string>()
                                {
                                    { "atkId", "" + Id },
                                    { "atkType", "" + 1 },
                                    { "dmg", "" + 10 },
                                }
                            });
                        }
                    }

                    // 向目标寻路, 如果不可达继续寻路
                    var nextNode = pathList.Pop();
                    Debug.Log("重新寻路前进:" + nextNode.X + "," + nextNode.Y);

                    // 跑出显示命令, 并等待显示部分反馈的帧数
                    SendCmd(new Commend(MemberManager.FrameCount, Id, OptionType.Move)
                    {
                        Param = new Dictionary <string, string>()
                        {
                            { "fromX", "" + X },
                            { "fromY", "" + Y },
                            { "toX", "" + nextNode.X },
                            { "toY", "" + nextNode.Y },
                        }
                    });
                }
            }
        }
コード例 #10
0
 public virtual NeuTreeCB Run(IBlackBoard _blackboard)
 {
     return null;
 }