public Fight(Team team_a, Team team_b) { random = ServiceRegistry.GetInstance().GetRandom(); this.team_a = team_a; this.team_b = team_b; }
public MetaSolver(int size, int generations) { this.size = size; this.generations = generations; teams = new List<Team>(); championTeam = new Team(); Initialize(); }
private void Generate() { for(int i = 0; i < size; i++) { Team team = new Team(); team.Generate(); teams.Add(team); } }
public void RunFight() { Pokemon attacker_p, defender_p; Team attacker_t, defender_t; attacker_t = team_a; defender_t = team_b; while (true) { defender_p = defender_t.SelectDefender(); attacker_p = attacker_t.SelectAttacker(defender_p); attacker_p.Attack(defender_p); if (defender_t.AliveCount < 1) { break; } Team temp = defender_t; defender_t = attacker_t; attacker_t = temp; } loser = defender_t; winner = attacker_t; }
public Team Mate(Team parent) { Team child = new Team(); while (child.team.Count < SIZE) { Pokemon pokemon; if (random.FlipCoin()) { pokemon = team[random.Next(SIZE)]; } else { pokemon = parent.team[random.Next(SIZE)]; } if (!child.team.Contains(pokemon)) { child.team.Add(pokemon); } } if (random.Mutate()) { child.Mutate(); } log.Debug("Parent 1: \n" + this + "Parent 2: \n" + parent); log.Debug("Child: \n" + child); return child; }
public void Battle(Team opponent) { Fight fight = new Fight(this, opponent); fight.RunFight(); //log.Info("Fitness: " + Fitness); }
private Team Mutate() { Team mutation = new Team(); foreach (Pokemon poke in team) { mutation.team.Add(poke); } mutation.team.RemoveAt(random.Next(SIZE)); while (mutation.team.Count < SIZE) { Pokemon pokemon = pokemonFactories[random.Next(0, pokemonFactories.Count)].Generate(); if (!mutation.team.Contains(pokemon)) { mutation.team.Add(pokemon); } } return mutation; }