Jump to content

  • Log In with Google      Sign In   
  • Create Account


Implementation - SFML


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 mypel16000   Members   -  Reputation: 46

Like
-5Likes
Like

Posted 30 January 2013 - 01:08 PM

Hi, even with the lack of help from the members of this forum who answered my first A star question (bringing my reputation down by 200), I have managed to get an A star recipe which was very useful. The thing is that I don't know how to implement it onto my project as it comes with no instructions.

 

Now, I will need someone very good with C++ to show me what functions i should use.

 

The code in the int main() that is shown in the code:

int main( int argc, char *argv[] )
{

	cout << "STL A* Search implementation\n©2001 Justin Heyes-Jones\n";

	// Our sample problem defines the world as a 2d array representing a terrain
	// Each element contains an integer from 0 to 5 which indicates the cost 
	// of travel across the terrain. Zero means the least possible difficulty 
	// in travelling (think ice rink if you can skate) whilst 5 represents the 
	// most difficult. 9 indicates that we cannot pass.

	// Create an instance of the search class...

	AStarSearch<MapSearchNode> astarsearch;

	unsigned int SearchCount = 0;

	const unsigned int NumSearches = 1;

	while(SearchCount < NumSearches)
	{

		// Create a start state
		MapSearchNode nodeStart;
		nodeStart.x = rand()%MAP_WIDTH;
		nodeStart.y = rand()%MAP_HEIGHT; 

		// Define the goal state
		MapSearchNode nodeEnd;
		nodeEnd.x = rand()%MAP_WIDTH;						
		nodeEnd.y = rand()%MAP_HEIGHT; 

		// Set Start and goal states

		astarsearch.SetStartAndGoalStates( nodeStart, nodeEnd );

		unsigned int SearchState;
		unsigned int SearchSteps = 0;

		do
		{
			SearchState = astarsearch.SearchStep();

			SearchSteps++;

	#if DEBUG_LISTS

			cout << "Steps:" << SearchSteps << "\n";

			int len = 0;

			cout << "Open:\n";
			MapSearchNode *p = astarsearch.GetOpenListStart();
			while( p )
			{
				len++;
	#if !DEBUG_LIST_LENGTHS_ONLY			
				((MapSearchNode *)p)->PrintNodeInfo();
	#endif
				p = astarsearch.GetOpenListNext();

			}

			cout << "Open list has " << len << " nodes\n";

			len = 0;

			cout << "Closed:\n";
			p = astarsearch.GetClosedListStart();
			while( p )
			{
				len++;
	#if !DEBUG_LIST_LENGTHS_ONLY			
				p->PrintNodeInfo();
	#endif			
				p = astarsearch.GetClosedListNext();
			}

			cout << "Closed list has " << len << " nodes\n";
	#endif

		}
		while( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_SEARCHING );

		if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_SUCCEEDED )
		{
			cout << "Search found goal state\n";

				MapSearchNode *node = astarsearch.GetSolutionStart();

	#if DISPLAY_SOLUTION
				cout << "Displaying solution\n";
	#endif
				int steps = 0;

				node->PrintNodeInfo();
				for( ;; )
				{
					node = astarsearch.GetSolutionNext();

					if( !node )
					{
						break;
					}

					node->PrintNodeInfo();
					steps ++;

				};

				cout << "Solution steps " << steps << endl;

				// Once you're done with the solution you can free the nodes up
				astarsearch.FreeSolutionNodes();


		}
		else if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_FAILED ) 
		{
			cout << "Search terminated. Did not find goal state\n";

		}

		// Display the number of loops the search went through
		cout << "SearchSteps : " << SearchSteps << "\n";

		SearchCount ++;

		astarsearch.EnsureMemoryFreed();
	}

	return 0;
}

 

 

