/// <summary> /// Given a list of points, find a circle that roughly passes through them all. /// </summary> public static CircleSegment ComputeCircle(System.Collections.Generic.IEnumerable <Point2d> l) { // https://www.scribd.com/document/14819165/Regressions-coniques-quadriques-circulaire-spherique // via http://math.stackexchange.com/questions/662634/find-the-approximate-center-of-a-circle-passing-through-more-than-three-points var n = l.Count(); var sumx = l.Sum(p => p.X); var sumxx = l.Sum(p => p.X * p.X); var sumy = l.Sum(p => p.Y); var sumyy = l.Sum(p => p.Y * p.Y); var d11 = n * l.Sum(p => p.X * p.Y) - sumx * sumy; var d20 = n * sumxx - sumx * sumx; var d02 = n * sumyy - sumy * sumy; var d30 = n * l.Sum(p => p.X * p.X * p.X) - sumxx * sumx; var d03 = n * l.Sum(p => p.Y * p.Y * p.Y) - sumyy * sumy; var d21 = n * l.Sum(p => p.X * p.X * p.Y) - sumxx * sumy; var d12 = n * l.Sum(p => p.Y * p.Y * p.X) - sumyy * sumx; var x = ((d30 + d12) * d02 - (d03 + d21) * d11) / (2 * (d20 * d02 - d11 * d11)); var y = ((d03 + d21) * d20 - (d30 + d12) * d11) / (2 * (d20 * d02 - d11 * d11)); var c = (sumxx + sumyy - 2 * x * sumx - 2 * y * sumy) / n; var r = Math.Sqrt(c + x * x + y * y); return(new CircleSegment(new Point2f((float)x, (float)y), (float)r)); }
protected override IEnumerable <IFightResult> GenerateResults() { System.Collections.Generic.List <IFightResult> list = new System.Collections.Generic.List <IFightResult>(); list.AddRange( from entry in base.GetAllFightersWithLeavers() where !(entry is IOwnable) select entry.GetFightResult()); FightTeam[] teams = new FightTeam[] { BlueTeam, RedTeam }; for (int i = 0; i < teams.Length; i++) { int xpBonusPercent = 0; int dropBonusPercent = 0; if (teams[i] == GetTeamChallenged()) { xpBonusPercent += GetChallengesExpPercentBonus(); dropBonusPercent += GetChallengesDropPercentBonus(); } FightTeam team = teams[i]; System.Collections.Generic.IEnumerable <Fighter> enumerable = ((team == base.RedTeam) ? base.BlueTeam : base.RedTeam).GetDeads(); IOrderedEnumerable <IFightResult> orderedEnumerable = list.FindAll(x => x.CanLoot(team)).OrderBy(x => x.Prospecting); int teamPP = team.GetFighters(false).Sum((Fighter entry) => entry.Stats.Prospecting.TotalInContext()); teamPP += teamPP.GetPercentageOf(dropBonusPercent); long baseKamas = enumerable.Sum((Fighter entry) => (long)((ulong)entry.GetDroppedKamas())); using (System.Collections.Generic.IEnumerator <IFightResult> enumerator = orderedEnumerable.GetEnumerator()) { while (enumerator.MoveNext()) { IFightResult looter = enumerator.Current; looter.Loot.Kamas = FormulasProvider.Instance.AdjustDroppedKamas(looter, teamPP, baseKamas, dropBonusPercent); System.Collections.Generic.IEnumerable <Fighter> arg_1F0_0 = enumerable; Func <Fighter, System.Collections.Generic.IEnumerable <DroppedItem> > selector = (Fighter dropper) => dropper.RollLoot(looter, dropBonusPercent); foreach (DroppedItem current in arg_1F0_0.SelectMany(selector)) { looter.Loot.AddItem(current); } if (looter is FightPlayerResult && looter.Outcome == FightOutcomeEnum.RESULT_VICTORY) { (looter as FightPlayerResult).AddEarnedExperience(xpBonusPercent); } } } } return(list); }