當前位置: 首頁>>代碼示例>>C#>>正文


C# GameState.TakeIfBetter方法代碼示例

本文整理匯總了C#中GameState.TakeIfBetter方法的典型用法代碼示例。如果您正苦於以下問題:C# GameState.TakeIfBetter方法的具體用法?C# GameState.TakeIfBetter怎麽用?C# GameState.TakeIfBetter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在GameState的用法示例。


在下文中一共展示了GameState.TakeIfBetter方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SearchBestMoves

 private GameState SearchBestMoves(IGame game, int depth, int playerIndex)
 {
     if ((game.CurrentUniversityIndex == playerIndex && game.HasWinner())
         || depth == 0)
     {
         return new GameState(Evaluate(game));
     }
     var allMoves = game.GenerateAllMoves();
     if (allMoves.Count() == 1 && playerIndex == game.CurrentUniversityIndex)
     {
         return new GameState(allMoves.First(), Evaluate(game));
     }
     var bestMoves = new GameState(game.NumberOfUniversities, double.MinValue);
     foreach (IPlayerMove move in allMoves)
     {
         if (move is IProbabilityPlayerMove)
         {
             var expectedScores = new GameState(game.NumberOfUniversities, 0);
             double totalProbability = 0.0;
             foreach (var possibleMove in ((IProbabilityPlayerMove) move).AllProbabilityMoves)
             {
                 var thisProbability = possibleMove.Probability.Value;
                 if (thisProbability < 0.06)
                 {
                     continue; // skip 2, 12, 3, 11 for end turn
                 }
                 totalProbability += thisProbability;
                 GameState nextScores = GetNextScores(game, depth, playerIndex, possibleMove);
                 for (int i = 0; i < expectedScores.Scores.Length; ++i)
                 {
                     expectedScores[i] += thisProbability*nextScores[i];
                 }
             }
             for (int i = 0; i < game.NumberOfUniversities; ++i)
             {
                 expectedScores[i] /= totalProbability;
             }
             // trust it with probability
             if (_random.NextDouble() < totalProbability)
             {
                 bestMoves.TakeIfBetter(expectedScores, game.CurrentUniversityIndex, move);
             }
         }
         else //move is BuildCampusMove || move is BuildLinkMove || move is TradingMove)
         {
             GameState nextScores = GetNextScores(game, depth, playerIndex, move);
             bestMoves.TakeIfBetter(nextScores, game.CurrentUniversityIndex, move);
         }
     }
     return bestMoves;
 }
開發者ID:MingStar,項目名稱:SimUniversity,代碼行數:51,代碼來源:ImprovedEMN.cs

示例2: SearchBestMoves

 private GameState SearchBestMoves(IGame game, int depth)
 {
     if (game.HasWinner() || depth == 0)
     {
         return new GameState(Evaluate(game));
     }
     var allMoves = game.GenerateAllMoves();
     if (allMoves.Count() == 1)
     {
         return new GameState(allMoves.First(), Evaluate(game));
     }
     var bestMoves = new GameState(game.NumberOfUniversities, double.MinValue);
     int currentUniversityIndex = game.CurrentUniversityIndex;
     foreach (var move in allMoves)
     {
         if (move is IBuildCampusMove || move is IBuildLinkMove || move is ITradingMove)
         {
             game.ApplyMove(move);
             GameState nextScoredMoves = SearchBestMoves(game, depth - 1);
             game.UndoMove();
             bestMoves.TakeIfBetter(nextScoredMoves, currentUniversityIndex, move);
         }
         else if (move is IProbabilityPlayerMove)
         {
             var expectedScores = new GameState(game.NumberOfUniversities, 0);
             foreach (IProbabilityPlayerMove possibleMove in ((IProbabilityPlayerMove) move).AllProbabilityMoves)
             {
                 game.ApplyMove(possibleMove);
                 GameState nextScores = SearchBestMoves(game, depth - 1);
                 game.UndoMove();
                 for (int i = 0; i < expectedScores.Scores.Length; ++i)
                 {
                     expectedScores[i] += possibleMove.Probability.Value*nextScores[i];
                 }
             }
             bestMoves.TakeIfBetter(expectedScores, currentUniversityIndex, move);
         }
     }
     return bestMoves;
 }
開發者ID:MingStar,項目名稱:SimUniversity,代碼行數:40,代碼來源:ExpectiMaxN.cs


注:本文中的GameState.TakeIfBetter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。