Jump to content

  • Log In with Google      Sign In   
  • Create Account

Is my design "bad"?


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

#1 bubbaray97   Members   -  Reputation: 217

Like
0Likes
Like

Posted 05 March 2013 - 05:15 PM


 

I think I have a bad design.  


 

I’d appreciate some pointers or directions on how to evolve this design.


 

This game is a port of a hex-based board-game.   It’s a pretty complicated board game (400 pages of rules) with 1000’s of different units, many with LOTs of special case rules.    My code is in C++ and using Allegro as well (although that is pretty hidden in my design, I could swap that out if I wanted too)


 

At a high level I have a class for the game itself which includes the core variables about game state, maps of all the core game elements and pointers to the major core steps.

 

There are classes for each of the core game elements (players, units, fleets, planets, etc.).    As previously mentioned the actual instances of these elements are in their own std::maps in the core game class.

 

For each major phase of the game (economics step, production step, etc…) there is a class which contains all relevant information for that
step (screen initializations, game logic for that step, listeners for input, etc.).    There is a pointer to the instance of each of these in the core game class.


 

From a GUI standpoint, anything that needs to put something on the screen (or for that matter interact with the human player) calls a GUIFactory class, which in turn calls classes for the various screen elements (button,image, dropdown, etc.).   I’ve further broken it out that those classes call a separate library of classes for actually rendering.

 

My class hierarchy is pretty flat for the core elements, although there is quite a bit of inheritance going on the GUI side (some layers are from the library though).


 

Anyway it does work…it’s just I’m barely scratching the surface on the rules/game content that I need to create and its feeling fragile/difficult to maintain already.   And I haven’t even looked at some of things I know I need to tackle like network play or if I wanted to make an AI player.  Maybe I have done it “right” and it’s just a complicated game…but before I get too much further I thought I’d ask the experts.


Clearly this isn’t enough information for you to redesign it for me…because I don’t want you too…I want to do it [learn better that way]…but
some pointers on how I should be thinking about this would be appreciated.    

 

Happy to post code if you need a better explanation.



 



Sponsor:

#2 Scouting Ninja   Members   -  Reputation: 777

Like
0Likes
Like

Posted 06 March 2013 - 05:07 AM

with 1000’s of different units

 

You should rather have a few solid units than a large amount of units that are similar to the others.

 

It’s a pretty complicated board game (400 pages of rules)

 

complicated isn't always better and is inverse to playability.



#3 Krohm   Crossbones+   -  Reputation: 3245

Like
1Likes
Like

Posted 06 March 2013 - 08:02 AM

Clearly this isn’t enough information for you to redesign it for me…because I don’t want you too…I want to do it [learn better that way]…but
some pointers on how I should be thinking about this would be appreciated.

With 400 pages of core rules, thousands of unit types and lots of special cases you're certainly going to spend some effort on this.

I suggest, as a start to separate presentation from model.

I am somewhat confused by the fact you spend a lot of words on the GUI and how to present controls, what about the game itself?

Special rules might be somehow be encoded by using sub-classes I guess.

Can you just tell us the game you're trying to do? Perhaps we can take a look? If not, provide some examples of what those units need to do.

 

As for the GUI itself, I'm afraid you'll have to bite the bullet. I am not well aware of how Allegro works. In Java AWT, I guess I would have to design a specific panel for each unit and provide each unit with a PopControlPanel() call of some sort which would create a popup window.

 

I'm sorry, it's really little information for us to work on. I'm really shooting blind.



#4 bubbaray97   Members   -  Reputation: 217

Like
0Likes
Like

Posted 06 March 2013 - 03:49 PM

I'm sorry, it's really little information for us to work on. I'm really shooting blind.

 

yes sorry some details coming below...

 

You should rather have a few solid units than a large amount of units that are similar to the others.

 

Very true, but in this case I didn't design the game rules...its a boardgame I used to play back in high school and college (oh too many years ago smile.png).     and I don't have to tackle them all at once, just looking to make sure my design would let me get there eventually.   The game was sold as a series of modules which all expand on the core rule  set.    If you were to include all the modules you would get the stats I listed above.   And yes its very complicated totally nerd out kind of game
 
The game is Federation & Empire by a company called ADB (Amarillo Design Bureau  can be found at starfleetgames.com).     To be clear...I'm building this game for myself and I have no legal right to sell, distribute, etc anything related to the board game (and certainly not use the licenses they in turn have with Paramont Pictures).   I've just always liked the game and since I left professional development many years ago, this is my side project that reminds me I still have some idea how to code... I have no plans to ever let anyone else have a copy...but doesn't mean I don't want to do it right.

 

anyway onto details about my design

 

class CoreGame 
{
private:
/* various functions related to the startup of the game itself called by GameInit() below which I've removed to keep this shorter*/
	void ChangeGamePhase(int state, int newState);
	void AdvanceTurn();
	int GameYear;
	std::string GameSeason;
	int PlayerTurn;
	int GameTurn;
	int GameStep;

public:
	CoreGame();
	~CoreGame(void);
	void GameInit();
	void SetNextGamePhase(int &state, int newState);
	int getGameYear() { return GameYear; };
	std::string getGameSeason() { return GameSeason; };
	int getPlayerTurn() { return PlayerTurn;};
	int getGameTurn() { return GameTurn;};
	int getGameStep() { return GameStep;};

//this is my image resource manager class
	ResourceManager<ImageResource> RM_Images;
	
//pointers to the classes for various game states (again removed some to keep this shorter
	ECONSTEP* econstep;
	GAMEMAP *TheMap;
	PRODSTEP* prodstep;

