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


C# GameState.Advance方法代码示例

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


在下文中一共展示了GameState.Advance方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: test_2x2_final

        static void test_2x2_final()
        {
            GameState gs = new GameState();
            MinMax m = new MinMax(new SimpleCostFuntcion(Side.Zero), new HeuristicTrunsGenerator(new LineBasedTurnHeuristics()), 2);

            gs.Advance(new Position(3, 3), Side.Cross);
                gs.Advance(new Position(4, 3), Side.Zero);
            gs.Advance(new Position(4, 4), Side.Cross);
                gs.Advance(new Position(3, 4), Side.Zero);
            gs.Advance(new Position(6, 6), Side.Cross);
                gs.Advance(new Position(2, 5), Side.Zero);
            gs.Advance(new Position(7, 7), Side.Cross);

            Position p = m.FindTurn(gs);
            Console.WriteLine("Turn found {0},{1}", p.X, p.Y);
        }
开发者ID:peter-popov,项目名称:xomango,代码行数:16,代码来源:Program.cs

示例3: State_DeriveStateAddsOneTurn

        public void State_DeriveStateAddsOneTurn()
        {
            //Test case:
            // | |.|.|.|
            // |.|.|o|.|
            // |.|x|.|.| --> initia pos(3,5)
            // |.|.|.| |
            // | | | | |

            GameState gs = new GameState();
            Position pos = new Position(3, 5);
            gs.Advance(pos, Side.Cross);
            Position turnPos = new Position(4, 4);
            gs.Advance(turnPos, Side.Zero);

            //Confirm.Equal(Side.Cross, gs.Player);
            Confirm.Equal(14, gs.Count<Position>());
            Confirm.Equal(Side.Cross, gs[pos].Side);
            Confirm.Equal(Side.Zero, gs[turnPos].Side);
        }
开发者ID:peter-popov,项目名称:xomango,代码行数:20,代码来源:CoreCZ_StateTest.cs

示例4: Play

        public GameState Play()
        {
            GameState gs = new GameState();

            var side = Side.Cross;
            foreach(var t in turns)
            {
                gs.Advance(t, side);
                side = Utils.FlipSide(side);
            }

            return gs;
        }
开发者ID:peter-popov,项目名称:xomango,代码行数:13,代码来源:Scenario.cs

示例5: HeuristicTurnsGenerator_GenerateFromTrivialState

        public void HeuristicTurnsGenerator_GenerateFromTrivialState()
        {
            Position pos = new Position(3, 5);
            GameState initialState = new GameState();
            initialState.Advance(pos, Side.Cross);

            HeuristicTrunsGenerator gen = new HeuristicTrunsGenerator(new LineBasedTurnHeuristics());

            int i = 0;
            foreach (Position p in gen.GenerateTurns(initialState))
            {
                ++i;
            }

            Confirm.IsTrue(i > 0);
        }
开发者ID:peter-popov,项目名称:xomango,代码行数:16,代码来源:CoreCZ_HeuristicTurnsGeneratorTest.cs

示例6: State_DeriveStateUpdatesAlongTheLine

        public void State_DeriveStateUpdatesAlongTheLine()
        {
            //Test case:
            // | | |o| |
            // | |x|o| | --> initia pos(3,3)
            // | | |x| |
            // | | | |x|

            Position pos0 = new Position(3, 3);
            Position pos1 = new Position(4, 4);
            Position pos2 = new Position(4, 2);
            Position pos3 = new Position(3, 2);
            Position pos4 = new Position(5, 1);

            // Create states
            GameState gs = new GameState();
            gs.Advance(pos0, Side.Cross);
            gs.Advance(pos1, Side.Zero);
            gs.Advance(pos2, Side.Cross);
            gs.Advance(pos3, Side.Zero);
            gs.Advance(pos4, Side.Cross);

            //(6,0)
            {
                PositionInfo info = gs[new Position(6, 0)];
                Confirm.IsNotNull(info);
                PositionInfo.LineInfo up = info[PositionInfo.Orientation.DiagonalNW, PositionInfo.Direction.Negative];
                Confirm.Equal(Side.Cross, up.side);
                Confirm.Equal(3, (int)up.amount);
                Confirm.Equal(true, up.open);
            }

            //(2,4)
            {
                PositionInfo info = gs[new Position(2, 4)];
                Confirm.IsNotNull(info);
                PositionInfo.LineInfo up = info[PositionInfo.Orientation.DiagonalNW, PositionInfo.Direction.Positive];
                Confirm.Equal(Side.Cross, up.side);
                Confirm.Equal(3, (int)up.amount);
                Confirm.Equal(true, up.open);
            }
        }
开发者ID:peter-popov,项目名称:xomango,代码行数:42,代码来源:CoreCZ_StateTest.cs

示例7: 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

示例8: State_InitialStateTest

        public void State_InitialStateTest()
        {
            GameState gs = new GameState();

            Position pos = new Position(3,5);

            gs.Advance(pos, Side.Cross);

            Confirm.Equal(9, gs.Count<Position>());
            Confirm.Equal(Side.Cross, gs[pos].Side);
        }
开发者ID:peter-popov,项目名称:xomango,代码行数:11,代码来源:CoreCZ_StateTest.cs

