Skip to content

Commit

Permalink
Fix protected? and add example
Browse files Browse the repository at this point in the history
  • Loading branch information
Maumagnaguagno committed Mar 18, 2016
1 parent 2e6bdd6 commit fa739c8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion examples/experiments/Protection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,24 @@ def unprotect(protection_pos, protection_not)
end

def protected?(effect_add, effect_del)
effect_add.none? {|pre| @state[:protection_not].include?(pre)} and effect_del.none? {|pre| @state[:protection_pos].include?(pre)}
effect_add.any? {|pre| @state[:protection_not].include?(pre)} and effect_del.any? {|pre| @state[:protection_pos].include?(pre)}
end

def apply_protected_operator(precond_pos, precond_not, effect_add, effect_del)
# Apply operator unless interfere with protected
apply_operator(precond_pos, precond_not, effect_add, effect_del) unless protected?(effect_add, effect_del)
end

#-----------------------------------------------
# Main
#-----------------------------------------------
if $0 == __FILE__
@state = {:something => [['a'], ['b']]}
setup_protection
protect([[:something, 'a']], [[:something, 'c']])
p @state
p apply_protected_operator([], [], [[:something, 'c']], [[:something, 'a']])
p @state
p apply_protected_operator([], [], [[:something, 'x']], [[:something, 'b']])
p @state
end

0 comments on commit fa739c8

Please sign in to comment.