当前位置: 首页>>代码示例>>C#>>正文


C# Board.generate方法代码示例

本文整理汇总了C#中Board.generate方法的典型用法代码示例。如果您正苦于以下问题:C# Board.generate方法的具体用法?C# Board.generate怎么用?C# Board.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Board的用法示例。


在下文中一共展示了Board.generate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: generate

 /// <summary>
 /// Generates the next boardstate or returns false if unable
 /// </summary>
 private Board generate(AForge.Genetic.ShortArrayChromosome max, Board b)
 {
     Debug.Assert(b.Turn % 2 == 0);
     int i = b.Turn / 2;
     Move m = b.legalMoves[max.Value[i] % b.legalMoves.Count];
     return b.generate(m);
 }
开发者ID:Zeplar,项目名称:Splendor,代码行数:10,代码来源:IndexFit.cs

示例2: minimax

        public static Move minimax(Board startingPoint, int depth, Heuristic scoringFunction, out double score, Func<Board, bool> endCondition=null)
        {
            bool myTurn = startingPoint.Turn % 2 == 0;  //Indicates that it's Minimax's turn.
            Move bestMove = null;
            List<Move> legalMoves = startingPoint.legalMoves;
            double[] bestScore = new double[legalMoves.Count];
            //int val;
            Func<double, double, bool> comp = (x,y) => (x > y);

            if (depth == 0 || legalMoves.Count == 0 || (endCondition != null && endCondition(startingPoint)))
            {
                //If the root is currently myTurn, then the opponent generated this board; therefore send the negation of the score. Otherwise send the score.
                score = scoringFunction.evaluate(startingPoint) * (myTurn ? -1 : 1);
                return null;
            }

            if (!myTurn)
            {
                //If it's the opponent's turn, they will select for the minimal score.
                for (int i=0; i < bestScore.Length; i++) bestScore[i] = double.MaxValue;
                comp = (x, y) => (x < y);
            }
            else for (int i = 0; i < bestScore.Length; i++) bestScore[i] = double.MinValue;

            Parallel.For(0, legalMoves.Count, (x) =>
               {
               Move m = legalMoves[x];
               minimax(startingPoint.generate(m), depth - 1, scoringFunction, out bestScore[x]);
               });
            //At this point bestscore[x] is the cumulative score of lower branches guaranteed by choosing the xth move.
            bestMove = legalMoves[0];
            //Minimax finds the maximum of these scores, or the opponent finds the minimum of these scores.
            for (int i=1; i < bestScore.Length; i++)
            {
                if (comp(bestScore[i], bestScore[0]))
                {
                    bestScore[0] = bestScore[i];
                    bestMove = legalMoves[i];
                }
            }
            //If it's Minimax's turn, the opponent generated this board; therefore the score is subtracted. Otherwise the score is added.
            score = myTurn ? bestScore[0] - scoringFunction.evaluate(startingPoint) : bestScore[0] + scoringFunction.evaluate(startingPoint);
            if (startingPoint.Equals(Board.current))
            {
                Array scores = bestScore.Set();
                var best = new List<double>(bestScore).FindAll(x => x == bestScore[0]);
                RecordHistory.current.writeToFile("minimax.txt", "Diversity: " + scores.Length + "   " + "BestScores:  " + best.Count + Environment.NewLine);
            }
            return bestMove;
        }
开发者ID:Zeplar,项目名称:Splendor,代码行数:50,代码来源:Minimax.cs

示例3: getGreedyMove

 /// <summary>
 /// Gets the greedy move based on the given function. Ignores Reserves to save computation.
 /// </summary>
 /// <param name="b"></param>
 /// <param name="scoringFunction"></param>
 /// <returns></returns>
 public static Move getGreedyMove(Board b, Heuristic scoringFunction)
 {
     Move bestMove = null;
     double bestScore = int.MinValue;
     foreach (Move m in b.legalMoves)
     {
        //if (m.moveType == Move.Type.RESERVE) continue;
         double temp = scoringFunction.evaluate(b.generate(m));
         if (temp > bestScore)
         {
             bestScore = temp;
             bestMove = m;
         }
     }
     if (bestMove == null)
     {
         throw new Exception("GreedyMove returned a null move.");
     }
     return bestMove;
 }
开发者ID:Zeplar,项目名称:Splendor,代码行数:26,代码来源:Greedy.cs

示例4: generate

 /// <summary>
 /// Generates the next boardstate or returns false if unable
 /// </summary>
 private Board generate(ExactChromosome max, Board b)
 {
     MovesTaken++;
     Debug.Assert(b.Turn % 2 == 0);
     int i = b.Turn / 2;
     if (max.moves.Count <= i)
     {
         max.moves.Add(null);
     }
     if (max.moves[i] == null || !max.moves[i].isLegal(b))
     {
         illegals++;
         max.moves[i] = getExactMove(b);
         if (max.moves[i] == null)
         {
             return null;
         }
     }
     max.boardState[i] = hash(b);
     return b.generate(max.moves[i]);
 }
开发者ID:Zeplar,项目名称:Splendor,代码行数:24,代码来源:ExactFit.cs


注:本文中的Board.generate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。