What is the best way to organize the rule component of a Django system?

I design (and end up writing) a system in Django, which consists of two main components:

  • Game manager: this is essentially a data entry element. Reliable (non-public) users will enter information about the game system, for example, parameters that players may have. The interface for this is just the Django admin console, and it does nothing but store information.
  • Character Manager: This is the consumer of the above data. Public users will create characters in the role systems defined above by pulling on the parameters entered by these trusted users. This is a standalone application in the project from the point of view of Django.

There is one part that I don’t know where to put, and these are the β€œrules” that are associated with each game. In fact, for each game placed in the first application, there is a set of preconditions, restrictions and other business logic specific to this game. (There is also a similarly structured logic that will be common to all games.) The logic will be encoded in Python, not entered by the user.

This logic is used in the process of checking a specific character, but is associated with a specific game and must be dynamically changed. Is this a standalone application or should it be attached to the forms of the Character Manager? Or could it be?

This is the first Django application that I built from scratch (instead of chewing on someone else's code), and I'm new to the Python philosophy to download, so I'm all ears for that.

Thanks in advance.

+4
source share
2 answers

I would create a subdirectory with named rules in the application with the game logic and create a module named after each game that you would like to serve. Then create a common interface for these modules that your games will use and import the correct rules module by name (if your game is called adom and then just __import__('rules.adom') inside the main game engine and will call special game methods).

If your games do not create their own models and representations, then, apparently, there is no reason to create a specific application for each of them. This is a sensitive issue because the code used is based on data stored in a database. Didn't you think about saving additional game scripts inside the database and then exec them? This seems more natural: the game is a data set and additional scripts associated with this game.

+1
source

"rules" that are associated with each game.

for each game placed in the first application, there is a set of preconditions, restrictions and other business logic specific to this game.

This part of the game application, then.

There is also a similarly-structured logic that will be common to all games.

This part of the game application, then.

This logic is used in the process of checking a specific character, but is associated with a specific game.

Right. Then this part of the game application. Characters are associated with one or more games.

Should I check for binding to character manager forms?

Character forms may have game-specific data cleansing rules.

+1
source

All Articles