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


C# GameState.Undo方法代码示例

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


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

示例1: AlphaBetaSearch

        private int AlphaBetaSearch(GameState s, int alpha, int beta, int deep, ref Position res_turn)
        {
            Position turn = new Position(0, 0);

            if (deep >= maxDepth || s.GameOver)
            {
                return costFunction.EvaluateState(s);
            }
            if (deep % 2 == 0)
            {
                foreach( Position p in turnsGenerator.GenerateTurns(s))
                {
                    GameState.ChangeSet ch = s.Advance(p, Utils.FlipSide(s.Player));
                    int score = AlphaBetaSearch(s, alpha, beta, deep + 1, ref turn) - deep * 20;
                    s.Undo(ch);

                    if (deep == 0)
                    {
                        var hscore = hf.EvaluateTurn(s, p);
                        Debug.WriteLine("Considering ({0},{1}) with ab_cost = {2}, h_cost = {3}", p.X, p.Y, score, hscore);
                    }

                    if (score > alpha)
                    {
                        res_turn = p;
                        alpha = score;
                    }
                    if (alpha >= beta) break;
                }

                return alpha;
            }
            else
            {
                foreach (Position p in turnsGenerator.GenerateTurns(s))
                {
                    GameState.ChangeSet ch = s.Advance(p, Utils.FlipSide(s.Player));
                    int score = AlphaBetaSearch(s, alpha, beta, deep + 1, ref turn) - deep * 20;
                    s.Undo(ch);

                    if (score < beta)
                    {
                        beta = score;
                        res_turn = p;
                    }
                    if (alpha >= beta) break;
                }
                return beta;
            }
        }
开发者ID:peter-popov,项目名称:xomango,代码行数:50,代码来源:MinMax.cs

示例2: checkUndoRedo

        void checkUndoRedo(GameState gs, Position p, Side side)
        {
            string before = gs.ToString();
            GameState.ChangeSet change = gs.Advance(p, side);
            string after = gs.ToString();

            Console.WriteLine("BEFORE:");
            Console.WriteLine(before);

            Console.WriteLine("AFTER:");
            Console.WriteLine(after);

            Confirm.Different(before, after);
            gs.Undo(change);
            Console.WriteLine("UNDO:");
            Console.WriteLine(gs);

            Confirm.Equal(before, gs.ToString());
            gs.Advance(p, side);
            Confirm.Equal(after, gs.ToString());
        }
开发者ID:peter-popov,项目名称:xomango,代码行数:21,代码来源:CoreCZ_StateTest.cs

示例3: MinMaxSearch

        private int MinMaxSearch(GameState s, int deep, ref Position turn)
        {
            int cost = costFunction.EvaluateState(s);
            if (deep == maxDepth || cost <= costFunction.LoseValue || cost >= costFunction.WinValue)
            {
                return cost;
            }
            if (deep % 2 == 0)
            {
                int max = int.MinValue;
                Position sub_turn = new Position(0, 0);
                foreach (Position p in turnsGenerator.GenerateTurns(s))
                {
                    string hash = s.ToString();
                    GameState.ChangeSet ch = s.Advance(p, Utils.FlipSide(s.Player));
                    int score = MinMaxSearch(s, deep + 1, ref sub_turn);
                    s.Undo(ch);
                    Debug.Assert(s.ToString() == hash);
                    if (deep == 0)
                    {
                        Debug.WriteLine(intend(deep) + "max: ({0},{1}) avaluated as {2}\n", p.X, p.Y, score);
                    }
                    if (score > max)
                    {
                        max = score;
                        turn = p;
                    }
                }
                return max;
            }
            else
            {
                int min = int.MaxValue;
                Position sub_turn = new Position(0, 0);
                foreach (Position p in turnsGenerator.GenerateTurns(s))
                {
                    string hash = s.ToString();

                    GameState.ChangeSet ch = s.Advance(p, Utils.FlipSide(s.Player));
                    int score = MinMaxSearch(s, deep + 1, ref sub_turn);

                    //if (deep == 1)
                    //    Debug.WriteLine(intend(deep) + "min: ({0},{1}) avaluated as {2}", p.X, p.Y, score);

                    s.Undo(ch);
                    Debug.Assert(s.ToString() == hash);

                    if (score < min)
                    {
                        min = score;
                        turn = p;
                    }
                }
                return min;
            }
        }
开发者ID:peter-popov,项目名称:xomango,代码行数:56,代码来源:MinMax.cs


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