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 stateexecute (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.