0

I am struggling to design a board game architecture since I am trying to keep it as generic as possible in order to improve its flexibility to extensions in case of new features, but doing that I'm over-complicating its architecture (maybe it's a case of premature-generalization?)

Just focus on these three elements that are the most important in my design:

  • GameState: represent an abstract state of the game
  • Action: represent an abstract action that a player (or even the GameController) can perform
  • Rule: represent an abstract game rule that validate and perform an Action updating the GameState

The Rule interface could provide the following methods:

  • is_valid (Action, GameState) -> bool: returns true if the provided action is valid on the provided state
  • execute (Action, GameState) -> (List<Action>, GameState): execute the provided action on a state and returns the list of actions (reactions) and new state of game

How I can design these three classes and their collaboration in order to make my code quite scalable end extendible without using fancy tricks or spaghetti code or switch/case? I was thinking to use a mix of state, visitor and strategy pattern, but I cannot find a good way to make it integrate in a nice shape.

Simone
  • 1
  • 4
    "since I am trying to keep it as generic as possible in order to improve its flexibility to extensions in case of new features" Don't do that. You want to simplest architecture which solves your current needs. Don't try to predict the future. – Vincent Savard Aug 21 '21 at 22:28
  • 1
    When you design software, there are tradeoffs where you need to make a choice. Making it as generic as possible vs keeping it simple is one of those tradeoffs: if you try to make it super-generic, it tends to become more abstract and more complicated. You'll have to find a balance for your particular project. Vincent in his comment above hints at the [YAGNI principle](https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it) (You Ain't Gonna Need It) which says: keep it simple, don't add features / complicate the design for possible features that you don't know about yet. – Jesper Aug 24 '21 at 07:49

0 Answers0