Commits

Anonymous committed c869f69

first commit

Comments (0)

Files changed (24)

+syntax: glob
+*.user
+*.ncb
+*.suo
+*.htm
+*.lib
+*.idb
+*.dep
+*.aps
+*.res
+*.manifest
+
+/Debug
+/Release

AIStateMachine.cs

+using System;
+using System.Collections.Generic;
+using System.Text;
+using PH.Common;
+using System.Drawing;
+using PH.Map;
+
+namespace SuperStar
+{
+    //所有状态的抽象接口类
+    public abstract class AIStateMachine
+    {
+        public  enum AIACTION_MEET_ENEMY
+        {
+            NORMAL,
+            STOP,
+            ESCAPE
+        }
+
+        protected Team m_Team;
+        public AIStateMachine(Team team)
+        {
+            m_Team = team;
+        }
+        public AI AI
+        {
+            get { return m_Team.AI; }
+        }
+        public Team Team
+        {
+            get { return m_Team; }
+        }
+        public abstract void DoAction();
+
+        protected virtual AIACTION_MEET_ENEMY GetAction()
+        {
+            MapAdapter ma = MapAdapter.Instance;
+            if (ma.TempThreat[AI.Location.X, AI.Location.Y] > 0)
+            {
+                Team.SetThreatPoint();
+                if (ma.TempAttackInfo[AI.Location.X, AI.Location.Y] > 0)
+                {
+                    return AIACTION_MEET_ENEMY.ESCAPE;
+                }
+                else
+                {
+                    return AIACTION_MEET_ENEMY.STOP;
+                }
+            }
+            else
+            {
+                return AIACTION_MEET_ENEMY.NORMAL;
+            }
+        }
+        protected AIACTION_MEET_ENEMY GetLandingAction()
+        {
+            if (EnemyMgr.Instance.AIInfo != null)
+            {
+                int nDistance = MathTools.SquareDistance(EnemyMgr.Instance.AILocation, AI.Location);
+                if (nDistance <= 225)
+                {
+                    return AIACTION_MEET_ENEMY.ESCAPE;
+                }
+            }
+            if (MapAdapter.Instance.TempAttackInfo[AI.Location.X, AI.Location.Y] > 0)
+            {
+                return AIACTION_MEET_ENEMY.ESCAPE;
+            }
+            return AIACTION_MEET_ENEMY.NORMAL;
+        }
+
+        protected bool Build(Type typeBuild)
+        {
+            if (LandingPointCreator.Set.Count > 0 && LandingPointCreator.Set[0].State == BotState.CreatingLP)
+            {
+                return AI.Build(typeBuild, "", LandingPointCreator.Set[0]);
+            }
+            else
+            {
+                return AI.Build(typeBuild);
+            }
+        }
+
+        protected bool IsNearToOtherLandingPoint(Point[] path)
+        {
+            if(path == null)
+                return true;
+
+            if (EnemyMgr.Instance.LandPointFinded)
+            {
+                int nDistance = MathTools.SquareDistance(EnemyMgr.Instance.LandPoint, AI.Location);
+                foreach (Point pt in path)
+                {
+                    //
+                    if (MathTools.SquareDistance(pt, EnemyMgr.Instance.LandPoint) < nDistance)
+                    {
+                        return true;
+                    }
+                }
+                
+            }
+            return false;
+        }
+        protected int GetBeatStrong(MiniBroadTree.BroadTreePointInfo bpi,Point[] path )
+        {
+            if (path == null)//返回最大值
+                return 400;
+            Point ptLast = path[path.Length - 1];
+            if (MapAdapter.Instance.TempAttackInfo[ptLast.X, ptLast.Y] > 0)//还没有跑到安全范围
+            {
+                return bpi._nWeight * bpi._nTurns * 5*2 / 800/3;//800是除8再除100,除8表示计算在每点的平均威胁系数,除100是计算攻击者的个数
+            }
+            else//已经跑出了安全范围
+            {
+                return bpi._nWeight * bpi._nTurns * 5 / 1600;//800是除8再除100,除8表示计算在每点的平均威胁系数,除100是计算攻击者的个数
+            }
+        }
+    }
+    #region 基地在登录点:Hosimi点的状态***
+    public class AILandingOnHosimiState:AIStateMachine
+    {
+        public AILandingOnHosimiState(Team team)
+            : base(team)
+        {            
+        }
+        public bool NormalBuildTask()//正常情况下的建造顺序
+        {
+            if (MyBots.Instance.IsNeedPioneer())
+            {
+                AI.Build(typeof(Pioneer));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedScouter())
+            {
+                AI.Build(typeof(Scouter));
+                return true;
+            }
+            if (MissionMgr.Instance.BuildUniqueMissionBot(Team))
+            {
+                return true;
+            }
+            if (MyBots.Instance.IsNeedWorker())
+            {
+                AI.Build(typeof(Worker));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedHardWorker())
+            {
+                AI.Build(typeof(HardWorker));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedKiller())
+            {
+                AI.Build(typeof(Killer));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedAIProtector())
+            {
+                AI.Build(typeof(AIProtector));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedLPCreator())
+            {
+                AI.Build(typeof(LandingPointCreator));
+                return true;
+            }            
+            return false;
+        }
+        public override void DoAction()
+        {
+            #region 没有创建存矿needle
+            if (!StockNeedle.Set.ContainsKey(AI.Location) &&
+                !EnemyMgr.Instance.SafeNeedles.ContainsKey(AI.Location) &&
+                !EnemyMgr.Instance.AllNeedles.ContainsKey(AI.Location))
+            {
+                AI.Build(typeof(StockNeedle));
+                return;
+            }
+            #endregion
+
+            #region 在敌人的wall中
+            if (EnemyMgr.Instance.IsInWall(AI.Location))
+            {
+                NormalBuildTask();
+                return;
+            }
+            #endregion
+
+            //检测敌人
+            AIACTION_MEET_ENEMY action = GetLandingAction();
+            if (action == AIACTION_MEET_ENEMY.ESCAPE)
+            {
+                MiniBroadTree.BroadTreePointInfo bpi;
+                Point[] path = SafePoint.GetSafePath(AI.Location, 8, out bpi);
+
+                int nBeated = GetBeatStrong(bpi, path);
+                //打击足够大或逃跑路线离对手基地越来越近
+                if (nBeated >= AI.Constitution + AI.Shield || IsNearToOtherLandingPoint(path))//躲在安全点
+                {
+                    NormalBuildTask();
+                    return;
+                }
+                else
+                {
+                    Team.AIState = new AIEscapeFromLandingState(Team, path);
+                    return;
+                }
+            }
+            else if (action == AIACTION_MEET_ENEMY.STOP)
+            {
+                NormalBuildTask();
+                return;
+            }
+
+            //正常状态下,检测建造状况
+            if (NormalBuildTask())
+                return;
+
+            Team.AIState = new AIMovingState(Team);
+            return;
+        }
+    }
+    #endregion
+
+    #region 从登录点进行逃跑的状态***
+    public class AIEscapeFromLandingState : AIStateMachine
+    {
+        public AIEscapeFromLandingState(Team team, Point pt)
+            : base(team)
+        {
+            AI.StopMoving();
+            AI.MoveTo(AStarPathFinder.Instance.GetPathPoint(AI.Location, pt));
+        }
+        public AIEscapeFromLandingState(Team team, Point[] path)
+            : base(team)
+        {
+            AI.StopMoving();
+            AI.MoveTo(path);
+        }
+
+        //在同一种状态下的建造总数有限,防止制造-死亡-制造的怪圈,因为该状态下LPCreator和Scouter有可能会从出生点向基地靠近,从而给对手攻击的机会
+        int m_nLPCreatorBuildCntr = 0;
+        int m_nScouterBuildCntr = 0;
+        public bool NormalBuildTask()//正常情况下的建造顺序
+        {
+            if(!ProtectNeedle.Set.ContainsKey(AI.Location))
+            {
+                AI.Build(typeof(ProtectNeedle));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedPioneer())
+            {
+                AI.Build(typeof(Pioneer));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedScouter() && m_nScouterBuildCntr<2)
+            {
+                m_nScouterBuildCntr++;
+                AI.Build(typeof(Scouter));
+                return true;
+            }
+            if (MissionMgr.Instance.BuildUniqueMissionBot(Team))
+            {
+                return true;
+            }
+            if (MyBots.Instance.IsNeedWorker())
+            {
+                AI.Build(typeof(Worker));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedHardWorker())
+            {
+                AI.Build(typeof(HardWorker));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedKiller())
+            {
+                AI.Build(typeof(Killer));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedAIProtector())
+            {
+                AI.Build(typeof(AIProtector));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedLPCreator() && m_nLPCreatorBuildCntr<2)
+            {
+                m_nLPCreatorBuildCntr++;
+                AI.Build(typeof(LandingPointCreator));
+                return true;
+            }
+            return false;
+        }
+
+        //遇一般敌人的建造状况
+        //遇到对手基地的建造状况
+        public override void DoAction()
+        {
+            if (EnemyMgr.Instance.IsInWall(AI.Location))//在敌人的wall中
+            {
+                NormalBuildTask();
+                return;
+            }
+            //检测敌人
+            AIACTION_MEET_ENEMY action = GetAction();
+            if (action == AIACTION_MEET_ENEMY.ESCAPE)
+            {
+                //Point ptSafe = SafePoint.GetSafePoint(AI.Location);
+                //AI.StopMoving();
+                //AI.MoveTo(AStarPathFinder.Instance.GetPathPoint(AI.Location, ptSafe));
+                Point[] path = SafePoint.GetSafePath(AI.Location, 8);
+                AI.StopMoving();
+                AI.MoveTo(path);
+                return;
+            }
+            else if (action == AIACTION_MEET_ENEMY.STOP)
+            {
+                AI.StopMoving();
+                NormalBuildTask();
+                return;
+            }
+            else//没有威胁的情况
+            {
+                if (NormalBuildTask())
+                    return;
+
+                Team.AIState = new AIMovingState(Team);
+            }
+            return;         
+        }
+    }
+    #endregion
+
+    #region 基地在登录点:非Hosimi点的状态***
+    public class AILandingOnOtherState : AIStateMachine
+    {
+        public AILandingOnOtherState(Team team)
+            : base(team)
+        {
+        }
+        public bool NormalBuildTask()//正常情况下的建造顺序
+        {
+            if (MyBots.Instance.IsNeedPioneer())
+            {
+                AI.Build(typeof(Pioneer));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedScouter())
+            {
+                AI.Build(typeof(Scouter));
+                return true;
+            }
+            if (MissionMgr.Instance.BuildUniqueMissionBot(Team))
+            {
+                return true;
+            }
+            if (MyBots.Instance.IsNeedWorker())
+            {
+                AI.Build(typeof(Worker));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedHardWorker())
+            {
+                AI.Build(typeof(HardWorker));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedKiller())
+            {
+                AI.Build(typeof(Killer));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedAIProtector())
+            {
+                AI.Build(typeof(AIProtector));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedLPCreator())
+            {
+                AI.Build(typeof(LandingPointCreator));
+                return true;
+            }
+            return false;
+        }
+        public override void DoAction()
+        {
+            //判断是否在敌人的wall中
+            if (EnemyMgr.Instance.IsInWall(AI.Location))
+            {
+                NormalBuildTask();
+                return;
+            }
+            //检测敌人
+            AIACTION_MEET_ENEMY action = GetLandingAction();
+            if (action == AIACTION_MEET_ENEMY.ESCAPE)
+            {
+                MiniBroadTree.BroadTreePointInfo bpi;
+                Point[] path = SafePoint.GetSafePath(AI.Location, 8, out bpi);
+
+                int nBeated = GetBeatStrong(bpi, path);
+                if (nBeated >= AI.Constitution + AI.Shield || IsNearToOtherLandingPoint(path))//躲在安全点
+                {
+                    NormalBuildTask();
+                    return;
+                }
+                else
+                {
+                    Team.AIState = new AIEscapeFromLandingState(Team, path);
+                    return;
+                }
+            }
+            else if (action == AIACTION_MEET_ENEMY.STOP)
+            {
+                NormalBuildTask();
+                return;
+            }
+
+            //正常状态下,检测建造状况
+            if (NormalBuildTask())
+                return;
+
+            Team.AIState = new AIMovingState(Team);
+            return;
+        }
+    }
+    #endregion
+
+    //基地在移动过程中的其它点
+    public class AIMovingState : AIStateMachine
+    {
+        Point m_ptDestHosimi = Point.Empty;
+
+        public AIMovingState(Team team)
+            : base(team)
+        {
+            //执行默认动作
+            m_ptDestHosimi = StrategyCenter.Instance.GetNextHosimiPoint(AI.Location);
+            AI.StopMoving();
+            AI.MoveTo(AStarPathFinder.Instance.GetPathPointHT(AI.Location,m_ptDestHosimi));
+        }
+        public bool IsNearToOXY()
+        {
+            //部队数量太多,忽略
+            if (Team.Bots.Count >= 38)
+                return false;
+            //已经靠近
+            bool bNeedProtected = false;
+            Point ptOxy = Point.Empty;
+
+            foreach(Entity et in MapAdapter.Instance.AllOXYS)
+            {
+                if (MathTools.SquareDistance(AI.Location, et.Location) <= 169)
+                {
+                    bNeedProtected = true;
+                    ptOxy = et.Location;
+                    break;
+                }
+            }
+            if (!bNeedProtected) return false;
+
+            //
+            Point[] path = AStarPathFinder.Instance.GetPathPointHT(AI.Location, m_ptDestHosimi);
+            if (MathTools.SquareDistance(ptOxy, AI.Location) > MathTools.SquareDistance(ptOxy, path[0]))
+            {
+                return false;
+            }
+
+            //
+            foreach (Point pt in ProtectNeedle.Set.Keys)
+            {
+                if (MathTools.SquareDistance(pt, ptOxy) <= 169)//已经造了
+                {
+                    return false;
+                }
+            }
+
+            AI.StopMoving();
+            AI.Build(typeof(ProtectNeedle));
+            return true;
+
+        }
+
+        public override void DoAction()
+        {
+            if (AI.Location == m_ptDestHosimi)
+            {
+                AI.StopMoving();
+                Team.AIState = new AIOnHosimiState(Team);
+                return;
+            }
+            AIACTION_MEET_ENEMY action = GetAction();
+            if (action == AIACTION_MEET_ENEMY.ESCAPE)
+            {
+                MiniBroadTree.BroadTreePointInfo bpi;
+                Point[] path = SafePoint.GetSafePath(AI.Location, 8, out bpi);
+                if (GetBeatStrong(bpi, path) >= AI.Constitution + AI.Shield)//不能承受,不能再跑
+                {
+                    Team.AIState = new AIStopAtOtherState(Team);
+                }
+                else
+                {
+                    Team.AIState = new AIEscapeState(Team, path);  
+                }
+                              
+                return;
+            }
+            else if (action == AIACTION_MEET_ENEMY.STOP)
+            {
+                Team.AIState = new AIStopAtOtherState(Team);
+                return;
+            }
+            else//没有威胁的情况
+            {
+                if (EnemyMgr.Instance.IsInForerverThreat(m_ptDestHosimi))
+                {
+                    m_ptDestHosimi = StrategyCenter.Instance.GetNextHosimiPoint(AI.Location);
+                    AI.StopMoving();
+                    AI.MoveTo(AStarPathFinder.Instance.GetPathPointHT(AI.Location, m_ptDestHosimi));
+                    return;
+                }
+
+                //
+                if (AI.State == BotState.WaitingOrders)
+                {
+                    AI.MoveTo(AStarPathFinder.Instance.GetPathPointHT(AI.Location, m_ptDestHosimi));
+                }
+            }
+        }
+    }
+
+    //基地在Hosimi点上的情况
+    public class AIOnHosimiState : AIStateMachine
+    {
+        public AIOnHosimiState(Team team)
+            : base(team)
+        {
+            //执行默认动作
+            AI.StopMoving();
+            AI.Build(typeof(StockNeedle));
+        }
+
+        //在同一种状态下的建造总数有限,防止制造-死亡-制造的怪圈,因为该状态下LPCreator和Scouter有可能会从出生点向基地靠近,从而给对手攻击的机会
+        int m_nScouterBuildCntr = 0;
+        bool NormalBuildTask()//正常情况下的建造顺序
+        {
+            //Needle被打死或者没有建造
+            if (!StockNeedle.Set.ContainsKey(AI.Location))
+            {
+                AI.Build(typeof(StockNeedle));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedPioneer())
+            {
+                AI.Build(typeof(Pioneer));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedScouter() && m_nScouterBuildCntr < 2)
+            {
+                m_nScouterBuildCntr++;
+                AI.Build(typeof(Scouter));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedWorker())
+            {
+                AI.Build(typeof(Worker));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedHardWorker())
+            {
+                AI.Build(typeof(HardWorker));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedKiller())
+            {
+                AI.Build(typeof(Killer));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedAIProtector())
+            {
+                AI.Build(typeof(AIProtector));
+                return true;
+            }
+            return false;
+        }
+        bool ErgentBuildTask()
+        {
+            //Needle被打死或者没有建造
+            if (!StockNeedle.Set.ContainsKey(AI.Location))
+            {
+                AI.Build(typeof(StockNeedle));
+                return true;
+            }
+
+            if (EnemyMgr.Instance.AIInfo != null && MathTools.SquareDistance(AI.Location, EnemyMgr.Instance.AILocation) <= 1600)
+            {
+                if (LandingPointCreator.Set.Count > 0)
+                    LandingPointCreator.Set[0].CreateLP();
+                if (Killer.Set.Count < 3)//先多修3个以组成防御战线)
+                {
+                    Build(typeof(Killer));
+                    return true;
+                }
+                if (Bomber.Set.Count < 6)
+                {
+                    Build(typeof(Bomber));
+                    return true;
+                }
+                if (Team.Bots.Count <= 39)
+                {
+                    Build(typeof(Killer));
+                    return true;
+                }
+            }
+            else
+            {
+                if (Bomber.Set.Count < 3)
+                {
+                    Build(typeof(Bomber));
+                    return true;
+                }
+                if (MyBots.Instance.IsNeedPioneer())
+                {
+                    Build(typeof(Pioneer));
+                    return true;
+                }
+                if (MyBots.Instance.IsNeedScouter() && m_nScouterBuildCntr < 2)
+                {
+                    m_nScouterBuildCntr++;
+                    Build(typeof(Scouter));
+                    return true;
+                }
+                if (MyBots.Instance.IsNeedWorker())
+                {
+                    Build(typeof(Worker));
+                    return true;
+                }
+                if (MyBots.Instance.IsNeedHardWorker())
+                {
+                    Build(typeof(HardWorker));
+                    return true;
+                }
+                if (MyBots.Instance.IsNeedKiller())
+                {
+                    Build(typeof(Killer));
+                    return true;
+                }
+                if (MyBots.Instance.IsNeedAIProtector())
+                {
+                    Build(typeof(AIProtector));
+                    return true;
+                }
+            }                        
+            return false;
+        }
+
+        public override void DoAction()
+        {
+            AIACTION_MEET_ENEMY action = GetAction();
+            if (action == AIACTION_MEET_ENEMY.ESCAPE)
+            {
+                MiniBroadTree.BroadTreePointInfo bpi;
+                Point[] path = SafePoint.GetSafePath(AI.Location, 8, out bpi);
+                if (GetBeatStrong(bpi, path) >= AI.Constitution + AI.Shield)//不能承受,不能再跑
+                {
+                    AI.StopMoving();
+                    ErgentBuildTask();
+                }
+                else
+                {
+                    Team.AIState = new AIEscapeState(Team, path);
+                }             
+                return;
+            }
+            else if (action == AIACTION_MEET_ENEMY.STOP)
+            {
+                AI.StopMoving();
+                ErgentBuildTask();
+                return;
+            }
+            else//没有威胁的情况
+            {
+                if (NormalBuildTask())
+                    return;
+
+                Team.AIState = new AIMovingState(Team);
+            }
+        }
+    }
+
+    //逃跑状态
+    public class AIEscapeState : AIStateMachine
+    {
+        public AIEscapeState(Team team,Point ptSafe)
+            : base(team)
+        {
+            AI.StopMoving();
+            AI.MoveTo(AStarPathFinder.Instance.GetPathPoint(AI.Location, ptSafe));
+        }
+        public AIEscapeState(Team team, Point[] path)
+            : base(team)
+        {
+            AI.StopMoving();
+            AI.MoveTo(path);
+        }
+        public override void DoAction()
+        {
+            AIACTION_MEET_ENEMY action = GetAction();
+            if (action == AIACTION_MEET_ENEMY.ESCAPE)
+            {
+                MiniBroadTree.BroadTreePointInfo bpi;
+                Point[] path = SafePoint.GetSafePath(AI.Location, 8, out bpi);
+                if (GetBeatStrong(bpi, path) >= AI.Constitution + AI.Shield)//不能承受,不能再跑
+                {
+                    Team.AIState = new AIStopAtOtherState(Team);
+                }
+                else
+                {
+                    AI.StopMoving();
+                    AI.MoveTo(path);   
+                }             
+                return;
+            }
+            else if (action == AIACTION_MEET_ENEMY.STOP)
+            {
+                Team.AIState = new AIStopAtOtherState(Team);
+                return;
+            }
+            else//没有威胁的情况
+            {
+                Team.AIState = new AIMovingState(Team);
+            }
+        }
+    }
+    //停止在其它地方的状态
+    public class AIStopAtOtherState : AIStateMachine
+    {
+        public AIStopAtOtherState(Team team)
+            : base(team)
+        {
+            AI.StopMoving();
+            if (MapAdapter.Instance.HosimiDicationary.ContainsKey(AI.Location))//避免出现死循环
+            {
+                AI.Build(typeof(StockNeedle));
+            }
+            else
+            {
+                AI.Build(typeof(ProtectNeedle));
+            }            
+        }
+
+        //在同一种状态下的建造总数有限,防止制造-死亡-制造的怪圈,因为该状态下LPCreator和Scouter有可能会从出生点向基地靠近,从而给对手攻击的机会
+        int m_nScouterBuildCntr = 0;
+        public bool NormalBuildTask()//正常情况下的建造顺序
+        {
+            if (!ProtectNeedle.Set.ContainsKey(AI.Location))
+            {
+                AI.Build(typeof(ProtectNeedle));
+                return true;
+            }
+            if (Bomber.Set.Count < 3 && Team.IsInThreat)//只有在遇到对手的攻击单位时才建造
+            {
+                Build(typeof(Bomber));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedPioneer())
+            {
+                Build(typeof(Pioneer));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedScouter() && m_nScouterBuildCntr < 2)
+            {
+                m_nScouterBuildCntr++;
+                Build(typeof(Scouter));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedWorker())
+            {
+                Build(typeof(Worker));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedHardWorker())
+            {
+                Build(typeof(HardWorker));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedKiller())
+            {
+                Build(typeof(Killer));
+                return true;
+            }
+            if (MyBots.Instance.IsNeedAIProtector())
+            {
+                Build(typeof(AIProtector));
+                return true;
+            }
+            return false;
+        }
+        public bool ErgentBuildTask()
+        {
+            if (!ProtectNeedle.Set.ContainsKey(AI.Location))
+            {
+                AI.Build(typeof(ProtectNeedle));
+                return true;
+            }
+            if (Killer.Set.Count < 3)//
+            {
+                Build(typeof(Killer));
+                return true;
+            }
+            if (Bomber.Set.Count < 6)
+            {
+                Build(typeof(Bomber));
+                return true;
+            }
+            if (Team.Bots.Count <= 39)
+            {
+                Build(typeof(Killer));
+                return true;
+            }
+            return false;
+        }
+        void BuildBots()
+        {
+            //遇到对方AI时的建造方法
+            if (EnemyMgr.Instance.AIInfo != null && MathTools.SquareDistance(AI.Location, EnemyMgr.Instance.AILocation) <= 1600)
+            {
+                ErgentBuildTask();
+            }
+            else//没有遇到对方AI的建造方法
+            {
+                NormalBuildTask();
+            }            
+        }
+
+        public override void DoAction()
+        {
+            //遇到对方基地时,要打开LPCreator
+            if (EnemyMgr.Instance.AIInfo != null &&
+                MathTools.SquareDistance(AI.Location, EnemyMgr.Instance.AILocation) <= 900 &&
+                LandingPointCreator.Set.Count>0)
+            {
+                LandingPointCreator.Set[0].CreateLP();
+            }
+
+            AIACTION_MEET_ENEMY action = GetAction();
+            if (action == AIACTION_MEET_ENEMY.ESCAPE)
+            {
+                MiniBroadTree.BroadTreePointInfo bpi;
+                Point[] path = SafePoint.GetSafePath(AI.Location, 8, out bpi);
+                if (GetBeatStrong(bpi, path) >= AI.Constitution + AI.Shield)//不能承受,不能再跑
+                {
+                    BuildBots();
+                }
+                else
+                {
+                    Team.AIState = new AIEscapeState(Team, path);
+                }              
+                return;
+            }
+            else if (action == AIACTION_MEET_ENEMY.STOP)
+            {
+                BuildBots();
+                return;
+            }
+            else//没有威胁的情况
+            {
+                Team.AIState = new AIMovingState(Team);
+            }            
+        }
+    }
+}

