⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pathfinderalgorythms.cs

📁 包括Pheromones Algorythm、Memory Algorythm和Hill Climbing Algorythm I
💻 CS
📖 第 1 页 / 共 5 页
字号:
			if( squareDirections == SquareDirectionsSet.BOTTOMLEFT || squareDirections == SquareDirectionsSet.BOTTOMRIGHT
				|| squareDirections == SquareDirectionsSet.TOPBOTTOM || squareDirections == SquareDirectionsSet.ALL 
				&& bottomSquare != null && bottomSquare.SquareType == "TOPBOTTOM" || bottomSquare.SquareType == "FOURWAYS"
				|| bottomSquare.SquareType == "TOPLEFT" || bottomSquare.SquareType == "TOPRIGHT" || bottomSquare.SquareType == "FOOD"
				|| bottomSquare.SquareType == "NEST" )
			{
				bIsBottomAvailable = true;
			}

			/// is the left square available
			if( squareDirections == SquareDirectionsSet.BOTTOMLEFT || squareDirections == SquareDirectionsSet.LEFTRIGHT
				|| squareDirections == SquareDirectionsSet.TOPLEFT || squareDirections == SquareDirectionsSet.ALL
				&& leftSquare != null && leftSquare.SquareType == "LEFTRIGHT" || leftSquare.SquareType == "FOURWAYS" 
				|| leftSquare.SquareType == "BOTTOMRIGHT" || leftSquare.SquareType == "TOPRIGHT" || leftSquare.SquareType == "FOOD" 
				|| leftSquare.SquareType == "NEST" )
			{
				bIsLeftAvailable = true;
			}

			/// now do the ants
			if( critter is Ant )
			{
				Ant currentAnt = ( Ant )critter;
				int nTopPheromone = 0;
				int nRightPheromone = 0;
				int nBottomPheromone = 0;
				int nLeftPheromone = 0;

	///			currentAnt.Log.Clear();

				/// get the pheromone counts
						
				if( bIsTopAvailable == true && topSquare != null )
					nTopPheromone = topSquare.PathFoodPheromone;
				if( bIsRightAvailable == true && rightSquare != null )
					nRightPheromone = rightSquare.PathFoodPheromone;
				if( bIsBottomAvailable == true && bottomSquare != null )
					nBottomPheromone = bottomSquare.PathFoodPheromone;
				if( bIsLeftAvailable == true && leftSquare != null )
					nLeftPheromone = leftSquare.PathFoodPheromone;

				FuzzyDecision topDecision = new FuzzyDecision( "TOP" );
				FuzzyDecision rightDecision = new FuzzyDecision( "RIGHT" );
				FuzzyDecision bottomDecision = new FuzzyDecision( "BOTTOM" );
				FuzzyDecision leftDecision = new FuzzyDecision( "LEFT" );

				/// decide which way you want to move
						
				/// At present there are only the available moves + 
				/// the do not follow strongest pheromone option +
				/// try to avoid occupied squares
						
				/// work out the top decision
						
				if( bIsTopAvailable == true )
				{
					/// validates the decision even if no pheromone
					topDecision.IncrementDecision();
					topDecision.IsValid = true;

					/// should we follow the highest pheromone

					if( currentAnt.DontAlwaysFollowStrongestPheromone == true 
						&& topSquare != null
						&& topSquare.PathFoodPheromone > 0 )
						topDecision.DecrementDecision();

					if( currentAnt.IsReturningHome == false 
						&& topSquare != null 
						&& topSquare.SquareType == "NEST" )
						topDecision.DecrementDecision();
							

				}
						
						
				if( bIsRightAvailable == true )
				{
					rightDecision.IncrementDecision();
					rightDecision.IsValid = true;

					if( currentAnt.DontAlwaysFollowStrongestPheromone == true 
						&& rightSquare != null
						&& rightSquare.PathFoodPheromone > 0 )
						rightDecision.DecrementDecision();

					if( currentAnt.IsReturningHome == false 
						&& rightSquare != null 
						&& rightSquare.SquareType == "NEST" )
						rightDecision.DecrementDecision();

				}


				if( bIsBottomAvailable == true )
				{
					bottomDecision.IncrementDecision();
					bottomDecision.IsValid = true;

					if( currentAnt.DontAlwaysFollowStrongestPheromone == true 
						&& bottomSquare != null
						&& bottomSquare.PathFoodPheromone > 0 )
						bottomDecision.DecrementDecision();

					if( currentAnt.IsReturningHome == false 
						&& bottomSquare != null 
						&& bottomSquare.SquareType == "NEST" )
						bottomDecision.DecrementDecision();


				}

				if( bIsLeftAvailable == true )
				{
					leftDecision.IncrementDecision();
					leftDecision.IsValid = true;

					if( currentAnt.DontAlwaysFollowStrongestPheromone == true 
						&& leftSquare != null
						&& leftSquare.PathFoodPheromone > 0 )
						leftDecision.DecrementDecision();

					if( currentAnt.IsReturningHome == false 
						&& leftSquare != null 
						&& leftSquare.SquareType == "NEST" )
						leftDecision.DecrementDecision();


				}

				/// choose the square
				/// Check that the potential squares are valid and that the decision
				/// for moving there is a valid decision.
						
				FuzzyDecision decision = new FuzzyDecision();

				/// if one is the home square move to it
				if( topSquare != null 
					&& topSquare.SquareType == "NEST" )
					topDecision.IncrementDecision();
				if( rightSquare != null 
					&& rightSquare.SquareType == "NEST" )
					rightDecision.IncrementDecision();
				if( bottomSquare != null 
					&& bottomSquare.SquareType == "NEST" )
					bottomDecision.IncrementDecision();
				if( leftSquare != null 
					&& leftSquare.SquareType == "NEST" )
					leftDecision.IncrementDecision();

				/// if one is the food square move to it
						
				if( currentAnt.IsReturningHome == false )
				{
					if( topSquare != null 
						&& topSquare.SquareType == "FOOD" 
						&& currentAnt.HasFoundFood == false )
						topDecision.IncrementDecision();
					if( rightSquare != null 
						&& rightSquare.SquareType == "FOOD" 
						&& currentAnt.HasFoundFood == false )
						rightDecision.IncrementDecision();
					if( bottomSquare != null 
						&& bottomSquare.SquareType == "FOOD" 
						&& currentAnt.HasFoundFood == false )
						bottomDecision.IncrementDecision();
					if( leftSquare != null 
						&& leftSquare.SquareType == "FOOD" 
						&& currentAnt.HasFoundFood == false )
						leftDecision.IncrementDecision();
				}

				/// if searching moving backwards is undesirable
					
				if( currentAnt.IsReturningHome == false )
				{
					if( directionLastTravelled == DirectionLastTravelledSet.TOP 
						&& bottomDecision.IsValid == true )
						bottomDecision.DecrementDecision();
					else if( directionLastTravelled == DirectionLastTravelledSet.RIGHT 
						&& leftDecision.IsValid == true )
						leftDecision.DecrementDecision();
					else if( directionLastTravelled == DirectionLastTravelledSet.BOTTOM 
						&& topDecision.IsValid == true )
						topDecision.DecrementDecision();
					else if( directionLastTravelled == DirectionLastTravelledSet.LEFT 
						&& rightDecision.IsValid == true )
						rightDecision.DecrementDecision();
					else
					{
					}

					/// improve the chances of moving forwards
					if( directionLastTravelled == DirectionLastTravelledSet.TOP 
						&& topDecision.IsValid == true )
						topDecision.IncrementDecision();
					else if( directionLastTravelled == DirectionLastTravelledSet.RIGHT 
						&& rightDecision.IsValid == true )
						rightDecision.IncrementDecision();
					else if( directionLastTravelled == DirectionLastTravelledSet.BOTTOM 
						&& bottomDecision.IsValid == true )
						bottomDecision.IncrementDecision();
					else if( directionLastTravelled == DirectionLastTravelledSet.LEFT 
						&& leftDecision.IsValid == true )
						leftDecision.IncrementDecision();
					else
					{
					}
				}



				/// try to avoid any squares that are already occupied
					
				if( currentAnt.TryToAvoidOccupiedSquares == true 
					&& currentAnt.IsReturningHome == false )
				{
					if( topSquare != null
						&& topSquare.IsCritterOnSquare == true
						&& topDecision.IsValid == true )
					{
						topDecision.DecrementDecision();
						topDecision.DecrementDecision();
					}
					if( rightSquare != null 
						&& rightSquare.IsCritterOnSquare == true 
						&& rightDecision.IsValid == true )
					{
						rightDecision.DecrementDecision();
						rightDecision.DecrementDecision();
					}
					if( bottomSquare != null
						&& bottomSquare.IsCritterOnSquare == true 
						&& bottomDecision.IsValid == true )
					{
						bottomDecision.DecrementDecision();
						bottomDecision.DecrementDecision();
					}
					if( leftSquare != null 
						&& leftSquare.IsCritterOnSquare == true 
						&& leftDecision.IsValid == true )
					{
						leftDecision.DecrementDecision();
						leftDecision.DecrementDecision();
					}
	
				}

				/// see if we are repeating the same moves over and over
				if( currentAnt.IsRepeatingOnce == true 
					&& currentAnt.IsReturningHome == false
					&& currentSquare.Name != "NEST"  )
				{
					/// see if there is another way to move
		
					switch( currentAnt.GetDirectionTravelledAt( 3 ) )
					{
						case ( int )DirectionLastTravelledSet.NONE: ; break;
						case ( int )DirectionLastTravelledSet.TOP: 
						{
							if( rightDecision.IsValid == true )
								rightDecision.IncrementDecision();
							if( bottomDecision.IsValid == true )
							{
								bottomDecision.IncrementDecision();
							}
							if( leftDecision.IsValid == true )
								leftDecision.IncrementDecision();
						}break;
						case ( int )DirectionLastTravelledSet.RIGHT: 
						{
							if( topDecision.IsValid == true )
								topDecision.IncrementDecision();
							if( bottomDecision.IsValid == true )
								bottomDecision.IncrementDecision();
							if( leftDecision.IsValid == true )
							{
								leftDecision.IncrementDecision();
							}
						}break;
						case ( int )DirectionLastTravelledSet.BOTTOM: 
						{
							if( topDecision.IsValid == true )
							{
								topDecision.IncrementDecision();
							}
							if( rightDecision.IsValid == true )
								rightDecision.IncrementDecision();
							if( leftDecision.IsValid == true )
								leftDecision.IncrementDecision();
						}break;
						case ( int )DirectionLastTravelledSet.LEFT: 
						{
							if( topDecision.IsValid == true )
								topDecision.IncrementDecision();
							if( rightDecision.IsValid == true )
							{
								rightDecision.IncrementDecision();
							}
							if( bottomDecision.IsValid == true )
								bottomDecision.IncrementDecision();
						}break;
						default:; break;
					}
					
									
				}

				/// check for pheromone following
						
				if( currentAnt.IsReturningHome == false 
					&& topSquare != null 
					&& topSquare.SquareType != "NEST"
					&& topSquare.PathFoodPheromone > 0 
					&& topDecision.IsValid == true )
				{
					topDecision.IncrementDecision();
					topDecision.IncrementDecision();
				}
				if( currentAnt.IsReturningHome == false
					&& rightSquare != null 
					&& rightSquare.SquareType != "NEST"
					&& rightSquare.PathFoodPheromone > 0 
					&& rightDecision.IsValid == true )
				{
					rightDecision.IncrementDecision();
					rightDecision.IncrementDecision();
				}
				if( currentAnt.IsReturningHome == false
					&& bottomSquare != null
					&& bottomSquare.SquareType != "NEST"
					&& bottomSquare.PathFoodPheromone > 0 
					&& bottomDecision.IsValid == true )
				{
					bottomDecision.IncrementDecision();
					bottomDecision.IncrementDecision();
				}
				if( currentAnt.IsReturningHome == false
					&& leftSquare != null 
					&& leftSquare.SquareType != "NEST"
					&& leftSquare.PathFoodPheromone > 0 
					&& leftDecision.IsValid == true )
				{
					leftDecision.IncrementDecision();
					leftDecision.IncrementDecision();
				}

				/// if returning home improve chances of moving forwards
				
				if( currentAnt.IsReturningHome == true 
					&& topSquare != null
					&& topSquare.SquareType != "NEST" 
					&& topSquare.PathFoodPheromone == 0 
					&& topDecision.IsValid == true )
				{
					topDecision.IncrementDecision();
				}
				
				if( currentAnt.IsReturningHome == true 
					&& rightSquare != null
					&& rightSquare.SquareType != "NEST"
					&& rightSquare.PathFoodPheromone == 0 
					&& rightDecision.IsValid == true )
				{
					rightDecision.IncrementDecision();
				}

				if( currentAnt.IsReturningHome == true 
					&& bottomSquare != null 
					&& bottomSquare.SquareType != "NEST" 
					&& bottomSquare.PathFoodPheromone == 0 
					&& bottomDecision.IsValid == true )
				{
					bottomDecision.IncrementDecision();
				}

				if( currentAnt.IsReturningHome == true 
					&& leftSquare != null 
					&& leftSquare.SquareType != "NEST"	
					&& leftSquare.PathFoodPheromone == 0 
					&& leftDecision.IsValid == true )
				{
					leftDecision.IncrementDecision();
				}


				/// make the decision
				if( topSquare != null
					&& topDecision.IsValid == true )
				{
					if( rightDecision.IsValid == false )
						decision = topDecision;
					else
						decision = topDecision.Compare( rightDecision );
				}
				if( rightSquare != null
					&& rightDecision.IsValid == true )
				{
					if( decision.IsValid == false )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -