Jump to content

April 2017 »

S M T W T F S
      1
2345678
9101112131415
16171819202122
23 242526272829
30      
- - - - -

Programming Cause and Effect.


boolean. cause effect subroutine coroutine
4: Adsense

So, it is sunny outside, and that makes you happy, so you go outside to play. But then, it starts raining which makes it rainy, and that causes you to be sad. So, you decide to go to sleep.

I sat down today and thought of a way to program cause and effect. I came up with this notation:
(initCondtion, initState, initBehavior) + Action = (deltaState, deltaCondition,deltaBehavior) = Reaction
The initial condition is that it is sunny outside.
The initial state is that you are happy.
This causes an initial behavior-- you go outside to play.

But then, something happens (an action).

It starts to rain. Now it is rainy outside.
Now you are sad.
This causes you to go back inside and go to sleep.


The action triggers a change in state and a change in condition.
This change in state and condition produces a reaction-- You go inside to go to sleep.

PseudoExample:
--States
normal = true
happy = false
sad = false
 
 
--Conditions
clear = true
rainy= false
sunny = false
 
--Behaviors
 
--Initial Behavior
function GoOutToPlay()
 
--Change in Behavior
function GoToSleep()
 
--Action
function Rain()
start to rain
end
 
--Reaction
function ChangeState()
sad = true
 
function ChangeCondition()
rainy = true
 
function ChangeBehavior()
if sad && rainy
GoToSleep()
 
I wonder if this is solid enough to implement. hmm.

Note: GameDev.net moderates comments.