-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCookie.rb
108 lines (97 loc) · 2.2 KB
/
Cookie.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require_relative '../../Hypertension_U'
module Cookie
include Hypertension_U
extend self
#-----------------------------------------------
# Domain
#-----------------------------------------------
@domain = {
# Operators
'goto' => 1,
'buy_cookie' => {
'buy_good_cookie' => 0.8,
'buy_bad_cookie' => 0.2
},
# Methods
'get_cookie' => [
'goto_and_buy_cookie'
]
}
#-----------------------------------------------
# State valuation
#-----------------------------------------------
def state_valuation(old_state)
previous_have = old_state[HAVE]
current_have = @state[HAVE]
bob__good_cookie = ['bob','good_cookie']
bob__bad_cookie = ['bob','bad_cookie']
value = 0
value += 10 if not previous_have.include?(bob__good_cookie) and current_have.include?(bob__good_cookie)
value -= 10 if not previous_have.include?(bob__bad_cookie) and current_have.include?(bob__bad_cookie)
value
end
#-----------------------------------------------
# Operators
#-----------------------------------------------
def goto(agent, from, to)
apply_operator(
# Positive preconditions
[
[AT, agent, from]
],
# Negative preconditions
[
[AT, agent, to]
],
# Add effects
[
[AT, agent, to]
],
# Del effects
[
[AT, agent, from]
]
)
end
def buy_good_cookie(agent)
apply_operator(
# Positive preconditions
[
[AT, agent, 'cookie_store']
],
# Negative preconditions
[],
# Add effects
[
[HAVE, agent, 'good_cookie']
],
# Del effects
[]
)
end
def buy_bad_cookie(agent)
apply_operator(
# Positive preconditions
[
[AT, agent, 'cookie_store']
],
# Negative preconditions
[],
# Add effects
[
[HAVE, agent, 'bad_cookie']
],
# Del effects
[]
)
end
#-----------------------------------------------
# Methods
#-----------------------------------------------
def goto_and_buy_cookie(agent, from, to)
yield [
['goto', agent, from, to],
['buy_cookie', agent]
]
end
end