// PRIVATE METHODS private static double FightViewers(FightOutcome fo) { double viewers; Fighter f1 = fo.Fighter1(); Fighter f2 = fo.Fighter2(); //Country country = f1.Nationality; //Console.WriteLine(f1.Nationality + "'s buff is " + country.PopularityBuff); WeightClass w1 = (WeightClass)f1.Weight; //WeightCoefficient[w1.Weight] fo.Interested = MathUtils.Gauss(((f1.Performance["Elo"] + f2.Performance["Elo"]) / 2), 100) * (f1.Nationality.PopularityBuff * f2.Nationality.PopularityBuff * w1.Popularity + f1.Belts + f2.Belts); //viewers = f1.Performance["Fans"] + f1.Performance["Followers"] + f1.Performance["Casuals"]; //viewers += (f1.Performance["Fans"] + f2.Performance["Followers"] + f2.Performance["Casuals"]); viewers = fo.Interested + (PWin(fo)) * f1.Performance["Followers"] + (1 - PWin(fo) * f2.Performance["Followers"]) + (PWin(fo)) * f1.Performance["Fans"] + (1 - PWin(fo) * f2.Performance["Fans"]); return(viewers); }
public void ProcessExpedition(ExpeditionData data, uint currentRoundNumber) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (currentRoundNumber < data.StartingRound || currentRoundNumber > data.EndingRound) { return; // already processed } decimal militaryPower = this.CalculateCurrentExpeditionPower(data, PowerType.Military); // increase defense and range decimal sciencePower = this.CalculateCurrentExpeditionPower(data, PowerType.Science); // increases rare findings per turn decimal laborPower = this.CalculateCurrentExpeditionPower(data, PowerType.Labour); // increase range & findings per turn decimal rangeDelta = this.CalculateRangeIncrease(militaryPower, laborPower); data.CurrentRange += rangeDelta; // calculate new findings - depending on passing turn and total range var explorableResources = ResourceInfo.KnownResources.Where(r => r.FindingProbability > 0.0m && r.BaseFindSize > 0.0m); foreach (var explorableResource in explorableResources) { var finding = this.CalculateFindingSize(explorableResource, militaryPower, sciencePower, laborPower, data.CurrentRange); data.DiscoveredResources.Add(finding); } // calculate endangerment (if any) depending on passing turn (& range) decimal dangerLevel = this.CalculateDangerLevel(data.CurrentRange, data.StartingRound, currentRoundNumber); // fight var enemyForces = this.GenerateOpposingForce(dangerLevel); if (enemyForces.AnyOne()) { FightOutcome outcome = this._fightLogic.CalculateFight(enemyForces, data.RemainingUnits); if (outcome.JunkProduced.Value > 0) { data.DiscoveredResources.Add(outcome.JunkProduced); } // reduce units if (outcome.RazedDefenders.AnyOne()) { data.RemainingUnits.Substract(outcome.RazedDefenders); } } // left at least one worker and stop expedition at that point if (!data.RemainingUnits.AnyOne()) { this._unitLogic.AddWorkers(data.RemainingUnits, 1); data.EndingRound = currentRoundNumber; } }
public void PrintFightResult(int index1, int index2, FightOutcome fo) { Console.WriteLine(Fighters[index1].Name + "(elo = " + Fighters[index1].Record.Rank.ToString("0") + ") vs " + Fighters[index2].Name + "(elo = " + Fighters[index2].Record.Rank.ToString("0") + ")"); Console.WriteLine(fo.Winner.Name + " wins in front of " + fo.Viewership + "k audience"); Console.Write("Elo changes: " + Fighters[index1].Name + " (" + Fighters[index1].Record.PreviousRank.ToString("0") + " to " + Fighters[index1].Record.Rank.ToString("0") + ") "); Console.WriteLine(Fighters[index2].Name + " (" + Fighters[index2].Record.PreviousRank.ToString("0") + " to " + Fighters[index2].Record.Rank.ToString("0") + ")\n"); }
public FightOutcome SimulateFight(int index1, int index2, bool printResult = true, bool sortFighters = false) { Fighter f1 = Fighters[index1]; Fighter f2 = Fighters[index2]; Fight ff = new Fight(f1, f2); IFightSimulator fs = new EloFightSimulator(); FightOutcome fo = fs.SimulateFight(ff); if (printResult && (this.IsTopFighter(index1) || this.IsTopFighter(index2))) { PrintFightResult(index1, index2, fo); } if (sortFighters) // sort the pool { SortFighters(); } return(fo); }
/// <summary> /// called from on death in this and EnemyFighter classes. /// sets global (game level) health and stamina, /// scaling stamina appropriately. /// sets global variable indicating whether we won or lost. /// </summary> public override void InformWorld(bool win) { character.health = (int)health; int staminaLoss = (int)(staminaLossPerMinute * (staminaTimer % 60)); if (character.stamina - staminaLoss >= 0) { character.stamina -= (int)(staminaLossPerMinute * ((staminaTimer / 60) + (staminaTimer % 60))); } else { character.stamina = 0; } FightOutcome.wonFight = win; FightOutcome.LoseItemsAfterLosingFight(); FightOutcome.currentlyFighting = null; }
public Fight(Data.Fight fight) { this.Fighter1Score = fight.Fighter1Score; this.Fighter2Score = fight.Fighter2Score; this.Fighter1 = new Model.FighterStats(fight.Fighter1); this.Fighter2 = new Model.FighterStats(fight.Fighter2); FightOutcome outcome = FightOutcome.Draw; if (fight.Fighter1Win == true) { outcome = FightOutcome.Win; } else if (fight.Fighter1Win == false) { outcome = FightOutcome.Loss; } SetJudgeScores(); this.Result = new FightResult() { Outcome = outcome, Rounds = fight.NumberOfRounds, ResultType = (FightResultType)fight.ResultType, TkoCut = fight.TkoCut }; this.RoundResults = new List <Model.Round>(); foreach (Data.Round r in fight.Rounds) { Round rr = new Model.Round(r) { Fight = this }; rr.Fighter1Round.SetPercentages(fight.Fighter1.Conditioning * 10); rr.Fighter2Round.SetPercentages(fight.Fighter2.Conditioning * 10); this.RoundResults.Add(rr); } }
public void SimulateFights(int epsilon = 16) { int op; int coeff; IFightSimulator fs = new EloFightSimulator(); for (int i = 0; i < Fighters.Count(); i++) { coeff = (rand.Next(0, 2) > 0) ? 1 : -1; op = i + coeff * rand.Next(1, epsilon); if (op < 0) { op += epsilon; } else if (op > Fighters.Count() - 1) { op -= epsilon; } FightOutcome fo = this.SimulateFight(i, op); } SortFighters(); }
/// <summary> // The method update fighter popularity of both fighters as a result // of FightOutcome object // // at the end of the method, FighterOutcome viewership is set by the // result of a private FightViewers(FighterOutcome) method. No need to // to call FightViewers outside of this class. /// </summary> public static void UpdatePopularity(FightOutcome fo) { double fans1 = fo.Fighter1().Performance["Fans"]; double fans2 = fo.Fighter2().Performance["Fans"]; double casuals1 = fo.Fighter1().Performance["Casuals"]; double casuals2 = fo.Fighter2().Performance["Casuals"]; double followers1 = fo.Fighter1().Performance["Followers"]; double followers2 = fo.Fighter2().Performance["Followers"]; Console.WriteLine("Fighter1: " + ToString(fo.Fighter1())); Console.WriteLine("Fighter2: " + ToString(fo.Fighter2())); double CountryCoeff1 = fo.Fighter1().Nationality.PopularityBuff; double CountryCoeff2 = fo.Fighter2().Nationality.PopularityBuff; double WeightCoeff = ((WeightClass)fo.Fighter1().Weight).Popularity; // do the calculation if (fo.Fighter1() == fo.Winner) { //winner double delta = 0.09 * casuals1 * (1 - PWin(fo)) * WeightCoeff * CountryCoeff1; delta = MathUtils.Gauss(delta, 0.5); fans1 += delta; casuals1 -= delta; delta = 0.4 * fo.Interested * (1 - PWin(fo)) * WeightCoeff * CountryCoeff1; delta = MathUtils.Gauss(delta, 0.5); casuals1 += delta; //fo.Interested =- delta; delta = 0.09 * casuals1 * (1 - PWin(fo)) * WeightCoeff * CountryCoeff1; delta = MathUtils.Gauss(delta, 0.5); followers1 += delta; casuals1 -= 0.18 * casuals1; //loser delta = 0.1 * fans2 * (1 - PWin(fo)); delta = MathUtils.Gauss(delta, 0.5); fans2 -= delta; casuals2 += delta; delta = 0.1 * casuals2 * (1 - PWin(fo)); delta = MathUtils.Gauss(delta, 0.5); casuals2 -= delta; //fo.Interested = +delta; delta = 0.1 * followers2 * (1 - PWin(fo)); delta = MathUtils.Gauss(delta, 0.5); followers2 -= delta; casuals2 += delta; } else if (fo.Fighter2() == fo.Winner) { //loser double delta = 0.09 * casuals1 * (PWin(fo)); delta = MathUtils.Gauss(delta, 0.5); fans1 -= delta; casuals1 += delta; delta = 0.4 * fo.Interested * (PWin(fo)); delta = MathUtils.Gauss(delta, 0.5); casuals1 -= delta; //fo.Interested =+ delta; delta = 0.09 * casuals1 * (PWin(fo)); delta = MathUtils.Gauss(delta, 0.5); followers1 -= delta; casuals1 += 0.18 * casuals1; //winner delta = 0.1 * fans2 * (PWin(fo)) * WeightCoeff * CountryCoeff2; delta = MathUtils.Gauss(delta, 0.5); fans2 += delta; casuals2 -= -delta; delta = 0.1 * casuals2 * (PWin(fo)) * WeightCoeff * CountryCoeff2; delta = MathUtils.Gauss(delta, 0.5); casuals2 += delta; //fo.Interested =- delta; delta = 0.1 * followers2 * (PWin(fo)) * WeightCoeff * CountryCoeff2; delta = MathUtils.Gauss(delta, 0.5); followers2 += delta; casuals2 -= delta; } // end of calculation fo.Fighter1().Performance["Fans"] = fans1; fo.Fighter2().Performance["Fans"] = fans2; fo.Fighter1().Performance["Casuals"] = casuals1; fo.Fighter2().Performance["Casuals"] = casuals2; fo.Fighter1().Performance["Followers"] = followers1; fo.Fighter2().Performance["Followers"] = followers2; fo.Viewership = FightViewers(fo); Console.WriteLine(ToString(fo)); Console.WriteLine("Fighter1: " + ToString(fo.Fighter1())); Console.WriteLine("Fighter2: " + ToString(fo.Fighter2()) + "\n"); }
internal static double PWin(FightOutcome fo) { return(1 / (1 + Math.Pow(10, (fo.Fighter2().Performance["Elo"] - fo.Fighter1().Performance["Elo"]) / 400))); }
private static double fightAttendance(FightOutcome fo, Fighter A, Fighter B) { double elasticity = 0; using (XmlReader reader = XmlReader.Create(@"venues.xml")) { while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name.ToString()) { case "Alabama": elasticity = -6; break; case "Alaska": elasticity = -6; break; case "Arizona": elasticity = -6; break; case "Arkansas": elasticity = -6; break; case "California": elasticity = -3; break; case "Colorado": elasticity = -6; break; case "Connecticut": elasticity = -6; break; case "Delaware": elasticity = -6; break; case "Florida": elasticity = -5; break; case "Georgia": elasticity = -5; break; case "Hawaii": elasticity = -6; break; case "Idaho": elasticity = -6; break; case "Illinois": elasticity = -6; break; case "Indiana": elasticity = -6; break; case "Iowa": elasticity = -6; break; case "Kansas": elasticity = -6; break; case "Kentucky": elasticity = -6; break; case "Louisiana": elasticity = -6; break; case "Maine": elasticity = -6; break; case "Maryland": elasticity = -6; break; case "Massachusetts": elasticity = -3; break; case "Michigan": elasticity = -6; break; case "Minnesota": elasticity = -6; break; case "Mississippi": elasticity = -6; break; case "Missouri": elasticity = -6; break; case "Montana": elasticity = -6; break; case "Nebraska": elasticity = -6; break; case "Nevada": elasticity = -2; break; case "New Hampshire": elasticity = -6; break; case "New Jersey": elasticity = -3; break; case "New Mexico": elasticity = -6; break; case "New York": elasticity = -3; break; case "North Carolina": elasticity = -6; break; case "North Dakota": elasticity = -6; break; case "Ohio": elasticity = -6; break; case "Oklahoma": elasticity = -6; break; case "Oregon": elasticity = -6; break; case "Pennsylvania": elasticity = -3; break; case "Rhode Island": elasticity = -6; break; case "South Carolina": elasticity = -6; break; case "South Dakota": elasticity = -6; break; case "Tennessee": elasticity = -6; break; case "Texas": elasticity = -6; break; case "Utah": elasticity = -6; break; case "Vermont": elasticity = -6; break; case "Virginia": elasticity = -6; break; case "Washington": elasticity = -6; break; case "Washington DC": elasticity = -6; break; case "West Virginia": elasticity = -6; break; case "Wisconsin": elasticity = -6; break; case "Wyoming": elasticity = -6; break; } } } Console.ReadKey(); } Random random = new Random(); double mathResult = Math.Round((random.NextDouble() * (0.005) + 0.03)); double demand = mathResult * (getBase(A) * (1 - PWin(fo)) + getBase(B) * (1 - PWin(fo))); double price = 0; // up to user return(elasticity * price + demand); }
public static string ToString(FightOutcome fo) { string s = ($"Viewership:{fo.Viewership:N0}"); return(s); }
public void SetFightOutcomeDecision() { FightOutcome outcome = GetDecisionResult(); this.Result = new Model.FightResult(outcome, this.RoundResults.Count, FightResultType.Decision); }
public FightResult(FightOutcome outcome, int rounds, FightResultType resultType) { this.Outcome = outcome; this.Rounds = rounds; this.ResultType = resultType; }