Exemplo n.º 1
0
        /// <summary>
        /// This is the default state that is entered into when the agent is started
        /// </summary>
        /// <param name="sender">The object that is calling this method</param>
        /// <param name="e">The arguments that are passed along</param>
        /// <param name="gs">The game state object.</param>
        /// <returns>The direction that we want to head in</returns>
        protected Direction Wander(object sender, EventArgs e, GameState gameState)
        {
            Ghost _ghost       = StateInfo.NearestGhost(gameState);
            Node  _nearestPill = StateInfo.NearestPill(gameState.Pacman.Node, gameState).Target;

            // Make sure that we haven't eaten the last pill before progressing!
            if (_nearestPill != null)
            {
                if (_nearestPill.ManhattenDistance(gameState.Pacman.Node) > EndgameDistanceThreshold)
                {
                    return(ChangeState(FiniteState.EndGame, true, gameState));
                }
            }

            /// FLEE
            if (_ghost != null)
            {
                if (_ghost.Node.ManhattenDistance(gameState.Pacman.Node) < FleeChangeThreshold)
                {
                    return(ChangeState(FiniteState.Flee, true, gameState));
                }
            }

            /// AMBUSH
            foreach (Node item in gameState.Map.PillNodes)
            {
                // Determine that we are looking at a power pill, if so then change to Ambush
                if (item.ManhattenDistance(gameState.Pacman.Node) < AmbushThreshold && item.Type == Node.NodeType.PowerPill)
                {
                    return(ChangeState(FiniteState.Ambush, true, gameState));
                }
            }

            /// WANDER
            if (LucPac.IsJunction(gameState.Pacman.Node.X, gameState.Pacman.Node.Y, gameState))
            {
                Direction _bestDirection    = Direction.None;
                int       _highestPillCount = 0;

                foreach (Direction item in gameState.Pacman.PossibleDirections())
                {
                    // Set the new value if we have found something that is of a higher value.
                    if (LucPac.CountPillsDirection(item, gameState) > _highestPillCount)
                    {
                        _highestPillCount = LucPac.CountPillsDirection(item, gameState);
                        _bestDirection    = item;
                    }
                }

                if (_bestDirection == Direction.None)
                {
                    return(TryGoDirection(gameState.Pacman.Direction, gameState));
                }
                else
                {
                    // Return the best direction to head in based on the pill count
                    return(_bestDirection);
                }
            }
            else
            {
                return(TryGoDirection(gameState.Pacman.Direction, gameState));
            }
        }