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


C# IGameState.GetDestination方法代码示例

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


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

示例1: DoTurn

        // DoTurn is run once per turn
        public override void DoTurn(IGameState state)
        {
            // loop through all my ants and try to give them orders
            foreach (Ant ant in state.MyAnts)
            {
                // try all the directions
                foreach (Direction direction in Ants.Aim.Keys)
                {
                    // GetDestination will wrap around the map properly
                    // and give us a new location
                    Location newLoc = state.GetDestination(ant, direction);

                    // GetIsPassable returns true if the location is land
                    if (state.GetIsPassable(newLoc) && !(orders.Contains(newLoc)))
                    {
                        IssueOrder(ant, direction);
                        orders.Add(newLoc);
                        break;
                    }
                }

                // check if we have time left to calculate more orders
                if (state.TimeRemaining < 10) break;
            }
            orders.Clear();
        }
开发者ID:TRdeBie,项目名称:KI_Project1,代码行数:27,代码来源:MyBot.cs

示例2: IssueOrder

 protected void IssueOrder(IGameState state, Ant ant, Direction direction)
 {
     if (direction != Direction.None) {
         //only walk if there's no other ant standing in that location
         if (state.GetIsUnoccupied(state.GetDestination(ant, direction))) {
             ant.WaitTime = 0;
             //tell the gamestate that the ant will be moved next turn
             state.MoveAnt(ant, direction);
             System.Console.Out.WriteLine("o {0} {1} {2}", ant.Row, ant.Col, direction.ToChar());
         }
     }
 }
开发者ID:CPutz,项目名称:KIPracticum1,代码行数:12,代码来源:Bot.cs

示例3: DoTurn

        // DoTurn is run once per turn
        public override void DoTurn(IGameState state)
        {
            #if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("{0}: Starting turn {1}", DateTime.Now.ToLongTimeString(), turnCounter), "TURN");
            #endif

            // loop through all my ants and try to give them orders
            foreach (Ant ant in state.MyAnts)
            {

                // try all the directions
                foreach (Direction direction in Ants.Aim.Keys)
                {

                    // GetDestination will wrap around the map properly
                    // and give us a new location
                    Location newLoc = state.GetDestination(ant, direction);

                    // GetIsPassable returns true if the location is land
                    if (state.GetIsPassable(newLoc))
                    {
                        IssueOrder(ant, direction);
                        // stop now, don't give 1 and multiple orders
                        break;
                    }
                }

                // check if we have time left to calculate more orders
                if (state.TimeRemaining < 10) break;
            }

            #if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("{0}: Ending turn {1}", DateTime.Now.ToLongTimeString(), turnCounter++), "TURN");
            if (true) { } // silly line just to set a breakpoint
            #endif
        }
开发者ID:j-c,项目名称:AntAiChallengeVsSolution,代码行数:37,代码来源:MyBot.cs

示例4: GetNeighbours

 static List<Location> GetNeighbours(Location loc, IGameState state)
 {
     List<Location> neighbours = new List<Location>();
     for (int i = 0; i < 4; i++)
         neighbours.Add(state.GetDestination(loc, (Direction)i));
     return neighbours;
 }
开发者ID:Lapixx,项目名称:CS-UU-KI1,代码行数:7,代码来源:Pathfinding.cs

示例5: DoMoveDirection

        //Handles collision checking and movement tracking
        private bool DoMoveDirection(Location ant, Direction direction, IGameState state)
        {
            // GetDestination will wrap around the map properly
            // and give us a new location
            Location newLoc = state.GetDestination(ant, direction);

            // GetIsPassable returns true if the location is land
            if (state.GetIsPassable(newLoc) && !(orders.Contains(newLoc) && state.GetIsUnoccupied(newLoc)))
            {
                IssueOrder(ant, direction);
                orders.Add(newLoc);
            }
            return false;
        }
开发者ID:TRdeBie,项目名称:KI_Project1,代码行数:15,代码来源:MyBot.cs

示例6: DoTurn

        public override void DoTurn(IGameState state)
        {
            var usedMoves = new HashSet<Location>();

            foreach (Ant ant in state.MyAnts)
            {
                int min = int.MaxValue;
                Location minLoc = ant;

                foreach (var point in state.FoodTiles)
                {
                    int ras = state.GetDistance(point, ant);
                    if (min > ras)
                    {
                        min = ras;
                        minLoc = point;
                    }
                }
                int x1 = ant.Col;
                int y1 = ant.Row;
                int x2 = minLoc.Col;
                int y2 = minLoc.Row;
                int dx = Math.Abs(x1-x2);
                int dy = Math.Abs(y1-y2);
                var direction = Direction.East;
                if (dx > 0)
                {
                    if (dx < state.Width - dx)
                        direction = GetDirectionX(x2 - x1);
                    else
                        direction = GetDirectionX(x1 - x2);
                }
                else if(dy > 0)
                {
                    if (dy < state.Height - dy)
                        direction = GetDirectionY(y2 - y1);
                    else
                        direction = GetDirectionY(y1 - y2);
                }

                Location newLoc = state.GetDestination(ant, direction);
                if (state.GetIsPassable(newLoc) && !usedMoves.Contains(newLoc))
                {
                    usedMoves.Add(newLoc);
                    IssueOrder(ant, direction);
                }
                /*for (int i = 0; i < 4; i++ )
                {
                    var direction = _directions[
                        _random.Next(4)];

                    Location newLoc = state.GetDestination(ant, direction);

                    if (state.GetIsPassable(newLoc) && !usedMoves.Contains(newLoc))
                    {
                        usedMoves.Add(newLoc);
                        IssueOrder(ant, direction);
                        break;
                    }

                }*/

                if (state.TimeRemaining < 10) break;
            }
        }
