What is an appropriate data structure and database schema to store logic rules?

前端 未结 3 1395
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 13:56

Preface: I don\'t have experience with rules engines, building rules, modeling rules, implementing data structures for rules, or whatnot. Therefore, I don\'t know what I\'m doin

3条回答
  •  旧时难觅i
    2021-02-05 14:19

    It seems like your problem breaks down to testing whether a particular condition has been satisfied.

    You will have compound conditions. So given a table of items:

    ID_Item    Description
    ----------------------
    1          A         
    2          B         
    3          C         
    4          F         
    

    and given a table of possible actions:

    ID_Action  VerbID  ItemID    ConditionID
    ----------------------------------------
    1          BUY     4         1
    

    We construct a table of conditions:

    ID_Condition  VerbA  ObjectA_ID  Boolean  VerbB            ObjectB_ID
    ---------------------------------------------------------------------
    1             OWNS   1           OR       MEETS_CONDITION  2
    2             OWNS   2           AND      OWNS             3
    

    So OWNS means the id is a key to the Items table, and MEETS_CONDITION means that the id is a key to the Conditions table.

    This isn't meant to restrict you. You can add other tables with quests or whatever, and add extra verbs to tell you where to look. Or, just put quests into your Items table when you complete them, and then interpret a completed quest as owning a particular badge. Then you can handle both items and quests with the same code.

提交回复
热议问题