Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to contain this data?


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
5 replies to this topic

#1 MadHaTr   Members   -  Reputation: 125

Like
0Likes
Like

Posted 24 October 2012 - 06:25 PM

I'm working on a game which will contain routes between different cities. These routes will have a certain pre-defined distance.

example: Cities A, B, C and D

Distance between City A and B is 5
Distance between City A and C is 7
Distance between City A and D is 9
Distance between City B and C is 3
Distance between City B and D is 4
Distance between City C and D is 2

So i obviously need to know which cities are being connected so there names i guess and the distance.


in game the process would work like this. Player clicks on City 'A' then decides which City they want to connect to and clicks that City, we'll say 'C' so the route 'A' to 'C' is added to the player.

Also if 'C' is selected first then 'A' the same route is added to the player 'A' to 'C' and of course the distance is 7.

I'll see what kind of answers I get and if I need to eloborate more I will.

Thanks :)

Sponsor:

#2 VildNinja   Members   -  Reputation: 420

Like
0Likes
Like

Posted 24 October 2012 - 06:42 PM

In a db you would have tables something like this:

CITY:
id,
city_name,
<other params for the city ..>

ROAD:
city_1,
city_2,
distance,
<other params for the road ..>

Then you can easily lookup the connections, and if no direct connection is found, it is quite easy to implement A* or dijkstra if the cities don't have a physical location.

The same structure would also work if you are not using a db. In an object oriented program, you would create lists with all connected roads for each city when loading the data. But you should not save those lists in a file or in a db, as it would create duplicated data, since the information is already in the roads.

#3 greenvertex   Members   -  Reputation: 510

Like
0Likes
Like

Posted 24 October 2012 - 06:44 PM

Some sort of graph (with weighted edges) might be a good choice. Each city is a node that contains a list of edges to other nodes (cities) that give possible routes as well as distance. This could even be a DAG with weighted edges so long as you view all routes uniformly (a route from A to B is the same as the route from B to A).

#4 MadHaTr   Members   -  Reputation: 125

Like
0Likes
Like

Posted 24 October 2012 - 07:00 PM

Thanks for the inputs I have taken a few ideas from both of them. My routes are airways and I've decided that having each city be able to connect to every other city is too much work at this point so I'll create hubs which will connect to the cities in the area and branch to other hubs in other areas.

I'll post for more help if I run into trouble working with these ideas.

Thanks :)

#5 superman3275   Crossbones+   -  Reputation: 1988

Like
0Likes
Like

Posted 24 October 2012 - 07:38 PM

^That's a smart idea. I believe a key feature of game design is being able to take "disadvantages" of certain techniques and make them compliment you're game. That seems to be what you're doing. You've decided that it would be too complicated to have them all be linked, so instead you're taking the Hub idea and making it fit to you're game. Continue on this track, because this game seems to be getting pretty interesting :)!

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#6 Trienco   Crossbones+   -  Reputation: 2057

Like
0Likes
Like

Posted 24 October 2012 - 09:48 PM

Since you didn't mention a language, I can't tell if it helps to bring up maps (or dictionaries in some languages). Boost also has a class for graphs, but if distance is the only thing you need, that might be overkill.

map<City, map<City, int> > distanceTable;

distanceAD = distanceTable[A][D];

f@dzhttp://festini.device-zero.de




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