开发者ID:MichaelEk,项目名称:AIChallengeTraining,代码行数:65,代码来源:MyBot.cs

示例7: DoTurn

        // DoTurn is run once per turn
        public override void DoTurn(IGameState gameState)
        {
            ProcessRewards(gameState);

            // erase old state data since we start a new turn
            this.lastStates = new List<StateAction>[gameState.Width * gameState.Height];

            // loop through all my ants and give them orders
            foreach (Ant ant in gameState.MyAnts) {

                State s = GetState(gameState, ant);
                Action a = this.learn.GetAction(s, this.rho);

                Location newLoc;
                if (a != Action.None) {
                    Direction direction = a.ToDirection();

                    this.IssueOrder(ant, direction);

                    newLoc = gameState.GetDestination(ant, direction);
                } else {
                    newLoc = ant;
                }

                //If the move will be blocked, the new location of the ant
                //is just were the ant is right now.
                if (gameState[newLoc] == Tile.Water) {
                    newLoc = ant;
                }

                ushort newPosition = newLoc.ToUShort(gameState.Width);

                if (lastStates[newPosition] == null)
                    lastStates[newPosition] = new List<StateAction>();

                StateAction sa = new StateAction();
                sa.State = s;
                sa.Action = a;
                this.lastStates[newPosition].Add(sa);

                // check if we have time left to calculate more orders
                if (gameState.TimeRemaining < 10) break;
            }

            this.SaveLastState(gameState);
            this.learn.SaveFile(this.learnFile);
        }
开发者ID:CPutz,项目名称:KIPracticum2,代码行数:48,代码来源:MyBot.cs

示例8: NumOfFoodNextTo

        /// <summary>
        /// Gets the number of food there was next to a certain location in the previous turn.
        /// </summary>
        /// <param name="gameState">The GameState.</param>
        /// <param name="location">The Location to check.</param>
        /// <returns>The number of food next to <paramref name="location"/> in the previous turn.</returns>
        private int NumOfFoodNextTo(IGameState gameState, Location location)
        {
            int res = 0;

            //in every direction, check whether there was food in the previous turn
            foreach (Direction direction in Enum.GetValues(typeof(Direction))) {
                Location checkLocation = gameState.GetDestination(location, direction);

                if (gameState.OldMap[checkLocation.Row, checkLocation.Col] == Tile.Food) {
                    res++;
                }
            }

            return res;
        }
开发者ID:CPutz,项目名称:KIPracticum2,代码行数:21,代码来源:MyBot.cs

示例9: GetState

        /// <summary>
        /// Gets a State object representing the current state.
        /// </summary>
        /// <param name="state">The GameState.</param>
        /// <param name="location">The Location from which to generate a state.</param>
        /// <returns>A State object that repressents the current state given the location.</returns>
        public State GetState(IGameState gameState, Location location)
        {
            QTile[] tiles = new QTile[statePositions.Length];
            for (int i = 0; i < statePositions.Length; ++i) {

                Location loc = gameState.GetDestination(location, statePositions[i]);
                tiles[i] = gameState[loc].ToQTile();
            }

            ushort position = location.ToUShort(gameState.Width);

            return new State(tiles, position);
        }
开发者ID:CPutz,项目名称:KIPracticum2,代码行数:19,代码来源:MyBot.cs

示例10: SearchFood

 // Find nearest food tile in range
 public Location SearchFood(Location loc, IGameState state)
 {
     Location f = loc;
     Direction g = Direction.North;
     for (int i = 1; i <= foodRadius * 2; i++)
     {
         for (int k = 0; k < 2; k++)
         {
             for (int j = 0; j < i; j++)
             {
                 f = state.GetDestination(f, g);
                 if (state[f.Row, f.Col] == Tile.Food && !yummies.Contains(f) && Pathfinding.ReachableWithin(loc, f, state, foodRadius))
                     return f;
             }
             g = DirectionExtensions.Rotate(g, 1);
             if (i == foodRadius * 2)
             {
                 for (int j = 0; j < i; j++)
                 {
                     f = state.GetDestination(f, g);
                     if (state[f.Row, f.Col] == Tile.Food && !yummies.Contains(f) && Pathfinding.ReachableWithin(loc, f, state, foodRadius))
                         return f;
                 }
             }
         }
     }
     return null;
 }
开发者ID:Lapixx,项目名称:CS-UU-KI1,代码行数:29,代码来源:MyBot.cs


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