/// <summary> /// 获取攻击目标 /// </summary> /// <param name="canAttTanks"></param> /// <returns></returns> private TankInfo GetAttTank(List <TankInfo> canAttTanks) { if (canAttTanks == null || canAttTanks.Count == 0) { return(null); } canAttTanks.Sort(); TankInfo rinfo = canAttTanks[0]; foreach (TankInfo info in canAttTanks) { if (rinfo == info) { continue; } if (info.ShengYuShengMing <= this.TankInfo.Gongji) { rinfo = info; break; } if (info.Adv == TankAdv.Attack) { rinfo = info; } } return(rinfo); }
protected override TanksAction AbsGetAction(GameInfo controller, TankInfo info) { if (info.Destination == null) { info.Destination = new Point(int.Parse(controller.SourceInfo.MapInfo.ColLen) / 2, int.Parse(controller.SourceInfo.MapInfo.RowLen) / 2); } if (base.Controller.GodCount == 0 && info.ShengYuShengMing == 1) { return(base.Retreat()); } if (controller.BossInfo.Location != null) { if (controller.BossInfo.ShengYuShengMing < 5) { info.Destination = controller.BossInfo.Location.Value; return(base.Boss()); } else { return(FindEnemy(true)); } } if (info.Destination.Value != info.Location.Value) { return(FindEnemy(false)); } else { return(base.Defend()); } }
private void SetGodTank() { int delta1; int delta2; int count = 9999; TankInfo tankInfo = null; foreach (TankInfo tank in SharedResources.OurTanks) { foreach (Point point in GodB) { delta1 = Math.Abs(tank.Location.Value.X - point.X); delta2 = Math.Abs(tank.Location.Value.Y - point.Y); if (count > (delta1 + delta2) / tank.YiDong) { count = delta1 + delta2; tankInfo = tank; } } } if (tankInfo != null) { tankInfo.NextCommand = TankActionEnum.God; } }
protected override TanksAction AbsGetAction(GameInfo controller, TankInfo info) { if (info.Destination == null) { info.Destination = new Point((int.Parse(controller.SourceInfo.MapInfo.ColLen) / 2) + 1, int.Parse(controller.SourceInfo.MapInfo.RowLen) / 2); } List <TankInfo> atttks = CanAttackEnemy(); if (atttks.Count > 0) { return(Attack(atttks, null)); } if (controller.BossInfo.Location != null) { info.Destination = controller.BossInfo.Location.Value; return(Boss()); } atttks = FindNearEnemy(); if (atttks.Count > 0) { return(Attack(null, atttks)); } if (info.Destination.Value != info.Location.Value) { return(Find()); } return(Defend()); }
public bool Contrast(TankInfo info) { if (this.SheCheng > info.SheCheng) { return(true); } return(this.ShengYuShengMing * Gongji > (info.ShengYuShengMing + 1) * Gongji); }
/// <summary> /// 设置我方坦克坐标 /// </summary> /// <param name="point"></param> /// <param name="tankId"></param> private void SetOurLocation(Point point, string tankId) { TankInfo info = SharedResources.OurTanks.FirstOrDefault(p => p.TId.Equals(tankId)); if (info != null) { info.Location = point; } }
/// <summary> /// 设置地方坦克坐标 /// </summary> /// <param name="point"></param> /// <param name="tankId"></param> private void SetEnemyLocation(Point point, string tankId) { TankInfo info = EnemyTanks.FirstOrDefault(p => p.TId.Equals(tankId)); if (info != null && info.ShengYuShengMing > 0) { info.Location = point; } }
public void UpdateInfo(List <TankInfo> infos) { TankInfo info = infos.FirstOrDefault(p => p.TId.Equals(this.TId)); if (info != null) { this.ShengYuShengMing = info.ShengYuShengMing; this.LastCommand = this.NextCommand; this.NextCommand = TankActionEnum.Null; } }
/// <summary> /// 进攻 /// </summary> protected virtual TanksAction Attack(List <TankInfo> canAttTanks, List <TankInfo> nearTanks) { if (canAttTanks == null && nearTanks == null) { canAttTanks = CanAttackEnemy(); nearTanks = FindNearEnemy(); } if (SharedResources.AttTank != null) { if (canAttTanks.Contains(SharedResources.AttTank)) { return(new TanksAction() { UseGlod = IsGod, Length = this.TankInfo.SheCheng, Direction = Conversion(this.TankInfo.Location.Value, SharedResources.AttTank.Location.Value).ToString(), TId = this.TankInfo.TId, ActionType = ActionTypeEnum.FIRE.ToString() }); } else { if (canAttTanks == null || canAttTanks.Count == 0) { return(this.Find(GetAttPoint(SharedResources.AttTank), false)); } } } if (canAttTanks != null && canAttTanks.Count > 0) { TankInfo tinfo = GetAttTank(canAttTanks); SharedResources.AttTank = tinfo; return(new TanksAction() { UseGlod = IsGod, Length = this.TankInfo.SheCheng, Direction = Conversion(this.TankInfo.Location.Value, tinfo.Location.Value).ToString(), TId = this.TankInfo.TId, ActionType = ActionTypeEnum.FIRE.ToString() }); } else { if (nearTanks == null) { return(Defend()); } TankInfo tinfo = GetAttTank(nearTanks); SharedResources.AttTank = tinfo; Debug.WriteLine("11"); return(this.Find(GetAttPoint(tinfo), false)); } }
public int CompareTo(object obj) { TankInfo tank = obj as TankInfo; if (tank != null) { return(this.ShengYuShengMing - tank.ShengYuShengMing); } else { return(-1); } }
/// <summary> /// 获取进攻位置 /// </summary> /// <returns></returns> private Point GetAttPoint(TankInfo tinfo) { Point point = tinfo.Location.Value; List <Point> listPoint = new List <Point>(); int row = point.X - this.TankInfo.SheCheng >= 0 ? point.X - this.TankInfo.SheCheng : 0; int col = point.Y; Point newPoint = new Point(row, col); if (IsRoad(newPoint)) { listPoint.Add(newPoint); } row = point.X + this.TankInfo.SheCheng < int.Parse(this.Controller.SourceInfo.MapInfo.RowLen) ? point.X + this.TankInfo.SheCheng : int.Parse(this.Controller.SourceInfo.MapInfo.RowLen) - this.TankInfo.SheCheng; newPoint = new Point(row, col); if (IsRoad(newPoint)) { listPoint.Add(newPoint); } row = point.X; col = point.Y - this.TankInfo.SheCheng >= 0 ? point.Y - this.TankInfo.SheCheng : 0; newPoint = new Point(row, col); if (IsRoad(newPoint)) { listPoint.Add(newPoint); } col = point.Y + this.TankInfo.SheCheng < int.Parse(this.Controller.SourceInfo.MapInfo.ColLen) ? point.Y + this.TankInfo.SheCheng : int.Parse(this.Controller.SourceInfo.MapInfo.ColLen) - this.TankInfo.SheCheng; newPoint = new Point(row, col); if (IsRoad(newPoint)) { listPoint.Add(newPoint); } int index = 0, count = -1; int delta1; int delta2; for (int i = 0; i < listPoint.Count; i++) { delta1 = Math.Abs(listPoint[i].X - this.TankInfo.Location.Value.X); delta2 = Math.Abs(listPoint[i].Y - this.TankInfo.Location.Value.Y); if (count == -1 || count > delta1 + delta2) { count = delta1 + delta2; index = i; } } if (listPoint.Count <= 0) { return(point); } return(listPoint[index]); }
/// <summary> /// 获取坦克下一步动作 /// </summary> /// <param name="controller"></param> /// <param name="info"></param> /// <returns></returns> public TanksAction GetNextAction(GameInfo controller, TankInfo info) { if (controller.GodCount > 0) { if (this.TankInfo.IsDie && this.TankInfo.Adv != TankAdv.Speed) { IsGod = true; } if (this.TankInfo.Adv == TankAdv.Defend && this.TankInfo.ShengYuShengMing < 2) { IsGod = true; } } this.TankInfo = info; Controller = controller; CanAttackPoint = GetAttackRange(); switch (info.NextCommand) { case TankActionEnum.Null: return(AbsGetAction(Controller, this.TankInfo)); case TankActionEnum.Attack: return(Attack(null, null)); case TankActionEnum.Boss: return(Boss()); case TankActionEnum.Defend: return(Defend()); case TankActionEnum.Find: return(Find()); case TankActionEnum.God: return(God()); case TankActionEnum.Retreat: return(Retreat()); } if (SharedResources.AttTank != null) { return(Attack(null, null)); } return(AbsGetAction(Controller, this.TankInfo)); }
protected override TanksAction AbsGetAction(GameInfo controller, TankInfo info) { if (SharedResources.AttTank != null) { return(Attack(null, null)); } List <TankInfo> cantank = CanAttackEnemy(); if (cantank.Count > 0) { Debug.WriteLine("阿斯玛发现可以攻击的敌人"); base.Attack(cantank, null); } if (FindNearEnemy().Count > 0) { base.Retreat(); } if (base.Controller.Fogs.Count > 0) { return(Find()); } TankInfo tinfo = SharedResources.OurTanks.FirstOrDefault(p => p.Adv == TankAdv.Defend && p.IsDie == false); if (tinfo == null) { tinfo = SharedResources.OurTanks.FirstOrDefault(p => p.Adv == TankAdv.Attack && p.IsDie == false); } if (tinfo == null) { tinfo = SharedResources.OurTanks.FirstOrDefault(p => p.Adv == TankAdv.Range && p.IsDie == false); } if (tinfo == null) { tinfo = SharedResources.OurTanks.FirstOrDefault(p => p.Adv == TankAdv.Speed && p.IsDie == false && p.Location != info.Location); } if (tinfo == null) { return(Defend()); } info.Destination = GetNearRoad(tinfo.Location.Value); return(base.Find()); }
protected override TanksAction AbsGetAction(GameInfo controller, TankInfo info) { if (info.Destination == null) { info.Destination = new Point((int.Parse(controller.SourceInfo.MapInfo.ColLen) / 2) - 1, int.Parse(controller.SourceInfo.MapInfo.RowLen) / 2); } if (controller.BossInfo.Location != null) { if (controller.BossInfo.ShengYuShengMing < 5) { return(base.Boss()); } else { return(FindEnemy(true)); } } if (SharedResources.AttTank != null) { return(Attack(null, null)); } return(FindEnemy(false)); }
protected abstract TanksAction AbsGetAction(GameInfo controller, TankInfo info);