	std::pair<int,int> ActiveObject;
	std::pair<int,int> LastActiveObject;

//all the various game objects
	std::map <std::string,SHIPCLASS> ShipClass;
	std::map<int,RACE> Race;
	std::map<int,PROV> Prov;
	std::map<int,PLANET> Planet;
	std::map<std::string,MAPCELL> MapCell;
	std::map<int,UNIT> Unit;
	std::map<int,FLEET> Fleet;
};

 

Then as an example here is the class for my econstep

 

class ECONSTEP 
{
private:
	std::map<int,ECONHIST> EconHist;   ///this is a object for holding some historical stats
	FlowLayout* flow;    ///the pointer to the root of the screen

	bool surveyStatus;   //various game logic flags
	bool tugStatus;

	void CalculateIncome();       //game logic for this step that happens without user input
	void InitEconStepControls();

protected:

public:
	ECONSTEP(void);
	~ECONSTEP(void);

	void InitEconScreen();     // generates the widgets that need to be on screen and sets up listners for input
	void InitEconStepScreen();
	void ConductSurvey();    //just one of the various logic steps which may happen as a result of user input
};

 

one last example....this is for one of the game objects themselves (a race)

 

class RACE
{
public:
	RACE(void);
	~RACE(void);

	std::string RaceName;
	std::string ShortName;
	int RaceID, iOffMapProvs, iOffMapMinor, iOffMapMajor, iOffMapSB, OrigOffMapProvs;
	int iCredits, iCommandPoints, iSurveyTotal, iSurveyShips;

//logic functions (in this cas related to econ
	int DetermineOnMapProvs();
	int DetermineOnMapMajor();
	int DetermineOnMapMinor();
	int DetermineCapitalMajor();
	int DetermineCapitalMinor();
	int DetermineCapturedProvs();
	int DetermineContestedProvs();

//these should be private, but haven't moved them yet
	std::multimap<int,std::string> ProdQueue;   //hold the allowed production for each turn
	int team,iEconStatus;
	std::map<std::string,int> mothballs;    //holds lilst os reserve units and count

};

I used those examples because they are all related.    But the question was asked about logic, you can see there is some above, but the really gory rules come in the ShipClass class. which I haven't needed to spend a ton of time on yet as the real differences come in how units move and fight and right now I'm building out most of the logisitical related aspects of the game (inital unit placement, econonmy, production, base maintence, that type of thing)



#5 jellyfishchris   Members   -  Reputation: 300

Like
1Likes
Like

Posted 06 March 2013 - 04:07 PM

First question...

Why are you using maps the way you are?

 

 std::map 
<std::string,SHIPCLASS> 
ShipClass;    std::map<int,RACE> 
Race;    std::map<int,PROV> 
Prov;    std::map<int,PLANET> 
Planet;    std::map<std::string,MAPCELL> 
MapCell;    std::map<int,UNIT> 
Unit;    std::map<int,FLEET> 
Fleet;
 

 

You are linking an int to a object for example of type race. Surely this should be a vector instead.

Ok here a few things you should consider before starting to code everything into the same class.

As youve stated there can be many rules etc so you need to think about away that the system will be able to extended apon. Below are a few links of design patterns you should most likely use to help make your job easier. Once you have finished reading all of those and understand them, and maybe implement them. Maybe you should have a better idea on how you want to design your system.

 

 

Good luck!

 

http://en.wikipedia.org/wiki/Strategy_pattern

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

http://en.wikipedia.org/wiki/Factory_method_pattern



#6 bubbaray97   Members   -  Reputation: 217

Like
0Likes
Like

Posted 06 March 2013 - 04:45 PM

Thanks I'll certainly check those links out.   And yes I'm using the factory pattern already for everything related to the GUI.

 

Why are you using maps the way you are?

 

The main reason was for improved random access.     For example there are LOTS of Units in the game.    But the unit is a fairly basic class.   It has stats about that particular unit, but all of its base charateristics (and special rules) are determined by what ShipClass it is.  And there are also lots of those.    The name if you will for a ShipClass is stored as a string (which is the key in its map) so I can quickly lookup the details about a unit's shipclass withouth having to traverse a vector looking for the shipclass which has a given name.    There are similar relationships say from Fleet to Unit, or Prov to MapCell...

 

I might have gone overboard here in that they don't all have to be maps (most of the others are pretty small datasets so traversing a vector probably wouldn't be a big deal performance-wise), but the unit to shipclass relationship is really what drove me down this path



#7 jellyfishchris   Members   -  Reputation: 300

Like
0Likes
Like

Posted 06 March 2013 - 06:50 PM

Ok first of all if you know the name of the ship, you should know which object you are looking for, or have some link to that object in some way. So then you dont need to use a map and just need somewhere to store it aka a vector.

 

Additionally if you go ahead with your idea finding an object in a map is O(log n) where as if you use a hash map for example unsorted_map it is O(1). I still recommend using a vector though for the first reason.






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