add examples
This commit is contained in:
parent
8504ba52f6
commit
42757ddc4f
35 changed files with 1104 additions and 609 deletions
4
examples/woods/rules/r_advance_time_lhs.od
Normal file
4
examples/woods/rules/r_advance_time_lhs.od
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
clock:RAM_Clock {
|
||||
RAM_time = `True`;
|
||||
}
|
||||
|
||||
27
examples/woods/rules/r_advance_time_rhs.od
Normal file
27
examples/woods/rules/r_advance_time_rhs.od
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
clock:RAM_Clock {
|
||||
RAM_time = `get_value(this) + 1`;
|
||||
}
|
||||
|
||||
# Advance time has a bunch of side-effects that we cannot easily model using NAC/LHS/RHS-kind of rules,
|
||||
# so we just do it in code:
|
||||
|
||||
:GlobalCondition {
|
||||
condition = ```
|
||||
for _, attacking_link in get_all_instances("attacking"):
|
||||
man_state = get_target(attacking_link)
|
||||
animal_state = get_source(attacking_link)
|
||||
if get_type_name(animal_state) == "BearState":
|
||||
# Bear hunger decreases
|
||||
set_slot_value(animal_state, "hunger", max(get_slot_value(animal_state, "hunger") - 50, 0))
|
||||
set_slot_value(man_state, "dead", True)
|
||||
delete(attacking_link)
|
||||
|
||||
# Bear hunger increases
|
||||
for _, bear_state in get_all_instances("BearState"):
|
||||
if get_slot_value(bear_state, "dead"):
|
||||
continue # bear already dead
|
||||
old_hunger = get_slot_value(bear_state, "hunger")
|
||||
new_hunger = min(old_hunger + 10, 100)
|
||||
set_slot_value(bear_state, "hunger", new_hunger)
|
||||
```;
|
||||
}
|
||||
18
examples/woods/rules/r_attack_lhs.od
Normal file
18
examples/woods/rules/r_attack_lhs.od
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Some man is afraid of some animal:
|
||||
|
||||
man:RAM_Man
|
||||
|
||||
animal:RAM_Animal
|
||||
|
||||
manAfraidOfAnimal:RAM_afraidOf (man -> animal)
|
||||
|
||||
|
||||
# Both man and animal have an associated state:
|
||||
|
||||
manState:RAM_ManState
|
||||
|
||||
man2State:RAM_of (manState -> man)
|
||||
|
||||
animalState:RAM_AnimalState
|
||||
|
||||
animal2State:RAM_of (animalState -> animal)
|
||||
7
examples/woods/rules/r_attack_nac.od
Normal file
7
examples/woods/rules/r_attack_nac.od
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Cannot attack if already attacking
|
||||
|
||||
manState:RAM_ManState
|
||||
|
||||
animalState:RAM_AnimalState
|
||||
|
||||
:RAM_attacking(animalState -> manState)
|
||||
7
examples/woods/rules/r_attack_nac2.od
Normal file
7
examples/woods/rules/r_attack_nac2.od
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Bear won't attack unless hungry
|
||||
|
||||
animalState:RAM_AnimalState {
|
||||
condition = ```
|
||||
get_type_name(this) == "BearState" and get_slot_value(this, "hunger") < 50
|
||||
```;
|
||||
}
|
||||
5
examples/woods/rules/r_attack_nac3.od
Normal file
5
examples/woods/rules/r_attack_nac3.od
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# If dead, cannot be attacked
|
||||
|
||||
manState:RAM_ManState {
|
||||
RAM_dead = `get_value(this)`;
|
||||
}
|
||||
5
examples/woods/rules/r_attack_nac4.od
Normal file
5
examples/woods/rules/r_attack_nac4.od
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# If dead, cannot attack
|
||||
|
||||
animalState:RAM_AnimalState {
|
||||
RAM_dead = `get_value(this)`;
|
||||
}
|
||||
7
examples/woods/rules/r_attack_nac5.od
Normal file
7
examples/woods/rules/r_attack_nac5.od
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Not already attacking someone else:
|
||||
|
||||
animalState:RAM_AnimalState
|
||||
|
||||
other:RAM_ManState
|
||||
|
||||
:RAM_attacking(animalState -> other)
|
||||
7
examples/woods/rules/r_attack_nac6.od
Normal file
7
examples/woods/rules/r_attack_nac6.od
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Not already being attacked by someone else:
|
||||
|
||||
manState:RAM_ManState
|
||||
|
||||
other:RAM_AnimalState
|
||||
|
||||
:RAM_attacking(other -> manState)
|
||||
28
examples/woods/rules/r_attack_rhs.od
Normal file
28
examples/woods/rules/r_attack_rhs.od
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# Our entire LHS (don't delete anything)
|
||||
|
||||
# Some man is afraid of some animal:
|
||||
|
||||
man:RAM_Man
|
||||
|
||||
animal:RAM_Animal
|
||||
|
||||
manAfraidOfAnimal:RAM_afraidOf (man -> animal)
|
||||
|
||||
|
||||
# Both man and animal have an associated state:
|
||||
|
||||
manState:RAM_ManState
|
||||
|
||||
man2State:RAM_of (manState -> man)
|
||||
|
||||
animalState:RAM_AnimalState
|
||||
|
||||
animal2State:RAM_of (animalState -> animal)
|
||||
|
||||
|
||||
|
||||
# Animal attacks man:
|
||||
|
||||
:RAM_attacking(animalState -> manState) {
|
||||
RAM_starttime = `get_slot_value(get_all_instances("Clock")[0][1], "time")`;
|
||||
}
|
||||
8
examples/woods/rules/r_hungry_bear_dies_lhs.od
Normal file
8
examples/woods/rules/r_hungry_bear_dies_lhs.od
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
bearState:RAM_BearState {
|
||||
RAM_hunger = ```
|
||||
get_value(this) == 100
|
||||
```;
|
||||
RAM_dead = ```
|
||||
not get_value(this)
|
||||
```;
|
||||
}
|
||||
4
examples/woods/rules/r_hungry_bear_dies_rhs.od
Normal file
4
examples/woods/rules/r_hungry_bear_dies_rhs.od
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
bearState:RAM_BearState {
|
||||
RAM_hunger = `get_value(this)`; # unchanged
|
||||
RAM_dead = `True`;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue