// Start is called before the first frame update void Start() { // Init cards CardList.InitCardList(); // Init population int inputSize = 16; int outputSize = CardList.Cards.Count; int hiddenSize = (inputSize + outputSize) / 2; Population = new Population(PopulationSize, inputSize, new int[] { /*hiddenSize*/ }, outputSize); //EvolutionInformation info = Population.EvolveGeneration(7); //SimulationUI.EvoStats.UpdateStatistics(info); SimulationUI.SpeciesScoreboard.UpdateScoreboard(Population); // Generate matches Matches = new List <Match>(); GenerateMatches(); SimulationPhase = SimulationPhase.MatchesReady; MatchesPlayed = 0; // Init statistics ResetStatistics(); // UI SimulationUI.MatchRules.UpdateStatistics(StartHealth, StartCardOptions, MinCardOptions, MaxCardOptions, FatigueDamageStartTurn, MaxMinions, MaxMinionsPerType); }
public void SetPhase(SimulationPhase phase, string winningPlayer, RendererUpdatable winningUpdatable) { Renderer.Renderer.RendererPhase rendererPhase; switch (phase) { case SimulationPhase.Intro: rendererPhase = ProjectMagma.Renderer.Renderer.RendererPhase.Intro; break; case SimulationPhase.Game: rendererPhase = ProjectMagma.Renderer.Renderer.RendererPhase.Game; break; case SimulationPhase.Outro: rendererPhase = ProjectMagma.Renderer.Renderer.RendererPhase.Outro; break; case SimulationPhase.Closed: rendererPhase = ProjectMagma.Renderer.Renderer.RendererPhase.Closed; break; default: throw new System.ArgumentException(string.Format("{0} is not a valid phase", phase)); } this.phase = phase; currentUpdateQueue.AddUpdate(new ProjectMagma.Renderer.Renderer.ChangeToPhaseUpdate(rendererPhase, winningPlayer, winningUpdatable)); }
// Update is called once per frame void Update() { switch (SimulationPhase) { case SimulationPhase.MatchesReady: //Debug.Log("Starting matchround " + Population.Generation + "." + (MatchesPlayed + 1)); SimulationUI.TitleText.text = "Match Round " + Population.Generation + "." + (MatchesPlayed + 1); foreach (Match m in Matches) { if (m.Visual) { SimulationUI.gameObject.SetActive(false); VisualMatch = m; m.StartMatch(VisualPlayer, VisualMinion, VisualBoardHeight, MatchUI); } else { m.StartMatch(); } } SimulationPhase = SimulationPhase.MatchesRunning; break; case SimulationPhase.MatchesRunning: foreach (Match m in Matches) { m.Update(); } if (Matches.TrueForAll(x => x.Phase == MatchPhase.GameEnded)) { MatchesPlayed++; SimulationPhase = SimulationPhase.MatchesFinished; if (VisualMatch != null) { VisualMatch = null; SimulationUI.gameObject.SetActive(true); } } break; case SimulationPhase.MatchesFinished: // Update Stats UpdateStatistics(); if (MatchesPlayed >= MatchesPerGeneration) { // Init Human vs AI game if gen is finished if (SimulationUI.PlayGame.isOn) { SimulationUI.PlayGame.isOn = false; Matches.Clear(); // Create match Match match = new Match(); Player player1 = new HumanPlayer(match); Subject bestSubject = Population.Subjects.OrderByDescending(x => x.Wins).First(); Player player2 = new AIPlayer(match, bestSubject); match.InitGame(player1, player2, StartHealth, StartCardOptions, MinCardOptions, MaxCardOptions, MaxMinions, MaxMinionsPerType, FatigueDamageStartTurn, true, false); // Start match Matches.Add(match); VisualMatch = match; SimulationUI.gameObject.SetActive(false); match.StartMatch(VisualPlayer, VisualMinion, VisualBoardHeight, MatchUI); SimulationPhase = SimulationPhase.MatchesReady; } else { SimulationPhase = SimulationPhase.GenerationFinished; } } else { GenerateMatches(); SimulationPhase = SimulationPhase.MatchesReady; } break; case SimulationPhase.GenerationFinished: // Reset stats ResetStatistics(); MatchesPlayed = 0; // Evolve and Update UI EvolutionInformation info = Population.EvolveGeneration(); SimulationUI.EvoStats.UpdateStatistics(info); SimulationUI.SpeciesScoreboard.UpdateScoreboard(Population); // Generate first match round GenerateMatches(); SimulationPhase = SimulationPhase.MatchesReady; break; } }