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


C# FSM.changeState方法代码示例

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


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

示例1: guardWallsMove

            /*
            private Action guardWallsMove (FSM<BomberAgent> fsm)
            {
                State<BomberAgent> current = fsm.getCurrentState ();

                Action move = null;
                State<BomberAgent> nextState = null;

                if (current is PredictDestinationState) {
                    if (current.fail (this)) {
                        nextState = new BlastWallState (this.gs, false);
                    } else if (current.complete(this)) {
                        nextState = new BombState(this.gs);
                    }
                } else if (current is BlastWallState) {
                    if (current.fail (this) || current.complete (this)) {
                        nextState = new EvadeExplosionState(this.gs);
                    }
                } else if (current is BombState) {
                    if (current.fail (this) || current.complete (this)) {
                        nextState = new EvadeExplosionState(this.gs);
                    }
                } else if (current is EvadeExplosionState) {
                    if (current.fail (this) || current.complete (this)) {
                        nextState = new PredictDestinationState(this.gs, this.isBombPassable);
                    }
                }

                if (nextState != null) {
                    Console.WriteLine ("Agent " + this.agentId + " switching to " + nextState.GetType ().ToString ());
                    fsm.changeState (nextState);
                }
                move = fsm.getCurrentState ().getAction (this);
                Console.WriteLine ("Agent " + this.agentId + ", state " + fsm.getCurrentState ().GetType ().ToString () + ", move " + move);
                return move;
            }
            */
            private Action surroundPlayerFSM(FSM<BomberAgent> fsm)
            {
                State<BomberAgent> current = fsm.getCurrentState();

                Action move = null;
                //check if blowing up stuff and we need to evade bombs!!
                //if (current is BlastWallState) {
                //for (int i = 0; i < this.gs.NumberAIBombermen; i++) {
                Coords botCoords = this.gs.GetAgentCoords(this.agentId + 1);
                bool shouldMove = this.gs.isOnExplosionPath(botCoords);
                if (shouldMove)
                {
                    State<BomberAgent> newState = new EvadeExplosionState(this.gs);
                    Console.WriteLine("Agent " + this.agentId + " switching to EvadeExplosionState");
                    fsm.changeState(newState);
                    move = fsm.getCurrentState().getAction(this);
                    Console.WriteLine("Agent " + this.agentId + ", state " + fsm.getCurrentState().GetType().ToString() + ", move " + move);
                    return move;
                }
                //}
                //}

                if (current.fail(this))
                {
                    Console.WriteLine("Failed strategy " + current.GetType());
                    if (current is SurroundState)
                    {
                        //Chaaarrge!! Blow our way to the player!!!
                        Console.WriteLine("Switching to BlastWallState");
                        BlastWallState newState = new BlastWallState(this.gs, false);
                        fsm.changeState(newState);
                    }
                    else if (current is BombState)
                    {
                        Console.WriteLine("Switching to SurroundState");
                        //this.current = new Surround(this.gs, this.surroundIgnoreBombs);
                        //this.current = new Surround(this.gs, this.isBombPassable);
                        SurroundState newState = new SurroundState(this.gs, this.isBombPassable);
                        fsm.changeState(newState);
                    }
                    else if (current is BlastWallState)
                    {
                        //map fail.... ruh roh
                        Console.WriteLine("AI can't move... map fail");
                        //switch to BombState as last-ditch resort...
                        Console.WriteLine("Switching to BombState");
                        BombState newState = new BombState(this.gs);
                        fsm.changeState(newState);
                    }
                }

                if (current.complete(this))
                {
                    Console.WriteLine("Agent " + this.agentId + " completed strategy " + current.GetType());
                    if (current is SurroundState)
                    {
                        //this.current = new KillPlayer(this.gs);
                        Console.WriteLine("Switching to BombState");
                        BombState newState = new BombState(this.gs);
                        fsm.changeState(newState);
                    }
                    else
                    {
//.........这里部分代码省略.........
开发者ID:vermagav,项目名称:bombersquad,代码行数:101,代码来源:BomberAgent.cs

示例2: blockEscapeMove

            private Action blockEscapeMove(FSM<BomberAgent> fsm)
            {
                State<BomberAgent> current = fsm.getCurrentState();

                Action move = null;
                State<BomberAgent> nextState = null;

                if (current is PursueState)
                {
                    if (current.fail(this))
                    {
                        nextState = new BlastWallState(this.gs, false);
                    }
                    else
                    {

                        //check for four adjacent locations open near player
                        Coords playerCoords = this.gs.GetAgentCoords(0);
                        List<Coords> adj = this.gs.GetAdjacentAccessibleTiles(playerCoords.getTileNum(), this.isBombPassable, false);
                        if (adj.Count == 4)
                        {
                            nextState = new SurroundState(this.gs, this.isBombPassable);
                        }
                        else
                        {
                            Coords choke = this.chokepoints.findChokePoint(this.isBombPassable, this);
                            if (choke != null)
                            {
                                nextState = new CutOffChokePointState(this.gs, this.isBombPassable, choke);
                            }
                        }
                    }
                }
                else if (current is BlastWallState)
                {
                    if (current.fail(this) || current.complete(this))
                    {
                        nextState = new EvadeExplosionState(this.gs);
                    }
                }
                else if (current is CutOffChokePointState)
                {
                    //Coords choke = this.chokepoints.findChokePoint(this.isBombPassable, this);
                    //if ((choke == null) || current.fail(this)) {
                    if (current.fail(this))
                    {
                        nextState = new PursueState(this.gs, this.isBombPassable);
                    }
                    else if (current.complete(this))
                    {
                        nextState = new BombState(this.gs);
                    }
                }
                else if (current is BombState)
                {
                    if (current.fail(this) || current.complete(this))
                    {
                        nextState = new EvadeExplosionState(this.gs);
                    }
                }
                else if (current is EvadeExplosionState)
                {
                    if (current.fail(this) || current.complete(this))
                    {
                        Coords choke = this.chokepoints.findChokePoint(this.isBombPassable, this);
                        if (choke == null)
                        {
                            nextState = new PursueState(this.gs, this.isBombPassable);
                        }
                        else
                        {
                            nextState = new CutOffChokePointState(this.gs, this.isBombPassable, choke);
                        }
                    }
                }
                else if (current is SurroundState)
                {
                    if (current.fail(this))
                    {
                        nextState = new PursueState(this.gs, this.isBombPassable); //move to default state
                    }
                    else if (current.complete(this))
                    {
                        nextState = new BombState(this.gs);
                    }
                }

                if (nextState != null)
                {
                    Console.WriteLine("Agent " + this.agentId + " switching to " + nextState.GetType().ToString());
                    fsm.changeState(nextState);
                }
                move = fsm.getCurrentState().getAction(this);
                Console.WriteLine("Agent " + this.agentId + ", state " + fsm.getCurrentState().GetType().ToString() + ", move " + move);
                return move;
            }
开发者ID:vermagav,项目名称:bombersquad,代码行数:96,代码来源:BomberAgent.cs


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