I'm currently coding a AI for a risk-like game, but I'm not sure how I put even the base classes together. I've read a lot about game design patterns, entity component designs and such, but I've trouble translating it to an actual architecture of my own.

Original Design

My original layout feels weird, I have too many reference cycles and store most objects in multiple places. I know how to remove those, but that would make it (in my mind) a lot more complicated to get simply lists, for example the amount of Units a player possesses, or which units are in Zones next to the current one.

I had a bit more classes and something that kinda worked, but it was a mess and worse than this design. I wanted to start over and design it right. I feel really dumb having problems that should be much more easier to solve. And I wouldn't even know how to begin plugging in the AI.

  • \$\begingroup\$ So... what is the problem you are having? If you just want to have a discussion about your design, and it's pros or cons, you should try the Game Development Chat since discussion-oriented questions are off-topic here. If there is a specific problem you are having with this design beyond it "feeling" messy, please clarify precisely what the problem is. \$\endgroup\$ – user1430 Nov 18 '14 at 0:30
  • \$\begingroup\$ I'm actually making a risk type game too. While I don't have AI in the game, I just made a database model, then the classes just mimic the same structure. You just have to normalize your database model, then you won't need so many connection like you have in your structure. \$\endgroup\$ – Trader Nov 18 '14 at 10:26

Right off the bat I think your units don't need neighbours.

Zones should hold neighbouring zones but I would likely add a class called a zoneEdge that contains two pointers one for each zone sharing the edge. Each zone would hold a list of edges. Walking the edges would get the neighbouring zones. When it comes to pathfinding this will really help.

Zones should store references to the units in them somehow be ita list or some other structure. For example if each zone has an id and each player has a dictionary where the key is the zone id and the value is a list of units the player owns in that zone you can reasonably get all the units for a player in a zone and move them to other zones without having to mess with sorting and filtering lists of mixed user units.

A game needs access to all these things. One important thing to remember is that experience makes these things clearer. Don't get paralyzed trying to find the best solution before starting. Get in there and see what works. Only you will know the pitfalls your specific game has.


Not the answer you're looking for? Browse other questions tagged or ask your own question.