-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateValue.m
147 lines (147 loc) · 5.04 KB
/
updateValue.m
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
function mapValues = updateValue(mapValues,uniformProbs,actProbs,currentratPos,gamma,reward)
mapSize = size(mapValues);
x = currentratPos(1);
y = currentratPos(2);
if (reward(currentratPos(1),currentratPos(2))==0)
sum2D = 0;
if (x == 1 && y == 1)
for i = [1,4]
for j = [1,4]
if(j == 1)
nextx = x + 1;
nexty = y;
elseif(j == 4)
nextx = x;
nexty = y+1;
end
sum2D = sum2D + actProbs(x,y,i)*uniformProbs(x,y,j)*mapValues(nextx,nexty);
end
end
elseif (x == 1 && y == mapSize(2))
for i = [1,2]
for j = [1,2]
if(j == 1)
nextx = x + 1;
nexty = y;
elseif(j == 2)
nextx = x;
nexty = y-1;
end
sum2D = sum2D + actProbs(x,y,i)*uniformProbs(x,y,j)*mapValues(nextx,nexty);
end
end
elseif (x == 1)
for i = [1,2,4]
for j = [1,2,4]
if(j == 1)
nextx = x + 1;
nexty = y;
elseif(j == 2)
nextx = x;
nexty = y-1;
elseif(j == 4)
nextx = x;
nexty = y+1;
end
sum2D = sum2D + actProbs(x,y,i)*uniformProbs(x,y,j)*mapValues(nextx,nexty);
end
end
elseif (x == mapSize(1) && y == 1)
for i = [3,4]
for j = [3,4]
if(j == 3)
nextx = x-1;
nexty = y;
elseif(j == 4)
nextx = x;
nexty = y+1;
end
sum2D = sum2D + actProbs(x,y,i)*uniformProbs(x,y,j)*mapValues(nextx,nexty);
end
end
elseif(x == mapSize(1) && y == mapSize(2))
for i = [2,3]
for j = [2,3]
if(j == 2)
nextx = x;
nexty = y-1;
elseif(j == 3)
nextx = x-1;
nexty = y;
end
sum2D = sum2D + actProbs(x,y,i)*uniformProbs(x,y,j)*mapValues(nextx,nexty);
end
end
elseif (y == 1)
for i = [1,3,4]
for j = [1,3,4]
if(j == 1)
nextx = x + 1;
nexty = y;
elseif(j == 3)
nextx = x-1;
nexty = y;
elseif(j == 4)
nextx = x;
nexty = y+1;
end
sum2D = sum2D + actProbs(x,y,i)*uniformProbs(x,y,j)*mapValues(nextx,nexty);
end
end
elseif(x == mapSize(1))
for i = [2,3,4]
for j = [2,3,4]
if(j == 2)
nextx = x;
nexty = y-1;
elseif(j == 3)
nextx = x-1;
nexty = y;
elseif(j == 4)
nextx = x;
nexty = y+1;
end
sum2D = sum2D + actProbs(x,y,i)*uniformProbs(x,y,j)*mapValues(nextx,nexty);
end
end
elseif(y == mapSize(2))
for i = [1,2,3]
for j = [1,2,3]
if(j == 1)
nextx = x + 1;
nexty = y;
elseif(j == 2)
nextx = x;
nexty = y-1;
elseif(j == 3)
nextx = x-1;
nexty = y;
end
sum2D = sum2D + actProbs(x,y,i)*uniformProbs(x,y,j)*mapValues(nextx,nexty);
end
end
else
for i = [1,2,3,4]
for j = [1,2,3,4]
if(j == 1)
nextx = x + 1;
nexty = y;
elseif(j == 2)
nextx = x;
nexty = y-1;
elseif(j == 3)
nextx = x-1;
nexty = y;
elseif(j == 4)
nextx = x;
nexty = y+1;
end
sum2D = sum2D + actProbs(x,y,i)*uniformProbs(x,y,j)*mapValues(nextx,nexty);
end
end
end
mapValues(x,y) = reward(x,y)+gamma*sum2D;
else
mapValues(x,y) = reward(x,y);
end
end