Exemple #1
0
 public void StartGame()
 {
     Cache.Refresh();
     m_MaxShot           = m_MaxShotFunction?.Invoke() ?? -1;
     m_MaxBalls          = BallSetFactory.GetMaxBallNum(m_GameMetadata.BallSet);
     m_BestScore         = null;
     m_ShotCount         = 1;
     m_BallCount         = null;
     m_PlayingGamesCount = m_Population;
     if (PlayWinner)
     {
         m_Population = 1;
         var bestGame = m_Games.Where(g => g.HasWin).OrderBy(g => g.BestScore).First();
         var brains   = new List <IBrain>();
         for (int i = 0; i < m_GameMetadata.PlayersNum; i++)
         {
             brains.Add(bestGame.GetBrain(i));
         }
         Initialize((pop, play) => brains[play]);
     }
     foreach (var g in m_Games)
     {
         g.RequestShot();
     }
     m_ShotRequestTimeout = null;
 }
Exemple #2
0
 private void Initialize(Func <int, int, IBrain> brainFactory)
 {
     m_Games             = new List <GameManager>();
     m_EvolutionRequests = new Dictionary <GameManager, bool>();
     for (int i = 0; i < m_Population; i++)
     {
         var brains = new List <IBrain>();
         for (int j = 0; j < m_GameMetadata.PlayersNum; j++)
         {
             brains.Add(brainFactory.Invoke(i, j));
         }
         var players     = new Players(brains);
         var ballSet     = BallSetFactory.GetBallSet(m_Table, m_GameMetadata.BallSet);
         var gameManager = new GameManager(m_Game, m_Table, ballSet, players);
         m_EvolutionRequests[gameManager] = false;
         players.EvolutionRequest        += () => HandleEvolutionRequests(gameManager);
         m_Games.Add(gameManager);
         m_Game.InitializeBrains(brains, ballSet);
     }
     m_ValidGames = m_Games;
 }