Пример #1
0
        /// <summary>
        /// Moves this agent in the grid world
        /// </summary>
        /// <param name="grid">The grid world</param>
        /// <param name="direction">The Direction to move towards</param>
        /// <returns>true if the move was successful; false otherwise</returns>
        public bool Move(GridWorld gridWorld, Direction direction)
        {
            // Move in the provided direction if there is no obstacle in that direction
            if (gridWorld.CanMove(direction, rowIndex, columnIndex))
            {
                switch (direction)
                {
                case Direction.UP:
                    rowIndex--;
                    break;

                case Direction.DOWN:
                    rowIndex++;
                    break;

                case Direction.LEFT:
                    columnIndex--;
                    break;

                case Direction.RIGHT:
                    columnIndex++;
                    break;
                }

                UpdatePosition();

                return(true);
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// Moves this agent in the grid world
        /// </summary>
        /// <param name="grid">The grid world</param>
        /// <param name="direction">The Direction to move towards</param>
        /// <returns>true if the move was successful; false otherwise</returns>
        public bool Move(GridWorld gridWorld, Direction direction)
        {
            // Move in the provided direction if there is no obstacle in that direction
            if (gridWorld.CanMove(direction, rowIndex, columnIndex))
            {
                switch (direction)
                {
                    case Direction.UP:
                        rowIndex--;
                        break;
                    case Direction.DOWN:
                        rowIndex++;
                        break;
                    case Direction.LEFT:
                        columnIndex--;
                        break;
                    case Direction.RIGHT:
                        columnIndex++;
                        break;
                }

                UpdatePosition();

                return true;
            }

            return false;
        }