-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbotworld_dataScript.sml
More file actions
183 lines (153 loc) · 4.29 KB
/
botworld_dataScript.sml
File metadata and controls
183 lines (153 loc) · 4.29 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
open HolKernel boolLib bossLib lcsymtacs botworld_miscTheory
val _ = new_theory"botworld_data"
val _ = Datatype`
frame = <| color: num; strength: num |>`;
val empty_frame = Define`empty_frame = <| color := 0; strength := 0 |>`;
val _ = Datatype`
cargo = <| cargoType: num; cargoWeight: num |>`;
val _ = Datatype`
item =
Cargo cargo
| ProcessorPart num
| FramePart frame
| RegisterPart (word8 list)
| InspectShield
| DestroyShield`;
val isRegisterPart_def = Define`
(isRegisterPart (RegisterPart _) = T) ∧
(isRegisterPart _ = F)`;
val destRegisterPart_def = Define`
destRegisterPart (RegisterPart ws) = ws`;
val isInspectShield_def = Define`
(isInspectShield InspectShield = T) ∧
(isInspectShield _ = F)`;
val isDestroyShield_def = Define`
(isDestroyShield DestroyShield = T) ∧
(isDestroyShield _ = F)`;
val _ = export_rewrites["isRegisterPart_def","destRegisterPart_def","isInspectShield_def","isDestroyShield_def"];
val weight_def = Define`
weight (Cargo c) = c.cargoWeight ∧
weight (FramePart _) = 100 ∧
weight _ = 1`;
val _ = Parse.type_abbrev("coordinate",``:int # int``);
val _ = Datatype`
name = <|
built_step : num;
built_coord : coordinate;
id : num
|>`;
val _ = Datatype`
command =
Move num
| Lift num
| Drop num
| Inspect name
| Destroy name
| Build (num list) (word8 list list)
| Pass`;
val _ = Datatype`
robot =
<| frame : frame
; processor : num (* ticks per Botworld step *)
; inventory : item list
; command : command
; memory : word8 list list
(* convention:
1st register encodes the policy
remaining registers are storage *)
|>`;
val empty_robot_def = Define`
empty_robot =
<| frame := empty_frame;
processor := 0;
inventory := [];
command := Pass;
memory := []
|>`;
val construct_def = Define`
construct ls m =
case ls of
| (FramePart f::ProcessorPart p::rs) =>
if EVERY isRegisterPart rs ∧
LIST_REL (λp r. LENGTH (destRegisterPart p) = LENGTH r)
rs m then
SOME <| frame := f; processor := p; memory := m;
command := Pass; inventory := [] |>
else NONE
| _ => NONE`;
val shatter_def = Define`
shatter r =
FramePart r.frame::
ProcessorPart r.processor::
MAP (RegisterPart o MAP (K 0w)) r.memory`;
val canLift_def = Define`
canLift r i ⇔
SUM (MAP weight (i::r.inventory)) ≤ r.frame.strength`;
val _ = Datatype`
action =
Passed
| MoveBlocked num
| MovedOut num
| MovedIn num
| CannotLift num
| GrappledOver num
| Lifted num
| Dropped num
| InspectTargetFled name
| InspectBlocked name
| Inspected name robot
| DestroyTargetFled name
| DestroyBlocked name
| Destroyed name
| BuildInterrupted (num list)
| Built (num list) robot
| Invalid`;
val isMovedOut_def = Define`
(isMovedOut (MovedOut _) ⇔ T) ∧
(isMovedOut _ ⇔ F)`;
val _ = export_rewrites["isMovedOut_def"];
val isMovedIn_def = Define`
(isMovedIn (MovedIn _) ⇔ T) ∧
(isMovedIn _ ⇔ F)`;
val _ = export_rewrites["isMovedIn_def"];
val isBuilt_def = Define`
(isBuilt (Built _ _) ⇔ T) ∧
(isBuilt _ ⇔ F)`;
val _ = export_rewrites["isBuilt_def"];
val destBuilt_def = Define`
destBuilt (Built is r) = (is,r)`;
val _ = export_rewrites["destBuilt_def"];
val isDropped_def = Define`
(isDropped (Dropped _) ⇔ T) ∧
(isDropped _ ⇔ F)`;
val _ = export_rewrites["isDropped_def"];
val destDropped_def = Define`
destDropped (Dropped i) = i`;
val _ = export_rewrites["destDropped_def"];
val _ = Datatype`
itemCache =
<| components: item list
; possessions: item list
|>`;
val _ = Datatype`
event = <|
robotActions : (name, robot # action) alist
; createdRobots : robot list
; untouchedItems: item list
; droppedItems : item list
; fallenItems : itemCache list|>`;
val _ = Datatype`
privateData = pInvalid | pNothing | pInspected num (word8 list list)`;
val _ = Datatype`
observation = <|
name : name
; event : event
; private : privateData
|>`;
val _ = Datatype`
square = <| robots: (name,robot) alist; items: item list |>`;
val _ = Parse.type_abbrev("grid",``:coordinate |-> square``)
val _ = Datatype`
state = <| grid : grid; time_step : num |>`;
val _ = Datatype`level = MP | Trust num`;
val _ = export_theory()