AttackStrategy.cs

+using System;
+using System.Collections.Generic;
+using System.Text;
+using PH.Common;
+using System.Drawing;
+using System.Collections;
+using PH.Map;
+using PH.Mission;
+
+namespace SuperStar
+{
+    /***********************************************
+     * Collector相关的攻击策略
+     * *********************************************/
+    public class CollectorAttackStrategy : BotContainer, IStrategy
+    {        
+        //加入一随机因子,让其攻击敌人时,有一些会选择较近的攻击机
+        int m_nAttackDelta = 0;
+
+        public Collector Collector
+        {
+            get { return (Collector)m_InnerBot; }
+        }
+        public CollectorAttackStrategy(Collector bot,int nAttackDelta)
+            : base(bot, "Collector Attacker")
+        {
+            m_nAttackDelta = nAttackDelta;
+        }
+        protected bool AttackEnemy()
+        {
+            bool bRet = false;
+            Hashtable hashTemp = new Hashtable();//用来判断是否已经处理过这个位置
+
+            int nSquareShortDD = (DefenseDistance) * (DefenseDistance);
+            //int nSquareMidDD = (DefenseDistance + 4) * (DefenseDistance + 4);
+            int nSquareLongDD = (DefenseDistance + 3+m_nAttackDelta) * (DefenseDistance + 3+m_nAttackDelta);//运动单位适当加长
+            
+            Point ptDefend = Point.Empty;
+
+            #region 先检查对手AI是否在攻击范围之内
+            BotInfo bot = EnemyMgr.Instance.AIInfo;
+            if (bot != null)
+            {
+                hashTemp.Add(bot.Location, null);//第一个处理,始终添加
+                int d = MathTools.SquareDistance(bot.Location, Location);
+                if (bot.State == BotState.Moving)
+                {
+                    if (d <= nSquareLongDD)
+                    {
+                        if (GetSafeDefendPoint(bot, 5, out ptDefend))
+                        {
+                            Collector.StopMoving();
+                            Collector.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                            return true;
+                        }
+                        else//不能直接返回,由后面的检查来确定
+                        {
+                            Collector.StopMoving();
+                            bRet = true;
+                        }
+                    }
+                }
+                else
+                {
+                    if (d <= nSquareShortDD)
+                    {
+                        if (GetSafeDefendPoint(bot, 3, out ptDefend))
+                        {
+                            Collector.StopMoving();
+                            Collector.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                            return true;
+                        }
+                        else//不能直接返回,由后面的检查来确定
+                        {
+                            Collector.StopMoving();
+                            bRet = true;
+                        }
+                    }
+                }
+            }
+            #endregion
+            #region 检查对手的攻击单位
+            //实在没有什么可攻击的时候,就攻击安全区内的单位
+            Vector<BotInfo> vecSafeBots = new Vector<BotInfo>();
+
+            Vector<BotInfo> bots = EnemyMgr.Instance.AttackBots;
+            for (int i = 0; i < bots.Count; i++)
+            {
+                if (!hashTemp.Contains(bots[i].Location))
+                    hashTemp.Add(bots[i].Location, null);//用来判断是否已经处理过这个位置
+
+                int d = MathTools.SquareDistance(Location, bots[i].Location);
+                if (bots[i].BotType == BotType.Needle)//对不能移动的单位
+                {
+                    if (d <= nSquareShortDD)
+                    {
+                        //添加到安全点中
+                        if (bots[i].Shield <= 0 && EnemyMgr.Instance.IsInSafeArea(bots[i].Location))
+                        {
+                            vecSafeBots.Add(bots[i]);
+                        }
+                        else if (GetSafeDefendPoint(bots[i], 3, out ptDefend))
+                        {
+                            Collector.StopMoving();
+                            Collector.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                            return true;
+                        }
+                    }
+                }
+                else//对可移动单位
+                {
+                    if (bots[i].State != BotState.WaitingOrders)
+                    {
+                        if (d <= nSquareLongDD)
+                        {
+                            if (EnemyMgr.Instance.IsInSafeArea(bots[i].Location))
+                            {
+                                vecSafeBots.Add(bots[i]);
+                            }
+                            else if (GetSafeDefendPoint(bots[i], 3 + m_nAttackDelta, out ptDefend))
+                            {
+                                Collector.StopMoving();
+                                Collector.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                                return true;
+                            }
+                            else//不能直接返回,由后面的检查来确定
+                            {
+                                Collector.StopMoving();
+                                bRet = true;
+                            }
+                        }
+                    }
+                    else
+                    {
+                        if (d <= nSquareShortDD)
+                        {
+                            if (EnemyMgr.Instance.IsInSafeArea(bots[i].Location))
+                            {
+                                vecSafeBots.Add(bots[i]);
+                            }
+                            else if (GetSafeDefendPoint(bots[i], 3, out ptDefend))
+                            {
+                                Collector.StopMoving();
+                                Collector.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                                return true;
+                            }
+                            else//不能直接返回,由后面的检查来确定
+                            {
+                                Collector.StopMoving();
+                                bRet = true;
+                            }
+                        }
+                    }
+                }
+            }
+            #endregion
+            #region 检查对手的非攻击单位
+            bots = EnemyMgr.Instance.NotAttackBots;
+            for (int i = 0; i < bots.Count; i++)
+            {
+                if (!hashTemp.ContainsKey(bots[i].Location))
+                {
+                    hashTemp.Add(bots[i].Location, null);
+                    int d = MathTools.SquareDistance(Location, bots[i].Location);
+                    if (d < nSquareShortDD)
+                    {
+                        if (!EnemyMgr.Instance.IsInSafeArea(bots[i].Location) && GetSafeDefendPoint(bots[i], 3, out ptDefend))
+                        {
+                            Collector.StopMoving();
+                            Collector.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                            return true;
+                        }
+                    }
+                }
+            }
+            #endregion
+            #region 检查电脑方的工厂
+            bots = EnemyMgr.Instance.Factories;
+            for (int i = 0; i < bots.Count; i++)
+            {
+                int d = MathTools.SquareDistance(Location, bots[i].Location);
+                if (d < nSquareShortDD)
+                {
+                    if (GetSafeDefendPoint(bots[i], 3, out ptDefend))
+                    {
+                        Collector.StopMoving();
+                        Collector.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                        return true;
+                    }
+                }
+            }
+            #endregion
+
+            //查看是否有安全区内的可攻击单位
+            if (vecSafeBots.Count > 0)
+            {
+                if (GetSafeDefendPoint(vecSafeBots[0], 3, out ptDefend))
+                {
+                    Collector.StopMoving();
+                    Collector.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                    return true;
+                }
+            }
+            return bRet;
+        }
+        public bool DoAction()
+        {
+            return AttackEnemy();
+        }
+        public bool ForceAutoDestruction()
+        {
+            throw new Exception("not required method");
+        }
+    }
+
+    /***********************************************
+     * Collector相关的常规策略
+     * *********************************************/
+    public class AIProtectorStrategy : BotContainer, IStrategy
+    {
+        public AIProtectorStrategy(Collector collector)
+            : base(collector, "AIProtector")
+        {
+        }
+        Collector Collector
+        {
+            get { return (Collector)m_InnerBot; }
+        }
+        public bool DoAction()
+        {
+            if (Team.IsInThreat)
+            {
+                Collector.StopMoving();
+                Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, Team.ThreatPoint));
+                return true;
+            }
+            //向基地靠拢
+            Collector.StopMoving();
+            Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, Team.AI.Location));
+            return true;
+        }
+        public bool ForceAutoDestruction()
+        {
+            bool bKilled = true;
+            //检查周围有没有可杀的敌人,没有即可杀
+            foreach (BotInfo bot in Team.OtherBotsInfo)
+            {
+                int d = MathTools.SquareDistance(bot.Location, Location);
+                if (bot.BotType == BotType.Factory)//静止单位
+                {
+                    if (d < 169)
+                    {
+                        bKilled = false;
+                        break;
+                    }
+                }
+                else
+                {
+                    if (d <= 400)
+                    {
+                        bKilled = false;
+                        break;
+                    }
+                }
+            }
+            if (bKilled)
+            {
+                m_InnerBot.ForceAutoDestruction();
+                return true;
+            }
+            return false;
+        }
+    }
+    public class PioneerStrategy : BotContainer, IStrategy
+    {
+        Point m_ptDestHosimi = Point.Empty;
+        Hashtable m_hshHistory = new Hashtable();
+        public PioneerStrategy(Collector collector)
+            : base(collector, "pioneer")
+        {
+        }
+        Collector Collector
+        {
+            get { return (Collector)m_InnerBot; }
+        }
+        void ChangeDestionation()
+        {
+            if (Location == Team.LandingPoint)//在出生点
+            {
+                m_ptDestHosimi = StrategyCenter.Instance.GetNextHosimiPoint(Location, Location);
+            }
+            else
+            {
+                m_ptDestHosimi = StrategyCenter.Instance.GetNextHosimiPoint(Location, m_hshHistory);
+            }
+            if (!m_hshHistory.ContainsKey(m_ptDestHosimi))
+                m_hshHistory.Add(m_ptDestHosimi, m_ptDestHosimi);
+            Collector.StopMoving();
+            Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, m_ptDestHosimi));
+        }
+        
+        void CheckHistoryPoint()
+        {
+            Dictionary<Point, BotInfo>.Enumerator it = EnemyMgr.Instance.AllNeedles.GetEnumerator();
+            while (it.MoveNext())
+            {
+                if (m_hshHistory.ContainsKey(it.Current.Key))
+                    m_hshHistory.Remove(it.Current.Key);
+            }
+        }
+        public bool DoAction()
+        {
+            //去掉历史路径中对手有Needle的点
+            CheckHistoryPoint();
+            /////////////////////
+            if (m_ptDestHosimi == Point.Empty)//在出生点
+            {
+                ChangeDestionation();
+                return true;
+            }
+            //重换点运动
+            if (StockNeedle.Set.ContainsKey(m_ptDestHosimi) || EnemyMgr.Instance.SafeNeedles.ContainsKey(m_ptDestHosimi))
+            {
+                ChangeDestionation();
+                return true;
+            }
+            //到达目标点
+            if (Location == m_ptDestHosimi)
+            {
+                ChangeDestionation();
+                return true;
+            }
+
+            //
+            if (State == BotState.WaitingOrders)
+            {
+                Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, m_ptDestHosimi));
+            }
+            return true;
+        }
+
+        public bool ForceAutoDestruction()
+        {
+            bool bKilled = true;
+            //检查周围有没有可杀的敌人,没有即可杀
+            foreach (BotInfo bot in Team.OtherBotsInfo)
+            {
+                int d = MathTools.SquareDistance(bot.Location, Location);
+                if (bot.BotType == BotType.Factory)//静止单位
+                {
+                    if (d < 169)
+                    {
+                        bKilled = false;
+                        break;
+                    }
+                }
+                else
+                {
+                    if (d <= 400)
+                    {
+                        bKilled = false;
+                        break;
+                    }
+                }
+            }
+            if (bKilled)
+            {
+                m_InnerBot.ForceAutoDestruction();
+                return true;
+            }
+            return false;
+        }
+    }
+    public class KillerStrategy : BotContainer, IStrategy
+    {
+        public KillerStrategy(Collector collector)
+            : base(collector, "killer")
+        {
+        }
+        Collector Collector
+        {
+            get { return (Collector)m_InnerBot; }
+        }
+        static int[] ms_QuadsX = new int[] { 0, 1, 1, 0 };
+        static int[] ms_QuadsY = new int[] { 0, 0, 1, 1 };
+
+        Point m_ptDestination = Point.Empty;
+         /*******************************************************
+         * new version
+         * ****************************************************/
+        BotType m_DestBotType = BotType.Unknown;
+
+        Vector<BotInfo> GetOtherAIAndNeedleInfo()
+        {
+            Vector<BotInfo> vecOtherBots = new Vector<BotInfo>();
+            if (EnemyMgr.Instance.AIInfo != null)
+                vecOtherBots.Add(EnemyMgr.Instance.AIInfo);
+            foreach (BotInfo bot in EnemyMgr.Instance.AllNeedles.Values)
+                vecOtherBots.Add(bot);
+            return vecOtherBots;
+        }
+        void SelectDestionation(Vector<BotInfo> vecOtherBots)
+        {
+            if (vecOtherBots.Count == 1)
+            {
+                m_ptDestination = vecOtherBots[0].Location;
+                m_DestBotType = vecOtherBots[0].BotType;
+            }
+            else
+            {
+                BroadTree tree = BroadTree.MakeBroadTree(Location);
+                int dist = tree.GetWeight(vecOtherBots[0].Location);
+                int min = 0;
+
+                for (int i = 1; i < vecOtherBots.Count; i++)
+                {
+                    int d = tree.GetWeight(vecOtherBots[i].Location);
+                    if (d < dist)
+                    {
+                        dist = d;
+                        min = i;
+                    }
+                }
+                m_ptDestination = vecOtherBots[min].Location;
+                m_DestBotType = vecOtherBots[min].BotType;
+            }
+
+            Collector.StopMoving();
+            Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, m_ptDestination));
+        }
+        void SelectRandomDestionation()//顺时针选择
+        {
+            m_DestBotType = BotType.Unknown;
+
+            //寻找当前象限位置
+            int pos = 0;
+            int sx = Location.X / 100;
+            int sy = Location.Y / 100;
+            for (int i = 0; i < 4; i++)
+            {
+                if (ms_QuadsX[i] == sx && ms_QuadsY[i] == sy)
+                {
+                    pos = i;
+                    break;
+                }
+            }
+
+            //基地所在的象限
+            int ax = Team.AI.Location.X / 100;
+            int ay = Team.AI.Location.Y / 100;
+
+
+            for (int i = 0; i < 4; i++)
+            {
+                pos = (pos + 1) % 4;
+                int x = ms_QuadsX[pos];
+                int y = ms_QuadsY[pos];
+
+                if ((x != ax || y != ay) && MapAdapter.Instance.QudrantInfo[x, y].Count > 0)
+                {
+                    Random r = new Random();
+                    int index = r.Next(MapAdapter.Instance.QudrantInfo[x, y].Count);//随机选择一个位置
+                    for (int j = 0; j < MapAdapter.Instance.QudrantInfo[x, y].Count; j++)
+                    {
+                        Point pt = MapAdapter.Instance.QudrantInfo[x, y][index];
+                        if (StockNeedle.Set.ContainsKey(pt) || EnemyMgr.Instance.IsInSafeAttackRange(pt))
+                        {
+                            index = (index + 1) % MapAdapter.Instance.QudrantInfo[x, y].Count;
+                        }
+                        else
+                        {
+                            m_ptDestination = pt;
+                            Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, m_ptDestination));
+                            return;
+                        }
+                    }
+                }
+
+            }
+        }
+
+        public bool DoAction()
+        {
+            if (m_ptDestination == Point.Empty)//在出生点
+            {
+                Vector<BotInfo> vecOtherBots = GetOtherAIAndNeedleInfo();
+                if (vecOtherBots.Count > 0)
+                    SelectDestionation(vecOtherBots);
+                else
+                    SelectRandomDestionation();
+                return true;
+            }
+            if (Location == m_ptDestination)
+            {
+                Collector.StopMoving();
+                Vector<BotInfo> vecOtherBots = GetOtherAIAndNeedleInfo();
+                if (vecOtherBots.Count > 0)
+                    SelectDestionation(vecOtherBots);
+                else
+                    SelectRandomDestionation();
+                return true;
+            }
+            //如果是对方AI
+            if (m_DestBotType == BotType.AI)
+            {
+                if (EnemyMgr.Instance.AIInfo != null)
+                {
+                    m_ptDestination = EnemyMgr.Instance.AILocation;
+                    Collector.StopMoving();
+                    Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, m_ptDestination));
+                    return true;
+                }
+            }
+
+            if (StockNeedle.Set.ContainsKey(m_ptDestination) || EnemyMgr.Instance.IsInSafeArea(m_ptDestination))
+            {
+                Collector.StopMoving();
+                Vector<BotInfo> vecOtherBots = GetOtherAIAndNeedleInfo();
+                if (vecOtherBots.Count > 0)
+                    SelectDestionation(vecOtherBots);
+                else
+                    SelectRandomDestionation();
+                return true;
+            }
+            //if (EnemyMgr.Instance.IsInSafeAttackRange(m_ptDestination) && !EnemyMgr.Instance.AllNeedles.ContainsKey(m_ptDestination))
+            if(m_DestBotType == BotType.Needle && !EnemyMgr.Instance.AllNeedles.ContainsKey(m_ptDestination))
+            {
+                Collector.StopMoving();
+                Vector<BotInfo> vecOtherBots = GetOtherAIAndNeedleInfo();
+                if (vecOtherBots.Count > 0)
+                    SelectDestionation(vecOtherBots);
+                else
+                    SelectRandomDestionation();
+                return true;
+            }
+
+            //没有目标时,随时寻找并更换目标
+            if (m_DestBotType == BotType.Unknown)
+            {
+                Vector<BotInfo> vecOtherBots = GetOtherAIAndNeedleInfo();
+                if (vecOtherBots.Count > 0)
+                {
+                    Collector.StopMoving();
+                    SelectDestionation(vecOtherBots);
+                    return true;
+                }
+            }
+
+            if (State == BotState.WaitingOrders)
+            {
+                Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, m_ptDestination));
+            }
+            return true;
+        }
+        public bool ForceAutoDestruction()
+        {
+            if (m_DestBotType == BotType.Unknown)
+            {
+                m_InnerBot.ForceAutoDestruction();
+                return true;
+            }
+            return false;
+        }
+    }
+    public class BombererStrategy : BotContainer, IStrategy
+    {
+        enum BOMBER_STEP
+        {
+            ROUND,//绕过中心点
+            TOTARGET,
+            NULL
+        }
+
+        BOMBER_STEP m_curStep = BOMBER_STEP.NULL;
+        Point m_ptDest = Point.Empty;
+        bool m_bTargetIsOtherAI = false;
+
+        Collector Collector
+        {
+            get { return (Collector)m_InnerBot; }
+        }
+        public BombererStrategy(Collector collector)
+            : base(collector, "bomber")
+        {
+            
+        }
+
+        protected bool AttackEnemy()
+        {
+            Hashtable hashTemp = new Hashtable();//用来判断是否已经处理过这个位置
+
+            int nSquareShortDD = (DefenseDistance + 3) * (DefenseDistance + 3);
+            Point ptDefend = Point.Empty;
+
+            #region 先检查对手AI是否在攻击范围之内
+            BotInfo bot = EnemyMgr.Instance.AIInfo;
+            if (bot != null)
+            {
+                hashTemp.Add(bot.Location, null);//第一个处理,始终添加
+                int d = MathTools.SquareDistance(bot.Location, Location);
+                if (d <= nSquareShortDD)
+                {
+                    GetSafeDefendPoint(bot, 3, out ptDefend);
+                    Collector.StopMoving();
+                    Collector.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                    return true;
+                }
+            }
+            #endregion
+            #region 检查对手的攻击单位
+            Vector<BotInfo> bots = EnemyMgr.Instance.AttackBots;
+            for (int i = 0; i < bots.Count; i++)
+            {
+                if (!hashTemp.ContainsKey(bots[i].Location))
+                {
+                    hashTemp.Add(bots[i].Location, null);//用来判断是否已经处理过这个位置
+                    int d = MathTools.SquareDistance(Location, bots[i].Location);
+                    if (d <= nSquareShortDD)
+                    {
+                        if (GetSafeDefendPoint(bots[i], 3, out ptDefend))
+                        {
+                            Collector.StopMoving();
+                            Collector.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                            return true;
+                        }
+                    }
+                }                    
+            }
+            #endregion 
+            #region 检查电脑的工厂
+            bots = EnemyMgr.Instance.Factories;
+            for (int i = 0; i < bots.Count; i++)
+            {
+                int d = MathTools.SquareDistance(Location, bots[i].Location);
+                if (d < nSquareShortDD)
+                {
+                    if (GetSafeDefendPoint(bots[i], 3, out ptDefend))
+                    {
+                        Collector.StopMoving();
+                        Collector.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                        return true;
+                    }
+                }
+            }
+            #endregion
+            return false;
+        }
+
+        void DoAtNullStep()
+        {
+            if (EnemyMgr.Instance.AIInfo != null)
+            {
+                Vector<CSize> vecEdge = CircleAreaMgr.GetCircleOutEdge(18);
+                Vector<Point> vecValid = new Vector<Point>();
+
+                for (int i = 0; i < vecEdge.Count; i++)
+                {
+                    Point pt = EnemyMgr.Instance.AILocation;
+                    pt.X += vecEdge[i]._cx;
+                    pt.Y += vecEdge[i]._cy;
+                    if (MapAdapter.Instance.IsMoveable(pt.X, pt.Y))
+                        vecValid.Add(pt);
+                }
+                if (vecValid.Count <= 0)//没有有效目标
+                {
+                    m_ptDest = EnemyMgr.Instance.AILocation;
+                    m_curStep = BOMBER_STEP.TOTARGET;
+                }
+                else
+                {
+                    m_ptDest = vecValid[new Random().Next(vecValid.Count)];
+                    m_curStep = BOMBER_STEP.ROUND;
+                }
+                m_bTargetIsOtherAI = true;
+
+                Collector.MoveTo(AStarPathFinder.Instance.GetPathPointB(Location, m_ptDest, EnemyMgr.Instance.AILocation));
+            }
+            else if (Team.IsInThreat)
+            {
+                Vector<CSize> vecEdge = CircleAreaMgr.GetCircleOutEdge(18);
+                Vector<Point> vecValid = new Vector<Point>();
+
+                for (int i = 0; i < vecEdge.Count; i++)
+                {
+                    Point pt = Team.ThreatPoint;
+                    pt.X += vecEdge[i]._cx;
+                    pt.Y += vecEdge[i]._cy;
+                    if (MapAdapter.Instance.IsMoveable(pt.X, pt.Y))
+                        vecValid.Add(pt);
+                }
+                if (vecValid.Count <= 0)//没有有效目标
+                {
+                    m_ptDest = Team.ThreatPoint;
+                    m_curStep = BOMBER_STEP.TOTARGET;
+                }
+                else
+                {
+                    m_ptDest = vecValid[new Random().Next(vecValid.Count)];
+                    m_curStep = BOMBER_STEP.ROUND;
+                }
+                m_bTargetIsOtherAI = false;
+                Collector.MoveTo(AStarPathFinder.Instance.GetPathPointB(Location, m_ptDest, Team.ThreatPoint));
+            }
+            else
+            {
+                m_InnerBot.ForceAutoDestruction();
+                return;
+            }
+        }
+        void DoAtRoundStep()
+        {
+            if (m_bTargetIsOtherAI)
+            {
+                if (EnemyMgr.Instance.AIInfo == null)
+                {
+                    m_InnerBot.ForceAutoDestruction();
+                    return;
+                }
+                if (m_ptDest == Location)
+                {
+                    m_curStep = BOMBER_STEP.TOTARGET;
+                    Collector.StopMoving();
+                    Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, EnemyMgr.Instance.AILocation));
+                    return;
+                }
+                if (State == BotState.WaitingOrders)
+                {
+                    Collector.MoveTo(AStarPathFinder.Instance.GetPathPointB(Location, m_ptDest, EnemyMgr.Instance.AILocation));
+                    return;
+                }
+            }
+            else
+            {
+                if (!Team.IsInThreat)
+                {
+                    m_InnerBot.ForceAutoDestruction();
+                    return;
+                }
+                if (m_ptDest == Location)
+                {
+                    m_curStep = BOMBER_STEP.TOTARGET;
+                    Collector.StopMoving();
+                    Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, Team.ThreatPoint));
+                    return;
+                }
+                if (State == BotState.WaitingOrders)
+                {
+                    Collector.MoveTo(AStarPathFinder.Instance.GetPathPointB(Location, m_ptDest, Team.ThreatPoint));
+                    return;
+                }
+            }
+        }
+        void DoAtTargetStep()
+        {
+            if (m_bTargetIsOtherAI)
+            {
+                if (EnemyMgr.Instance.AIInfo == null)
+                {
+                    m_InnerBot.ForceAutoDestruction();
+                    return;
+                }
+                if (State == BotState.WaitingOrders)
+                {
+                    Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, EnemyMgr.Instance.AILocation));
+                    return;
+                }
+            }
+            else
+            {
+                if (!Team.IsInThreat)
+                {
+                    m_InnerBot.ForceAutoDestruction();
+                    return;
+                }
+                if (State == BotState.WaitingOrders)
+                {
+                    Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, Team.ThreatPoint));
+                    return;
+                }
+            }
+        }
+        public bool DoAction()
+        {
+            if (AttackEnemy())//能攻击到敌人,直接攻击
+                return true;
+            //
+            if (m_curStep == BOMBER_STEP.NULL)//初始情况
+            {
+                DoAtNullStep();
+            }
+            else if (m_curStep == BOMBER_STEP.ROUND)
+            {
+                DoAtRoundStep();
+            }
+            else
+            {
+                DoAtTargetStep();
+            }
+
+            //if (EnemyMgr.Instance.AIInfo == null)
+            //{
+            //    m_InnerBot.ForceAutoDestruction();
+            //    return true;
+            //}
+
+            //if (m_curAction == BOMBER_STEP.ROUND)
+            //{
+            //    if (Location == m_ptDest)
+            //    {
+            //        m_curAction = BOMBER_STEP.TOTARGET;
+            //        Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, EnemyMgr.Instance.AILocation));
+            //        return true;
+            //    }
+            //    else if (State == BotState.WaitingOrders)
+            //    {
+            //        Collector.MoveTo(AStarPathFinder.Instance.GetPathPointB(Location, m_ptDest, EnemyMgr.Instance.AILocation));
+            //        return true;
+            //    }
+            //}
+            //else if (m_curAction == BOMBER_STEP.TOTARGET)
+            //{
+            //    Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, EnemyMgr.Instance.AILocation));
+            //    return true;
+            //}
+
+            return false;
+        }
+
+        public bool ForceAutoDestruction()
+        {
+            throw new Exception("not required method");
+        }
+    }
+
+    /***********************************************
+     * Needle的攻击策略和常规策略
+     **********************************************/
+    public class NeedleAttackStrategy : BotContainer, IStrategy
+    {
+        Needle Needle
+        {
+            get { return (Needle)m_InnerBot; }
+        }
+        public NeedleAttackStrategy(Needle needle)
+            : base(needle, "Needle Attacker")
+        {
+        }
+        protected bool AttackEnemy()
+        {
+            bool bRet = false;
+            Hashtable hashTemp = new Hashtable();//用来判断是否已经处理过这个位置
+
+            int nSquareShortDD = (DefenseDistance + 3) * (DefenseDistance + 3);
+            int nSquareMidDD = (DefenseDistance + 4) * (DefenseDistance + 4);
+            int nSquareLongDD = (DefenseDistance + 5) * (DefenseDistance + 5);//运动单位适当加长
+            Point ptDefend = Point.Empty;
+
+            #region 先检查对手AI是否在攻击范围之内
+            BotInfo bot = EnemyMgr.Instance.AIInfo;
+            if (bot != null)
+            {
+                hashTemp.Add(bot.Location, null);//第一个处理,始终添加
+                int d = MathTools.SquareDistance(bot.Location, Location);
+                if (bot.State == BotState.Moving)
+                {
+                    if (d <= nSquareLongDD)
+                    {
+                        if (GetSafeDefendPoint(bot, 5, out ptDefend))
+                        {
+                            Needle.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                            return true;
+                        }
+                    }
+                }
+                else
+                {
+                    if (d <= nSquareShortDD)
+                    {
+                        if (GetSafeDefendPoint(bot, 3, out ptDefend))
+                        {
+                            Needle.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                            return true;
+                        }
+                    }
+                }
+            }
+            #endregion
+            #region 检查对手的攻击单位
+            //实在没有什么可攻击的时候,就攻击安全区内的单位
+            Vector<BotInfo> vecSafeBots = new Vector<BotInfo>();
+            Vector<BotInfo> bots = EnemyMgr.Instance.AttackBots;
+            for (int i = 0; i < bots.Count; i++)
+            {
+                if (!hashTemp.Contains(bots[i].Location))
+                    hashTemp.Add(bots[i].Location, null);//用来判断是否已经处理过这个位置
+
+                int d = MathTools.SquareDistance(Location, bots[i].Location);
+                if (bots[i].BotType == BotType.Needle)//对不能移动的单位
+                {
+                    if (d <= nSquareShortDD)
+                    {
+                        if (bots[i].Shield <= 0 && EnemyMgr.Instance.IsInSafeArea(bots[i].Location))
+                        {
+                            vecSafeBots.Add(bots[i]);
+                        }
+                        else if (GetSafeDefendPoint(bots[i], 3, out ptDefend))
+                        {
+                            Needle.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                            return true;
+                        }
+                    }
+                }
+                else//对可移动单位
+                {
+                    if (bots[i].State != BotState.WaitingOrders)
+                    {
+                        if (d <= nSquareLongDD)
+                        {
+                            if (EnemyMgr.Instance.IsInSafeArea(bots[i].Location))
+                            {
+                                vecSafeBots.Add(bots[i]);
+                            }
+                            else if (GetSafeDefendPoint(bots[i], 5, out ptDefend))
+                            {
+                                Needle.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                                return true;
+                            }
+                        }
+                    }
+                    else
+                    {
+                        if (d <= nSquareMidDD)
+                        {
+                            if (EnemyMgr.Instance.IsInSafeArea(bots[i].Location))
+                            {
+                                vecSafeBots.Add(bots[i]);
+                            }
+                            else if (GetSafeDefendPoint(bots[i], 4, out ptDefend))
+                            {
+                                Needle.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                                return true;
+                            }
+                        }
+                    }
+                }
+            }
+            #endregion
+            #region 检查对手的非攻击单位
+            bots = EnemyMgr.Instance.NotAttackBots;
+            for (int i = 0; i < bots.Count; i++)
+            {
+                if (!hashTemp.ContainsKey(bots[i].Location))
+                {
+                    hashTemp.Add(bots[i].Location, null);
+                    int d = MathTools.SquareDistance(Location, bots[i].Location);
+                    if (d < nSquareShortDD)
+                    {
+                        if (!EnemyMgr.Instance.IsInSafeArea(bots[i].Location) && GetSafeDefendPoint(bots[i], 3, out ptDefend))
+                        {
+                            Needle.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                            return true;
+                        }
+                    }
+                }
+            }
+            #endregion
+            #region 检查电脑方的工厂
+            bots = EnemyMgr.Instance.Factories;
+            for (int i = 0; i < bots.Count; i++)
+            {   
+                int d = MathTools.SquareDistance(Location, bots[i].Location);
+                if (d < nSquareShortDD)
+                {
+                    if (GetSafeDefendPoint(bots[i], 3, out ptDefend))
+                    {
+                        Needle.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                        return true;
+                    }
+                }
+            }
+            #endregion
+
+            //查看是否有安全区内的可攻击单位
+            if (vecSafeBots.Count > 0)
+            {
+                if (GetSafeDefendPoint(vecSafeBots[0], 3, out ptDefend))
+                {
+                    Needle.DefendTo(ptDefend, ATTACK_MIN_TURNS);
+                    return true;
+                }
+            }
+
+            return bRet;
+        }
+        public bool DoAction()
+        {
+            return AttackEnemy();
+        }
+        public bool ForceAutoDestruction()
+        {
+            throw new Exception("not required method");
+        }
+    }
+    public class NeedleTaskStrategy : BotContainer, IStrategy
+    {
+        Needle Needle
+        {
+            get { return (Needle)m_InnerBot; }
+        }
+        public NeedleTaskStrategy(Needle needle)
+            : base(needle, "Needle Task")
+        {
+        }
+        static CSize[] m_Dirs = new CSize[] { new CSize(0, 10), new CSize(7, 7), new CSize(10, 0), new CSize(-7, 7), new CSize(-10, 0), new CSize(-7, -7), new CSize(0, -10), new CSize(7, -7) };
+        int m_nCurrentDir = 0;
+
+        protected bool AttackFixedDir()
+        {
+            for (int i = 0; i < 8; i++)
+            {
+                m_nCurrentDir = (m_nCurrentDir + 1) % m_Dirs.Length;
+                Point pt = Location;
+                pt.X += m_Dirs[m_nCurrentDir]._cx;
+                pt.Y += m_Dirs[m_nCurrentDir]._cy;
+
+                if (pt.X > 0 && pt.X < Team.Terrain.Width && pt.Y > 0 && pt.Y < Team.Terrain.Height)
+                {
+                    bool bAttacked = true;
+                    foreach (Bot bot in Team.Bots)
+                    {
+                        if (bot.BotType == BotType.Needle || bot.BotType == BotType.Wall || bot.BotType == BotType.Blocker)
+                        {
+                            if (MathTools.SquareDistance(bot.Location, pt) <= 16)
+                            {
+                                bAttacked = false;
+                                break;
+                            }
+                        }
+                        else
+                        {
+                            if (MathTools.SquareDistance(bot.Location, pt) <= 81)
+                            {
+                                bAttacked = false;
+                                break;
+                            }
+                        }
+                    }
+                    if (bAttacked)
+                    {
+                        Needle.DefendTo(pt, ATTACK_MIN_TURNS);
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        public bool DoAction()
+        {
+            return AttackFixedDir();
+        }
+
+        public bool ForceAutoDestruction()
+        {
+            if (m_InnerBot.ContainerCapacity >= 100)//存矿Needle,不能自杀
+            {
+                throw new Exception("not required method");
+            }
+            bool bKilled = true;
+            //检查周围有没有可杀的敌人,没有即可杀
+            foreach (BotInfo bot in Team.OtherBotsInfo)
+            {
+                int d = MathTools.SquareDistance(bot.Location, Location);
+                if (bot.BotType == BotType.Factory || bot.BotType == BotType.Needle)//静止单位
+                {
+                    if (d <= 169)
+                    {
+                        bKilled = false;
+                        break;
+                    }
+                }
+                else
+                {
+                    if (d <= 400)
+                    {
+                        bKilled = false;
+                        break;
+                    }
+                }
+            }
+            if (bKilled)
+            {
+                m_InnerBot.ForceAutoDestruction();
+                return true;
+            }
+            return false;
+        }
+    }
+
+
+    /**************************************************
+     * 新增
+     *************************************************/
+    public class NavigateKillerStrategy : BotContainer, IStrategy
+    {
+        enum KILLER_ACTION
+        {
+            ATTACKNEEDLE,
+            ATTACKAI,
+            MISSION,
+            RANDOM,
+            NONE
+        }
+        Point m_ptDest = Point.Empty;
+        KILLER_ACTION m_curAction = KILLER_ACTION.NONE;
+        int m_nStartTurn = 0;
+        int m_nEndTurn = 0;
+
+        public NavigateKillerStrategy(Collector collector)
+            : base(collector, "nkiller")
+        {
+        }
+        void GetRandomDestionation(int sx,int sy)//顺时针选择
+        {
+            m_curAction = KILLER_ACTION.RANDOM;
+            //寻找当前象限位置
+            int pos = 0;
+            for (int i = 0; i < 4; i++)
+            {
+                if (ms_QuadsX[i] == sx && ms_QuadsY[i] == sy)
+                {
+                    pos = i;
+                    break;
+                }
+            }
+
+            for (int i = 0; i < 4; i++)
+            {
+                pos = (pos + 1) % 4;
+                int x = ms_QuadsX[pos];
+                int y = ms_QuadsY[pos];
+
+                if (MapAdapter.Instance.QudrantInfo[x, y].Count > 0)
+                {
+                    Random r = new Random();
+                    int index = r.Next(MapAdapter.Instance.QudrantInfo[x, y].Count);//随机选择一个位置
+                    for (int j = 0; j < MapAdapter.Instance.QudrantInfo[x, y].Count; j++)
+                    {
+                        Point pt = MapAdapter.Instance.QudrantInfo[x, y][index];
+                        if (StockNeedle.Set.ContainsKey(pt) || EnemyMgr.Instance.IsInSafeAttackRange(pt))
+                        {
+                            index = (index + 1) % MapAdapter.Instance.QudrantInfo[x, y].Count;
+                        }
+                        else
+                        {
+                            m_ptDest = pt;
+                            return;
+                        }
+                    }
+                }
+
+            }
+        }
+        void GetDestionation(Vector<BotInfo> vecOtherBots)//确保vecOtherBots的个数大于0
+        {
+            int nMissionDist = 0;
+            NavPoint nvPoint = MissionMgr.Instance.GetNextCollectorNavigatePoint(Location,out nMissionDist);
+
+            int nAttackDist = 0;
+            BotInfo botAttacked = null;
+
+            if (vecOtherBots.Count > 0)
+            {
+                BroadTree tree = BroadTree.MakeBroadTree(Location);
+                botAttacked = vecOtherBots[0];
+                nAttackDist = tree.GetWeight(botAttacked.Location);
+
+                for (int i = 1; i < vecOtherBots.Count; i++)
+                {
+                    int d = tree.GetWeight(vecOtherBots[i].Location);
+                    if (d < nAttackDist)
+                    {
+                        botAttacked = vecOtherBots[i];
+                        nAttackDist = d;
+                    }
+                }
+            }
+
+            if (nvPoint == null)
+            {
+                if (botAttacked == null)
+                {
+                    GetRandomDestionation(Location.X / 100, Location.Y / 100);
+                }
+                else
+                {
+                    m_ptDest = botAttacked.Location;
+                    if (botAttacked.BotType == BotType.AI)
+                        m_curAction = KILLER_ACTION.ATTACKAI;
+                    else
+                        m_curAction = KILLER_ACTION.ATTACKNEEDLE;
+                }
+            }
+            else
+            {
+                if (botAttacked == null || nMissionDist < nAttackDist)
+                {
+                    m_ptDest = nvPoint.Location;
+                    m_curAction = KILLER_ACTION.MISSION;
+                    m_nStartTurn = nvPoint.StartTurn;
+                    m_nEndTurn = nvPoint.EndTurn;
+                    MissionMgr.Instance.GainACollectorMission(nvPoint.Location, m_InnerBot);
+                }
+                else
+                {
+                    
+                    m_ptDest = botAttacked.Location;
+                    if (botAttacked.BotType == BotType.AI)
+                        m_curAction = KILLER_ACTION.ATTACKAI;
+                    else
+                        m_curAction = KILLER_ACTION.ATTACKNEEDLE;
+                }
+            }
+        }
+
+        Collector Collector
+        {
+            get { return (Collector)m_InnerBot; }
+        }
+        static int[] ms_QuadsX = new int[] { 0, 1, 1, 0 };
+        static int[] ms_QuadsY = new int[] { 0, 0, 1, 1 };
+
+        /*******************************************************
+        * new version
+        * ****************************************************/
+        Vector<BotInfo> GetOtherAIAndNeedleInfo()
+        {
+            Vector<BotInfo> vecOtherBots = new Vector<BotInfo>();
+            if (EnemyMgr.Instance.AIInfo != null)
+                vecOtherBots.Add(EnemyMgr.Instance.AIInfo);
+            foreach (BotInfo bot in EnemyMgr.Instance.AllNeedles.Values)
+                vecOtherBots.Add(bot);
+            return vecOtherBots;
+        }
+        public bool MissionAction()
+        {
+            if (Location == m_ptDest)//到达目标点
+            {
+                if (Team.CurrentTurn <= m_nStartTurn)
+                {
+                    Collector.StopMoving();
+                    return true;
+                }
+                else
+                {
+                    MissionMgr.Instance.ComplishACollectorMission(Location);
+                    Vector<BotInfo> vecBots = GetOtherAIAndNeedleInfo();
+                    GetDestionation(vecBots);
+                    Collector.StopMoving();
+                    Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, m_ptDest));
+                    return true;
+                }
+            }
+            if (State == BotState.WaitingOrders)
+            {
+                Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, m_ptDest));
+                return true;
+            }
+            return true;
+        }
+        public bool AttackAIAction()
+        {
+            if (EnemyMgr.Instance.AIInfo != null)
+            {
+                m_ptDest = EnemyMgr.Instance.AILocation;
+                Collector.StopMoving();
+                Collector.MoveTo(AStarPathFinder.Instance.GetPathPoint(Location, m_ptDest));
+                return true;
+            }
+
+            if (Location == m_ptDest)
+            {
+                if(!m_bSelectInitMissionTask)//还没有选择过出生点
+                {
+                    NavPoint np = MissionMgr.Instance.GetInitCollectorNavigatePoint(new Random().Next(4));