Beispiel #1
0
        public JsonResults <List <TanksAction> > Action(ReceiveInfo receiveInfo)
        {
            try
            {
                Stopwatch watch = new Stopwatch();
                watch.Start();
                GameInfo           gameInfo     = new GameInfo(receiveInfo);
                List <TanksAction> tanksActions = new List <TanksAction>();
                TanksAction        tanksAction  = null;
                foreach (TankInfo info in SharedResources.OurTanks)
                {
                    tanksAction = info.GetAction(gameInfo);
                    if (tanksAction != null)
                    {
                        tanksActions.Add(tanksAction);
                    }
                }

                JsonResults <List <TanksAction> > ret = new JsonResults <List <TanksAction> >
                {
                    Action = @"/action",
                    Code   = "0",
                    Msg    = "succeeded",
                    OK     = true,
                    Data   = tanksActions
                };
                watch.Stop();
                Debug.WriteLine(watch.ElapsedMilliseconds);
                return(ret);
            }
            catch (Exception ex)
            {
                List <TanksAction> tanksActions = new List <TanksAction>();
                foreach (TankInfo info in SharedResources.OurTanks)
                {
                    tanksActions.Add(new TanksAction {
                        ActionType = ActionTypeEnum.FIRE.ToString(),
                        Direction  = "UP",
                        Length     = info.SheCheng,
                        TId        = info.TId,
                        UseGlod    = false
                    });
                }
                JsonResults <List <TanksAction> > ret = new JsonResults <List <TanksAction> >
                {
                    Action = @"/action",
                    Code   = "0",
                    Msg    = "succeeded",
                    OK     = true,
                    Data   = tanksActions
                };
                return(ret);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 空指令
        /// </summary>
        protected virtual TanksAction Null()
        {
            TanksAction tanksAction = new TanksAction()
            {
                UseGlod    = IsGod,
                Length     = this.TankInfo.SheCheng,
                Direction  = DirectionEnum.UP.ToString(),
                TId        = this.TankInfo.TId,
                ActionType = ActionTypeEnum.FIRE.ToString()
            };

            return(tanksAction);
        }
Beispiel #3
0
 public TanksAction GetAction(GameInfo game)
 {
     if (this.ActionBase != null)
     {
         return(this.ActionBase.GetNextAction(game, this));
     }
     else
     {
         TanksAction tanks = new TanksAction
         {
             ActionType = ActionTypeEnum.FIRE.ToString(),
             Direction  = DirectionEnum.UP.ToString(),
             TId        = this.TId,
             Length     = this.SheCheng,
             UseGlod    = false
         };
         return(tanks);
     }
 }
Beispiel #4
0
        private TanksAction Find(Point tar, bool avoid)
        {
            Astar astar = new Astar
            {
                Team = Controller.SourceInfo.Team
            };
            ANode node = astar.Star(this.TankInfo.Location.Value, tar, GetTempMaps(avoid));

            if (node.Position == this.TankInfo.Location.Value)
            {
                return(Defend());
            }
            Stack <Point> points = GetDirection(node);
            Point         next   = points.Pop();
            int           length = 1;

            if (this.TankInfo.YiDong > 1 && points.Count > 0)
            {
                if (points.Peek().X == this.TankInfo.Location.Value.X || points.Peek().Y == this.TankInfo.Location.Value.Y)
                {
                    next   = points.Pop();
                    length = 2;
                }
            }
            TanksAction tanksAction = new TanksAction()
            {
                UseGlod    = IsGod,
                Length     = length,
                Direction  = this.Conversion(this.TankInfo.Location.Value, next).ToString(),
                TId        = this.TankInfo.TId,
                ActionType = ActionTypeEnum.MOVE.ToString()
            };

            points.Clear();
            return(tanksAction);
        }