My game will consist of a vector of zombies which will try and get to the player through a map with obstacles. I know how to create the map, but I need to know how to make this powerful code make my zombies follow the player without going through the obstacles. I would like to know how to initialize the code, what to loop for each zombie in the vector and how to get the player to move node by node to the player. Also, as my player will keep moving, this needs to be updated every second or so.

 

I know this is a tough job, but please, if you are really good with C++ and have experience with A*, help me.

 

Thank you



Sponsor:

#2 BeerNutts   Crossbones+   -  Reputation: 2198

Like
7Likes
Like

Posted 30 January 2013 - 01:24 PM

Hi, even with the lack of help from the members of this forum who answered my first A star question (bringing my reputation down by 200), I have managed to get an A star recipe which was very useful.

 

You don't have the slightest idea how to ask for help do you?  No-one has any responsibility to help you, we all do it because we love game programming, and we want others to be able to enjoy it as well.  

 

Sometimes we have people who come along and they feel it's the GameDev.net community's OBLIGATION to help them; it's not. 

 

I think you need a little humility after some of your responses to people TRYING to help you, but the start of this topic is just going turn anyone off from helping you.


My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#3 JTippetts   Moderators   -  Reputation: 7962

Like
9Likes
Like

Posted 30 January 2013 - 01:26 PM

I think you fail to understand that nobody is under any obligation to help you whatsoever. Every question that gets answered here is done 100% voluntarily. So coming on here with your anger and your passive aggressive little accusations of unhelpfulness is just not the way you should behave if you want answers to another question.

 

Have you heard the saying "Give a man a fish and you'll feed him for a day. Teach a man to fish and you'll feed him for a lifetime."? (I probably butchered the actual quote.) But the sentiment applies here, and is a large part of why you got rated down in your previous thread. There are knowledgeable members on this forum that could easily build your game for you. But they're not going to. They might help you to learn how, but if you demonstrate an unwillingness to learn how then you're going to take some flak for it. Asking for pre-made solutions that you can just plug in is not going to teach you anything; it will just put in the spot you find yourself in at the moment, where you have a pre-made solution but don't have the knowledge to integrate it into your game.

 

A very large part of creating a game is the software engineering aspect of things: or, as you put it, knowing "what functions I should use." And software engineering simply is not teachable through a medium such as forum threads. The members here can give you guidelines and instruction, but the responsibility of putting the pieces together is yours and yours alone. One reason that you can't teach this kind of thing by thread is that it's such a big field, and there are a thousand and one ways to do any given thing, all of which depend strongly on the design and abstraction of your systems. There simply isn't any easy answer to "what functions I should use" because so much depends on the overall structure of your program.

 

Now, in Goblinson Crusoe, the way I handle this is that each unit is given a queue of commands to execute. Goblinson Crusoe is turn-based, and each unit is given a set amount of movement points per turn. When the scheduler indicates that it is a particular unit's turn to move, the unit's AI controller will call a think() method. This think() method will determine the unit's priorities based upon any number of inputs (life levels, nearby targets, relative strength to any given target, class-specific goals such as does an ally need healing and am I a healer, and so forth; it can get complex). If think() indicates that the unit needs to move somewhere, then it will call the pathfinder code with the unit's current location as the start node and the unit's desired destination as the end node. If there exists a path, then once the path is constructed and returned the unit controller think() method will iterate the path and add single-step movement commands to the unit's action queue, then exit.

 

As the unit receives UpdateLogic commands for each round of the unit's turn, the controller will pop an action command off the queue. Is it a movement command? Then it will direct the unit to take a step to the location indicated by the movement command (which is the location given by a node in the path). Is it a spellcast command? Then it will direct the unit to cast a spell. And so forth.

 

As you can see, how I use the pathfinder to move my units is heavily influenced by the overall design of my logic structure, and yours is probably going to be entirely different. That is why there are no easy answers for this kind of question, and that is why you are going to get --rates instead of helpful answers as long as you keep asking for pre-packaged code that you don't have to work for.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS