public override ActionEnum Action(List <Element> elements, float angleToCenter, bool inZone, ref float xdelta, ref float ydelta, ref float angle) { // check if last action failed if (LastActionFailed > 0) { LastActionFailed--; xdelta = Xdelta; ydelta = Ydelta; return(ActionEnum.Move); } // construct a view of the current world var data = new TrainingData() { // core data CenterAngle = angleToCenter, InZone = inZone, Health = Health, Shield = Shield, Z = Z, Primary = Primary != null?Primary.GetType().Name : "", PrimaryAmmo = Primary != null ? Primary.Ammo : 0, PrimaryClip = Primary != null ? Primary.Clip : 0, Secondary = Secondary != null?Secondary.GetType().Name : "", SecondaryAmmo = Secondary != null ? Secondary.Ammo : 0, SecondaryClip = Secondary != null ? Secondary.Clip : 0 }; data.Proximity = AITraining.ComputeProximity(this, elements).Values.ToList(); // use the model to predict its actions var modeldataset = data.AsModelDataSet(); int iAction = 0; { iAction = (int)Math.Round(ActionModel.Predict(modeldataset)); angle = AngleModel.Predict(modeldataset); XYModel.Predict(modeldataset, out xdelta, out ydelta); } // do some sanity checking... if (iAction < 0 || iAction >= (int)ActionEnum.COUNT) { iAction = (int)ActionEnum.Move; } if (Math.Abs(xdelta) + Math.Abs(ydelta) > 1.00001) { throw new Exception("xdelta and ydelta are invalid"); } if (angle < 0) { angle += 360; } if (angle > 360) { angle -= 360; } if (angle < 0 || angle > 360) { throw new Exception("Invalid angle: " + angle); } return((ActionEnum)iAction); }
public override ActionEnum Action(List <Element> elements, float angleToCenter, bool inZone, ref float xdelta, ref float ydelta, ref float zdelta, ref float angle) { // check if last action failed if (LastActionFailed > 0) { LastActionFailed--; xdelta = Xdelta; ydelta = Ydelta; return(ActionEnum.Move); } // construct a view of the current world var pname = ""; var pammo = 0; var pclip = 0; var sname = ""; var sammo = 0; var sclip = 0; if (Primary != null && Primary is RangeWeapon) { pname = Primary.GetType().Name; pammo = (Primary as RangeWeapon).Ammo; pclip = (Primary as RangeWeapon).Clip; } if (Secondary != null && Secondary.Length == 1 && Secondary[0] != null && Secondary[0] is RangeWeapon) { sname = Secondary.GetType().Name; sammo = (Secondary[0] as RangeWeapon).Ammo; sclip = (Secondary[0] as RangeWeapon).Clip; } var data = new TrainingData() { // core data CenterAngle = angleToCenter, InZone = inZone, Health = Health, Shield = Shield, Z = Z, Primary = pname, PrimaryAmmo = pammo, PrimaryClip = pclip, Secondary = sname, SecondaryAmmo = sammo, SecondaryClip = sclip }; data.Proximity = AITraining.ComputeProximity(this, elements).Values.ToList(); // use the model to predict its actions var modeldataset = data.AsModelDataSet(); int iAction = 0; { iAction = (int)Math.Round(ActionModel.Predict(modeldataset)); angle = AngleModel.Predict(modeldataset); XYModel.Predict(modeldataset, out xdelta, out ydelta); } // do some sanity checking... if (iAction < 0 || iAction >= (int)ActionEnum.COUNT) { iAction = (int)ActionEnum.Move; } if (Math.Abs(xdelta) + Math.Abs(ydelta) > 1.00001) { throw new Exception("xdelta and ydelta are invalid"); } while (angle < 0) { angle += 360; } while (angle >= 360) { angle -= 360; } if (angle < 0 || angle >= 360) { throw new Exception("Invalid angle: " + angle); } return((ActionEnum)iAction); }