示例9: State_InitialStateHasCorrectPositionInfo

        public void State_InitialStateHasCorrectPositionInfo()
        {
            GameState gs = new GameState();
            //empty state
            Position pos0 = new Position(4, 5);
            gs.Advance(pos0, Side.Cross);

            //
            foreach (PositionInfo.Orientation o in PositionInfo.Orientations)
            {
                foreach (PositionInfo.Direction d in PositionInfo.Directions)
                {
                    Position p = pos0 + PositionInfo.GetDirectionVector(o, d);
                    Confirm.IsNotNull(gs[p]);
                    Confirm.Equal(gs[p].Side, Side.Nobody);

                    PositionInfo info = gs[p];
                    //Check that line is dectected in the direction to pos0
                    //and that all others direction are empty
                    foreach (PositionInfo.Orientation o1 in PositionInfo.Orientations)
                    {
                        foreach (PositionInfo.Direction d1 in PositionInfo.Directions)
                        {
                            PositionInfo.LineInfo l = info[o1, d1];

                            if (o1 == o && d1 != d)
                            {
                                Confirm.Equal(Side.Cross, l.side);
                                Confirm.Equal(1, (int)l.amount);
                                Confirm.Equal(true, l.open);
                            }
                            else
                            {
                                Confirm.Equal(0, (int)l.amount);
                            }
                        }
                    }
                }
            }
        }
开发者ID:peter-popov,项目名称:xomango,代码行数:40,代码来源:CoreCZ_StateTest.cs

示例10: State_DeriveState_OpenFlag

        public void State_DeriveState_OpenFlag()
        {
            //Test case:
            // | | |o|
            // | |x| | --> initial pos(3,3)
            // | | | |

            GameState gs = new GameState();

            Position pos0 = new Position(3, 3);
            Position pos1 = new Position(4, 4);

            gs.Advance(pos0, Side.Cross);
            gs.Advance(pos1, Side.Zero);

            //Sanity:
            Confirm.Equal(Side.Cross, gs[pos0].Side);
            Confirm.Equal(Side.Zero, gs[pos1].Side);

            // (2, 2)
            {
                PositionInfo info = gs[new Position(2, 2)];
                Confirm.IsNotNull(info);
                PositionInfo.LineInfo l = info[PositionInfo.Orientation.DigonalSW, PositionInfo.Direction.Positive];
                Confirm.Equal(Side.Cross, l.side);
                Confirm.Equal(1, (int)l.amount);
                Confirm.Equal(false, l.open);
            }
            // (5, 5)
            {
                PositionInfo info = gs[new Position(5, 5)];
                Confirm.IsNotNull(info);
                PositionInfo.LineInfo l = info[PositionInfo.Orientation.DigonalSW, PositionInfo.Direction.Negative];
                Confirm.Equal(Side.Zero, l.side);
                Confirm.Equal(1, (int)l.amount);
                Confirm.Equal(false, l.open);
            }
        }
开发者ID:peter-popov,项目名称:xomango,代码行数:38,代码来源:CoreCZ_StateTest.cs

示例11: State_DeriveStateUpdatesPositionInformation

        public void State_DeriveStateUpdatesPositionInformation()
        {
            //Test case:
            // | | |o|
            // | |x| | --> initia pos(3,3)
            // | | |x|
            GameState gs = new GameState();
            Position pos0 = new Position(3, 3);
            Position pos1 = new Position(4, 4);
            Position pos2 = new Position(4, 2);
            // Create states
            gs.Advance(pos0, Side.Cross);
            gs.Advance(pos1, Side.Zero);
            gs.Advance(pos2, Side.Cross);
            // (4, 3)
            {
                PositionInfo info = gs[new Position(4, 3)];
                Confirm.IsNotNull(info);
                PositionInfo.LineInfo up = info[PositionInfo.Orientation.Vertical, PositionInfo.Direction.Positive];
                Confirm.Equal(Side.Zero, up.side);
                Confirm.Equal(1, (int)up.amount);
                Confirm.Equal(true, up.open);

                PositionInfo.LineInfo left = info[PositionInfo.Orientation.Horizontal, PositionInfo.Direction.Negative];
                Confirm.Equal(Side.Cross, left.side);
                Confirm.Equal(1, (int)left.amount);
                Confirm.Equal(true, left.open);

                PositionInfo.LineInfo down = info[PositionInfo.Orientation.Vertical, PositionInfo.Direction.Negative];
                Confirm.Equal(Side.Cross, down.side);
                Confirm.Equal(1, (int)down.amount);
                Confirm.Equal(true, down.open);
            }

            // (2,2)
            {
                PositionInfo info = gs[new Position(2, 2)];
                Confirm.IsNotNull(info);
                PositionInfo.LineInfo up = info[PositionInfo.Orientation.DigonalSW, PositionInfo.Direction.Positive];
                Confirm.Equal(Side.Cross, up.side);
                Confirm.Equal(1, (int)up.amount);
                Confirm.Equal(false, up.open);
            }
            // (2,4)
            {
                PositionInfo info = gs[new Position(2, 4)];
                Confirm.IsNotNull(info);
                PositionInfo.LineInfo up = info[PositionInfo.Orientation.DiagonalNW, PositionInfo.Direction.Positive];
                Confirm.Equal(Side.Cross, up.side);
                Confirm.Equal(2, (int)up.amount);
                Confirm.Equal(true, up.open);
            }
            // (5,1)
            {
                PositionInfo info = gs[new Position(5, 1)];
                Confirm.IsNotNull(info);
                PositionInfo.LineInfo up = info[PositionInfo.Orientation.DiagonalNW, PositionInfo.Direction.Negative];
                Confirm.Equal(Side.Cross, up.side);
                Confirm.Equal(2, (int)up.amount);
                Confirm.Equal(true, up.open);
            }
        }
开发者ID:peter-popov,项目名称:xomango,代码行数:62,代码来源:CoreCZ_StateTest.cs

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