Data Structures and turn based games

I am in the process of designing a turn based computer game based on RISK. At the moment I am not bothered about Game graphics or a GUI. There will be some, but at the moment I want to get the mechanics sorted.

As risk involves:

several players
multiple countires
multiple armies

I am wondering the best way too structure these.

The players I was planning on using a linked list. This way I can create the number of players that are wanted. And when a player is wiped out, they will be removed from memory.

This seems better than creating several classes, some of which will not even be used. However I will need classes for all the moves. Unless I do a map class, which consists of several country classes. I am unsure about this sort of design, only done OOP tutorials so far. Not sure how to best implement classes in a turn based game.

Multiple countries - However I decide to do teh GUIand graphics, each country will have a unique identifier. I am just wondering the best way to store all information about the countries. I am planning a binary tree. As I reckon this will be quicker than searching through an Array to the relevent country. And in my version of RISK. Countries can be destroyed.

Also if I do a Binary Tree per player, it should be super quick to search.

Multiple armies, again I was planning a linked list or binary tree. Not sure on the pro's and cons for this. Was planning army strength and owner for each country but unsure on best implementation.


The only other way I can think of storing all this info is via some sort of database, then running SQL commands but this seems a bit OTT for a game like this.
Don't be so focused on performance initially. Get the mechanics of the game working first. If you have your classes designed well, modifying them later to use a linked list or binary tree should be easy.

How many players are you expecting? A typical game of Risk has just a few (2-6) players. Unless you're planning a massive multiplayer game, a simple array should work nicely. Consider a map<string,Country> for your list of countries. Easy to find a country by name.

And yes, and SQL database for this is OTT unless you're dealing with thousands of players and thousands of countries.
I have actually set up a structure for my territories. I am going to define them in a territories file, so they are easily modifiable. However I just dont see how to link them to a continent. I need 46 territories over 6 continents. Here is what I have:

struct Territory
{
string territoryName;
int owner; // Linked to playerNumber, NULL means noone owns it
int Strength; // Military Strength. Base score dependent on population
int population; // Population of country, higher means more military strength.
};

I am making a couple of chages to RISK, to suit myself. I have realised how much planning I need to do. WHich I plan to do tomorrow(during work). However right now I am really baffled as how to implement Continents.

I need some sort of check that goes

If player controls continent.
{
Boost population.
Give player special action.
}

I have not decided what the special actions are yet. ANd I wont until I have a basic running game mechanic. But I want the feature there so it can be implemented later. I was just going to create an ENUM, and each value grants some bonus or something.
By the way at the minute Im writing this all using functions. I giving myself practice at the basics before turning it all into classes.

Like I said I didnt realise how big a project this would actually be. But sitting inf front of the screen, I am.
Depending on what number of territories a certain continent consists of, you may represent Continent as a class with an array of regions, for example

1
2
3
4
5
6
7
 
class Continent
{
    Territory regions[3]; 
    // Are all regions conquered by some player? 
    bool status; 
}; 


In the example above, the Territory member is an array because the number of regions is fairly small and it is constant for the duration of the game.
So set up a class for each continent. Then perform a check on all the territories to see if they are controlled by the same player. That is actually a good idea.

I already have ann array of territories. Surely with a pointer to the array, I could just check the territories specific to that continent.

Thanks for that.
Topic archived. No new replies allowed.