• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Acharis

Provinces structure (irregular, RISK like 2D map)

8 posts in this topic

I'm making a strategy game and the map is made out of irregular areas (provinces), like for example in Europe Universalis or RISK. Since I was always doing traditional 2D grid map I wanted to talk about it so I can grasp the concept more.

 

At the moment I made provinces (areas) as 1D list. Then I added neighbour variables to each province (max 6 neighbours).

Tell me if that's the "correct" way of doing this.

 

 

Simplified code:

class CRegion
{
public:
 int neighbor[6];
} Region[256];

Note:

- the performance is almost irrelevant, the total map is very small and the game is turn based

Edited by Acharis
0

Share this post


Link to post
Share on other sites

That should work fine.  You have an easy way to iterate over every region (just a simple for loop), and you have a way to find the neighbors of a given region.  What other operations might you want to do on your regions?  That might alter your choice in structures.

0

Share this post


Link to post
Share on other sites

This may be way beyond what you are looking to do at the moment, but you might want to look at this article on generating nice-looking irregular maps.  It uses Voronai diagrams, which are pretty complicated (I've been thinking about it and trying to correctly implement Fortune's Algorithm for quite a while now...) but very cool.

1

Share this post


Link to post
Share on other sites

Looks like you've got the basics of an adjacency list there.  I would personally use some form of dynamic container instead of a static array.  Vector would probably be ideal since it should never change once everything is loaded.  And from my perspective it provides a more intuitive/usable interface to your list of neighbors.  eg. say you have 3 neighbors.  How do you know you only have 3 neighbors with a static array.  What data is contained in the other 3 elements of the array?

 

The other option would be an adjacency matrix (you're really conceptually dealing with a graph structure here).  Since you've said your total map is very small, the memory overhead of a matrix should be small.  On the other hand, the main advantage of a matrix over a list is faster lookups of adjacency information and you said performance is almost irrelevant.

 

All that being said, you're probably on the right track already for your purposes.  I'd still just recommend using dynamic containers though.

1

Share this post


Link to post
Share on other sites

An adjacency list/graph would work. What I might recommend you do is store all the adjacency info in a single flat array/vector, end-to-end. Then, in the list of provinces, store a pointer to the first adjacency that corresponds to the province. From that, you have an iterator pair (using the next province's first adjacency as the .end() iterator) that defines all the adjacency of each province (you'll need to add one last "dummy" province for the end, or special-case the last province somehow). This ought to give relatively good performance for both iterative and random access to the information.

 

If memory space were a concern and the number of provinces is relatively low, you could also do some tricks with prime numbers.

0

Share this post


Link to post
Share on other sites

Looks like you've got the basics of an adjacency list there.  I would personally use some form of dynamic container instead of a static array.  Vector would probably be ideal since it should never change once everything is loaded.  And from my perspective it provides a more intuitive/usable interface to your list of neighbors.  eg. say you have 3 neighbors.  How do you know you only have 3 neighbors with a static array.  What data is contained in the other 3 elements of the array?

 

They are storing indices, so one could just stick -1s in there for invalid entries.  (and/or they could keep a count variable)  

 

A vector list could be used (though why, unless regions actually change?), or a dynamic array, but it's probably overkill for a non-issue.  I mean, worst case scenario, where all the regions are in a straight line and only have a left/right neighbor, thats wasting 256 * 4 presumably 32-bit integers, and really, they could be using bytes if they really wanted to save memory, since they have a hardcoded 256 region limit.  So, basically 1MB could be lost, but only in worst case scenarios, and thats really not all that much.

Edited by ferrous
1

Share this post


Link to post
Share on other sites


That should work fine. You have an easy way to iterate over every region (just a simple for loop), and you have a way to find the neighbors of a given region. What other operations might you want to do on your regions? That might alter your choice in structures.
I'm not sure... that's why I ask people who did these things in the past.

 

Most likely I will need:

- the distance from the capital (distance in number of provinces, not hexes)

- pathfinding

 


I would personally use some form of dynamic container instead of a static array. Vector would probably be ideal since it should never change once everything is loaded. And from my perspective it provides a more intuitive/usable interface to your list of neighbors. eg. say you have 3 neighbors. How do you know you only have 3 neighbors with a static array. What data is contained in the other 3 elements of the array?
All empty neighbours variables hold "0" (there will be no province numbered 0). I was thinking that would be the easiest way of implementing it.
0

Share this post


Link to post
Share on other sites

 

Looks like you've got the basics of an adjacency list there.  I would personally use some form of dynamic container instead of a static array.  Vector would probably be ideal since it should never change once everything is loaded.  And from my perspective it provides a more intuitive/usable interface to your list of neighbors.  eg. say you have 3 neighbors.  How do you know you only have 3 neighbors with a static array.  What data is contained in the other 3 elements of the array?

 

They are storing indices, so one could just stick -1s in there for invalid entries.  (and/or they could keep a count variable)  

 

A vector list could be used (though why, unless regions actually change?), or a dynamic array, but it's probably overkill for a non-issue.  I mean, worst case scenario, where all the regions are in a straight line and only have a left/right neighbor, thats wasting 256 * 4 presumably 32-bit integers, and really, they could be using bytes if they really wanted to save memory, since they have a hardcoded 256 region limit.  So, basically 1MB could be lost, but only in worst case scenarios, and thats really not all that much.

 

 

I wasn't even looking at it from a memory usage perspective, but a code readability and maintainability perspective (which are really priority one in my opinion).

 

In the static case, you are iterating over all the elements of the container that are NOT a specific, arbitrary value.

 

In the dynamic case, you are iterating over all the elements of the container.

 

On a side note, I wouldn't even assume that a vector implementation would use less memory, as it's entirely possible that the average capacity of each vector is as large as, or even larger than, the static array.

0

Share this post


Link to post
Share on other sites

 

 

Looks like you've got the basics of an adjacency list there.  I would personally use some form of dynamic container instead of a static array.  Vector would probably be ideal since it should never change once everything is loaded.  And from my perspective it provides a more intuitive/usable interface to your list of neighbors.  eg. say you have 3 neighbors.  How do you know you only have 3 neighbors with a static array.  What data is contained in the other 3 elements of the array?

 

They are storing indices, so one could just stick -1s in there for invalid entries.  (and/or they could keep a count variable)  

 

A vector list could be used (though why, unless regions actually change?), or a dynamic array, but it's probably overkill for a non-issue.  I mean, worst case scenario, where all the regions are in a straight line and only have a left/right neighbor, thats wasting 256 * 4 presumably 32-bit integers, and really, they could be using bytes if they really wanted to save memory, since they have a hardcoded 256 region limit.  So, basically 1MB could be lost, but only in worst case scenarios, and thats really not all that much.

 

 

I wasn't even looking at it from a memory usage perspective, but a code readability and maintainability perspective (which are really priority one in my opinion).

 

In the static case, you are iterating over all the elements of the container that are NOT a specific, arbitrary value.

 

In the dynamic case, you are iterating over all the elements of the container.

 

On a side note, I wouldn't even assume that a vector implementation would use less memory, as it's entirely possible that the average capacity of each vector is as large as, or even larger than, the static array.

 

 

Eh, it's down to personal taste, pretty much.  I personally dislike Vector, only because it's so much messier than the C# equivalent.  =)

 

That said, the vector version wouldn't waste that much memory, assuming the implementor either sets the reserve size or shrinks to fit during the construction of the regions.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0