private static void Interact(EntityCharacteristic ec1, EntityCharacteristic ec2) { Battle battle = new Battle(ec1, ec2); ToFile.Write("(" + (battle.Luck ? "F" : "S") + ") "); string str2 = $"[ {battle.Winner} > {battle.Loser} ]"; ToFile.Write(String.Format("{0,-100}", str2)); battle.Winner.Score += SCORE_WIN; battle.Winner.WinRate *= WINRATE_WIN; bool injury = (battle.WBehavior == battle.LBehavior && (battle.WBehavior == EntityBehavior.Attack || battle.WBehavior == EntityBehavior.Incr_Intensity)); bool pr_meet = (battle.Winner.Type == EntityType.Prober_Retaliator && battle.Winner.Type == EntityType.Prober_Retaliator); bool waste_time = (battle.WBehavior == EntityBehavior.Threaten && battle.LBehavior == EntityBehavior.Threaten); if (injury) { battle.Winner.Score += SCORE_INJURY; battle.Loser.Score += SCORE_INJURY; battle.Winner.WinRate *= WINRATE_INJURY; battle.Loser.WinRate *= WINRATE_INJURY; } if (pr_meet) { battle.Winner.WinRate *= WINRATE_MEET_PR; battle.Loser.WinRate *= WINRATE_MEET_PR; } if (waste_time) { battle.Winner.Score += SCORE_WASTE_TIME; battle.Loser.Score += SCORE_WASTE_TIME; } ToFile.WriteLine($" => [ {battle.Winner} | {battle.Loser} ]"); }
private void Simulate() { List <EntityCharacteristic> ecs = new List <EntityCharacteristic>(this._count); foreach (EntityType type in typeof(EntityType).GetEnumValues()) { int amnt = this.Distibution.GetDistributeOf(type, this._count); for (int i = 0; i < amnt; ++i) { ecs.Add(EntityCharacteristic.GetDefault(type)); } } int amount = this._generation; for (int l = 0; l < amount; ++l) { ToFile.WriteLine($"================== Generation {l + 1} =================="); for (int k = 0; k < this._interactionC; ++k) { ecs.Shuffle(); for (int i = 0; i < ecs.Count / 2; ++i) { Interact(ecs[2 * i], ecs[2 * i + 1]); } } ToFile.WriteLine(); PrintResult(this.GetScore(ecs)); ToFile.WriteLine(); ToFile.WriteLine(); } }
public Battle(EntityCharacteristic ec1, EntityCharacteristic ec2) { EntityBehavior eb1 = Interaction.Get(ec1.Type, ec2.Type); EntityBehavior eb2 = Interaction.Get(ec2.Type, ec1.Type); this.Luck = false; if (eb1 == eb2) { bool firstwon = this._random.NextDouble() < (ec1.WinRate / (ec1.WinRate + ec2.WinRate)); this.Winner = firstwon ? ec1 : ec2; this.Loser = firstwon ? ec2 : ec1; this.Luck = true; } else if (eb1 == EntityBehavior.Run || eb2 == EntityBehavior.Run) { this.Winner = (eb1 == EntityBehavior.Run) ? ec2 : ec1; this.Loser = (eb1 == EntityBehavior.Run) ? ec1 : ec2; } else if (eb1 != eb2) { this.Winner = (eb1 == EntityBehavior.Attack) ? ec1 : ec2; this.Loser = (eb1 == EntityBehavior.Attack) ? ec2 : ec1; } if (this.Winner != null) { this.WBehavior = Interaction.Get(this.Winner.Type, this.Loser.Type); } else { this.WBehavior = null; } if (this.Loser != null) { this.LBehavior = Interaction.Get(this.Loser.Type, this.Winner.Type); } else { this.LBehavior = null; } }