Skip to content

Commit a9a598a

Browse files
author
luzexi
committed
初级框架
初级框架
1 parent eb71a0d commit a9a598a

30 files changed

Lines changed: 768 additions & 0 deletions

AIBehaviorTree/AIBehaviorTree.sln

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AIBehaviorTree", "AIBehaviorTree\AIBehaviorTree.csproj", "{43D91877-7988-4C60-90A9-6E6281464D99}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{43D91877-7988-4C60-90A9-6E6281464D99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{43D91877-7988-4C60-90A9-6E6281464D99}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{43D91877-7988-4C60-90A9-6E6281464D99}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{43D91877-7988-4C60-90A9-6E6281464D99}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
EndGlobal
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Properties>
2+
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
3+
<MonoDevelop.Ide.Workbench ActiveDocument="AIBehaviorTree/AIManager.cs">
4+
<Files>
5+
<File FileName="AIBehaviorTree/AIManager.cs" Line="9" Column="1" />
6+
</Files>
7+
<Pads>
8+
<Pad Id="ProjectPad">
9+
<State expanded="True">
10+
<Node name="AIBehaviorTree" expanded="True">
11+
<Node name="References" expanded="True" />
12+
<Node name="AIManager.cs" selected="True" />
13+
</Node>
14+
</State>
15+
</Pad>
16+
<Pad Id="ClassPad">
17+
<State expanded="True" selected="True" />
18+
</Pad>
19+
<Pad Id="MonoDevelop.Debugger.WatchPad">
20+
<State>
21+
<Value>bytes[0]</Value>
22+
<Value>bytes[1]</Value>
23+
<Value>m</Value>
24+
<Value>n</Value>
25+
</State>
26+
</Pad>
27+
</Pads>
28+
</MonoDevelop.Ide.Workbench>
29+
<MonoDevelop.Ide.DebuggingService.Breakpoints>
30+
<BreakpointStore />
31+
</MonoDevelop.Ide.DebuggingService.Breakpoints>
32+
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
33+
</Properties>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{43D91877-7988-4C60-90A9-6E6281464D99}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>AIBehaviorTree</RootNamespace>
12+
<AssemblyName>AIBehaviorTree</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>True</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>False</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>True</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="System" />
35+
</ItemGroup>
36+
<ItemGroup>
37+
<Compile Include="ActionNode\BNodeActionNothing.cs" />
38+
<Compile Include="AIManager.cs" />
39+
<Compile Include="Base\BNodeAction.cs" />
40+
<Compile Include="Base\BNode.cs" />
41+
<Compile Include="Base\BNodeComposite.cs" />
42+
<Compile Include="Base\BNodeCondition.cs" />
43+
<Compile Include="Base\BNodeDecorator.cs" />
44+
<Compile Include="Base\BTree.cs" />
45+
<Compile Include="CompositeNode\BNodeParallel.cs" />
46+
<Compile Include="CompositeNode\Parallel\BNodeParallelHybird.cs" />
47+
<Compile Include="CompositeNode\Parallel\BNodeParallelSucceedOnAll.cs" />
48+
<Compile Include="CompositeNode\BNodeSelector.cs" />
49+
<Compile Include="CompositeNode\BNodeSequence.cs" />
50+
<Compile Include="CompositeNode\Parallel\BNodeParallelFallOnAll.cs" />
51+
<Compile Include="CompositeNode\Parallel\BNodeParallelSelector.cs" />
52+
<Compile Include="CompositeNode\Parallel\BNodeParallelSequence.cs" />
53+
<Compile Include="ConditionNode\BNodeConditionNothing.cs" />
54+
<Compile Include="DecoratorNode\BNodeDecoratorNothing.cs" />
55+
<Compile Include="Input\BInput.cs" />
56+
<Compile Include="Properties\AssemblyInfo.cs" />
57+
</ItemGroup>
58+
<ItemGroup />
59+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
60+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
61+
Other similar extension points exist, see Microsoft.Common.targets.
62+
<Target Name="BeforeBuild">
63+
</Target>
64+
<Target Name="AfterBuild">
65+
</Target>
66+
-->
67+
</Project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
4+
// AIManager.cs
5+
// Author: Lu Zexi
6+
// 2014-06-07
7+
8+
9+
10+
namespace Game.AIBehaviorTree
11+
{
12+
/// <summary>
13+
/// AI管理类
14+
/// </summary>
15+
public class AIManager
16+
{
17+
private static Dictionary<int, BTree> m_mapBTree = new Dictionary<int, BTree>(); //行为树集合
18+
19+
/// <summary>
20+
/// 新增行为树
21+
/// </summary>
22+
public void IncBTree()
23+
{
24+
for (int i = 1; ; i++)
25+
{
26+
if (!m_mapBTree.ContainsKey(i))
27+
{
28+
BTree bTree = new BTree();
29+
bTree.m_iID = i;
30+
m_mapBTree.Add(i, bTree);
31+
return;
32+
}
33+
}
34+
}
35+
36+
/// <summary>
37+
/// 删除行为树
38+
/// </summary>
39+
/// <param name="id"></param>
40+
public void RemoveBTree( int id )
41+
{
42+
if (m_mapBTree.ContainsKey(id))
43+
m_mapBTree.Remove(id);
44+
}
45+
46+
/// <summary>
47+
/// 获取行为树
48+
/// </summary>
49+
/// <param name="id"></param>
50+
/// <returns></returns>
51+
public BTree GetBTree( int id )
52+
{
53+
if (m_mapBTree.ContainsKey(id))
54+
return m_mapBTree[id];
55+
return null;
56+
}
57+
58+
/// <summary>
59+
/// 保存数据
60+
/// </summary>
61+
public void Save()
62+
{
63+
//
64+
}
65+
66+
/// <summary>
67+
/// 加载数据
68+
/// </summary>
69+
public void Load()
70+
{
71+
//
72+
}
73+
}
74+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
4+
5+
// BNodeActionNothing.cs
6+
// Author: Lu Zexi
7+
// 2014-06-07
8+
9+
10+
11+
namespace Game.AIBehaviorTree
12+
{
13+
/// <summary>
14+
/// 执行节点空闲
15+
/// </summary>
16+
public class BNodeActionNothing : BNodeAction
17+
{
18+
/// <summary>
19+
/// 执行
20+
/// </summary>
21+
/// <param name="input"></param>
22+
/// <returns></returns>
23+
public override bool Excute(BInput input)
24+
{
25+
return true;
26+
}
27+
}
28+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
4+
5+
6+
// BNode.cs
7+
// Author: Lu Zexi
8+
// 2014-06-07
9+
10+
11+
namespace Game.AIBehaviorTree
12+
{
13+
/// <summary>
14+
/// 节点类型
15+
/// </summary>
16+
public enum NODE_TYPE
17+
{
18+
NODE_ACTION = 1, //执行节点
19+
NODE_COMPOSITE = 2, //混合节点
20+
NODE_CONDITION = 3, //条件节点
21+
NODE_DECORATOR = 4, //装饰节点
22+
}
23+
24+
/// <summary>
25+
/// 行为树节点基类
26+
/// </summary>
27+
public abstract class BNode
28+
{
29+
protected NODE_TYPE m_eNodeType; //节点类型
30+
protected int m_iTypeID; //类型ID
31+
protected BNode m_cParent; //父节点
32+
protected List<BNode> m_lstChildren = new List<BNode>(); //子节点
33+
34+
/// <summary>
35+
/// 设置父节点
36+
/// </summary>
37+
/// <param name="node"></param>
38+
public void SetParent(BNode node)
39+
{
40+
this.m_cParent = node;
41+
}
42+
43+
/// <summary>
44+
/// 获取父节点
45+
/// </summary>
46+
/// <returns></returns>
47+
public BNode GetParent()
48+
{
49+
return this.m_cParent;
50+
}
51+
52+
/// <summary>
53+
/// 获取子节点列表
54+
/// </summary>
55+
/// <returns></returns>
56+
public List<BNode> GetNodeList()
57+
{
58+
return this.m_lstChildren;
59+
}
60+
61+
/// <summary>
62+
/// 获取子节点个数
63+
/// </summary>
64+
/// <returns></returns>
65+
public int GetChildCount()
66+
{
67+
return this.m_lstChildren.Count;
68+
}
69+
70+
/// <summary>
71+
/// 执行
72+
/// </summary>
73+
/// <returns></returns>
74+
public virtual bool Excute( BInput input )
75+
{
76+
return true;
77+
}
78+
79+
/// <summary>
80+
/// 增加子节点
81+
/// </summary>
82+
/// <param name="node"></param>
83+
public virtual void AddChild(BNode node)
84+
{
85+
this.m_lstChildren.Add(node);
86+
}
87+
88+
/// <summary>
89+
/// 交换子节点
90+
/// </summary>
91+
/// <param name="index1"></param>
92+
/// <param name="index2"></param>
93+
public virtual void SwapChild(int index1, int index2)
94+
{
95+
if (this.m_lstChildren.Count <= index1 || this.m_lstChildren.Count <= index2 || index1 < 0 || index2 < 0)
96+
{
97+
return;
98+
}
99+
100+
BNode node = this.m_lstChildren[index1];
101+
this.m_lstChildren[index1] = this.m_lstChildren[index2];
102+
this.m_lstChildren[index2] = this.m_lstChildren[index1];
103+
}
104+
105+
/// <summary>
106+
/// 删除子节点
107+
/// </summary>
108+
/// <param name="index"></param>
109+
public virtual void RemoveChild(int index)
110+
{
111+
if (this.m_lstChildren.Count <= index || index < 0 )
112+
{
113+
return;
114+
}
115+
this.m_lstChildren.RemoveAt(index);
116+
}
117+
118+
/// <summary>
119+
/// 读取数据
120+
/// </summary>
121+
public virtual void Read( List<string> lst ,ref int index)
122+
{
123+
this.m_eNodeType = (NODE_TYPE)(int.Parse(lst[index++]));
124+
this.m_iTypeID = int.Parse(lst[index++]);
125+
int count = int.Parse(lst[index++]);
126+
for (int i = 0; i < count; i++)
127+
{
128+
//
129+
}
130+
}
131+
132+
/// <summary>
133+
/// 写入数据
134+
/// </summary>
135+
/// <param name="lst"></param>
136+
public virtual void Write(List<string> lst) { }
137+
}
138+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
4+
5+
// BNodeAction.cs
6+
// Author: Lu Zexi
7+
// 2014-06-07
8+
9+
10+
namespace Game.AIBehaviorTree
11+
{
12+
/// <summary>
13+
/// 执行节点
14+
/// </summary>
15+
public class BNodeAction : BNode
16+
{
17+
}
18+
}

0 commit comments

Comments
 (0)