Advertisement

non-linear event handling

Started by November 23, 2000 05:27 AM
21 comments, last by dwarfsoft 24 years ago
Let me repeat this again. I think you are making this too complex for yourself. A completely general solution (I think) is a simple production system. It works like this:

You have a set of existing conditions.
You have a set of production rules.
A production rule takes on the form:
A B G P
-->
E1 E2 E3

where A and B and G and P are the necessary preconditions. If these preconditions exist, events E1 and E2 and E3 fire. These events create new conditions. Most events will likely erase or modify some existing conditions.

At each time step, all production rules are matched against all existing conditions. The productions which match are fired.

To make the matching process efficient, there should be links between existing conditions and the conditional side of productions.

If you want, you can make existing conditions change value over time based on some function. I''m sure there are all kinds of embellishments you could make.


_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
How about representing the boolean expressions as a DAG (Directed Acyclic Graph, basically a tree, where each node can have multiple parent-nodes).

When a trigger (leaf-value) changes just propagate the change up the DAG until you reach a root or it can be determined that the changed trigger didn''t affect nodes further up the tree, ie. short-circuited evaluation.

eg. in the expression ((x AND y) OR z)
if initially y=false and we then change x then we don''t have to evaluate anything above the AND because it will still evaluate to false and thus the change has no effect on the expression as a whole (unless we also change y)

Also, to make the system more flexible you could implement it with fuzzy logic instead of boolean logic. This would make it a bit more complicated to code though
Advertisement
I understand what you are saying Bishop, but I will still continue with my idea. Unfortunately, the web (seeing as it is no longer a tree) has been half coded. What I have done works and it is DYNAMIC being that you can theoretically have an infinite number of Links coming into a node and an Infinite number of links leaving the node. The node itself is of the form ''GROUP'',''EVENT'' or ''CONDITION'' where ''GROUP'' is just a link to a node. I will post up the code for what I have done once it is more near completion.

Until then, some more coding is for me

What I disagree with though, Bishop, is that you are Evaluating EVERY precondition per timestep... Because not all events have to be updated based on time then this really becomes redundant. If it is based on location then it would be more efficient to update that trigger-event relationship based on everytime that trigger is hit. Why need to update it every 4 seconds in a game when you could just wait for the guy to walk into the building and trip the ''open door'' trigger (causing the event ''show door opening'' or something simple like that ).

AP - I am not sure that I can really do what you are saying, because it is no longer a tree, as it has many nodes entering AND leaving the node. What I have, though, is a state for the "evaluation" of CONDITIONS as well as the "triggered" variable within each NODE. That way, when an EVENT NODE is triggered, it need only check the nodes that lead into it to see if the conditions are met. If they aren''t then there is no need to parse the web, if they do meet conditions then the event is triggered and the triggered state is stored. This can be quite easily handled...

I don''t need to worry about multiple uses of a single event though either, because each node that uses that event links to that event. I can always just group those links within that node, into a GROUP (der) and then do my conditional comparison by ANDING all GROUPS entering that event as a prerequisite. It shouldn''t be too hard to add after the setup that I used.

Additionally - the code is REALLY UGLY, so I do agree with you Bishop. Far to much malloc, memcpy, free work through the whole of the program, but that is what you get for editing dynamically modifyable structures *sigh*. Anyway, once the trees have been created, there is no need for memory reallocation, and the game can use the ''static'' dynamic tree . It is quite a diverse system, and if it works out under its current model, then this oughto be able to be used in almost any game.

Ahhh... Non-linearity.

-Chris Bennett of Dwarfsoft - Site:"The Philosophers'' Stone of Programming Alchemy" - IOL
The future of RPGs - Thanks to all the goblins over in our little Game Design Corner niche
          

This topic is closed to new replies.

Advertisement