-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSorryGameFacts.krf
384 lines (323 loc) · 12 KB
/
SorryGameFacts.krf
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
(in-microtheory SorryFactsMt)
(genlMt SorryGameMt SorryFactsMt)
(isa BoardPieces SecondOrderCollection)
(isa SorryAgents FirstOrderCollection)
(isa SorryColors FirstOrderCollection)
;;; define pieces
;;;
;;; red
;;; 2/23: still think we need to define "RedPieces" first?
(isa RedPieces FirstOrderCollection)
(isa RedPieces BoardPieces)
(isa Red1 RedPieces)
(isa Red2 RedPieces)
(isa Red3 RedPieces)
(isa Red4 RedPieces)
(isa red SorryColors)
(colorOfPiece Red1 red)
(colorOfPiece Red2 red)
(colorOfPiece Red3 red)
(colorOfPiece Red4 red)
(isa RedAgent SorryAgents)
(colorOfAgent RedAgent red)
;;; USE: check if landing on space that has piece of same or different color
;;; if same ==> cannot make move
;;; if different ==> knock other piece back to start
;;; yellow
;;; 2/23: still think we need to define "YellowPieces" first?
(isa YellowPieces FirstOrderCollection)
(isa YellowPieces BoardPieces)
(isa Yellow1 YellowPieces)
(isa Yellow2 YellowPieces)
(isa Yellow3 YellowPieces)
(isa Yellow4 YellowPieces)
(isa yellow SorryColors)
(colorOfPiece Yellow1 yellow)
(colorOfPiece Yellow2 yellow)
(colorOfPiece Yellow3 yellow)
(colorOfPiece Yellow4 yellow)
(isa YellowAgent SorryAgents)
(colorOfAgent YellowAgent yellow)
;;; cards
;;; added 2/23 below:
(isa Sorry-Cards FirstOrderCollection)
(isa Sorry-Cards-Pickable FirstOrderCollection)
(genls Sorry-Cards PlayingCard)
(genls Sorry-Cards-Pickable PlayingCard)
;;; ended adding below...
(isa Sorry-One Sorry-Cards)
(isa Sorry-One Sorry-Cards-Pickable)
(isa Sorry-Two Sorry-Cards)
(isa Sorry-Two Sorry-Cards-Pickable)
(isa Sorry-Three Sorry-Cards)
(isa Sorry-Three Sorry-Cards-Pickable)
(isa Sorry-Four Sorry-Cards)
(isa Sorry-Four Sorry-Cards-Pickable)
(isa Sorry-Five Sorry-Cards)
(isa Sorry-Five Sorry-Cards-Pickable)
(isa Sorry-Seven Sorry-Cards)
(isa Sorry-Seven Sorry-Cards-Pickable)
;;; subset:
(isa Sorry-Seven-Six Sorry-Cards)
(isa Sorry-Seven-Five Sorry-Cards)
(isa Sorry-Seven-Four Sorry-Cards)
(isa Sorry-Seven-Three Sorry-Cards)
(isa Sorry-Seven-Two Sorry-Cards)
(isa Sorry-Seven-One Sorry-Cards)
(isa Sorry-Eight Sorry-Cards)
(isa Sorry-Eight Sorry-Cards-Pickable)
(isa Sorry-Ten Sorry-Cards)
(isa Sorry-Ten Sorry-Cards-Pickable)
(isa Sorry-Eleven Sorry-Cards)
(isa Sorry-Eleven Sorry-Cards-Pickable)
(isa Sorry-Twelve Sorry-Cards)
(isa Sorry-Twelve Sorry-Cards-Pickable)
(isa Sorry-Sorry Sorry-Cards)
(isa Sorry-Sorry Sorry-Cards-Pickable)
;;; (RandomMemberFn (TheSet Sorry-Cards-Pickable))
;;; returns a random card
;;; game start off with random card in KB
;;; swap turns:
(<== (swapTurn ?next)
(whoseTurn YellowAgent)
(unifies ?next RedAgent))
(<== (swapTurn ?next)
(whoseTurn RedAgent)
(unifies ?next YellowAgent))
;;; check if there is a piece at the destination
(<== (noSameColorAhead ?piece1 ?step)
(colorOfPiece ?piece1 ?color1)
(colorOfPiece ?piece2 ?color1)
(colorOfPiece ?piece3 ?color1)
(colorOfPiece ?piece4 ?color1)
(different ?piece4 ?piece3 ?piece2 ?piece1)
(piecePosition ?piece1 ?position)
(evaluate ?destination (PlusFn ?position ?step))
(uninferredSentence (piecePosition ?piece2 ?destination))
(uninferredSentence (piecePosition ?piece3 ?destination))
(uninferredSentence (piecePosition ?piece4 ?destination))
)
(<== (noOppoAhead ?piece ?step)
(piecePosition ?piece ?position)
(evaluate ?destination (PlusFn ?position ?step))
(greaterThan ?destination 60))
(<== (noOppoAhead ?piece ?step)
(colorOfPiece ?piece ?color1)
(colorOfPiece ?piece1 ?color2)
(different ?color1 ?color2)
(colorOfPiece ?piece2 ?color2)
(colorOfPiece ?piece3 ?color2)
(colorOfPiece ?piece4 ?color2)
(piecePosition ?piece1 ?position1)
(piecePosition ?piece2 ?position2)
(piecePosition ?piece3 ?position3)
(piecePosition ?piece4 ?position4)
(different ?piece1 ?piece2 ?piece3 ?piece4)
(piecePosition ?piece ?position)
(evaluate ?destination (PlusFn ?position ?step))
(evaluate ?distance1 (AbsoluteValueFn (DifferenceFn 30 (AbsoluteValueFn (DifferenceFn ?destination ?position1)))))
(greaterThan ?distance1 0)
(evaluate ?distance2 (AbsoluteValueFn (DifferenceFn 30 (AbsoluteValueFn (DifferenceFn ?destination ?position2)))))
(greaterThan ?distance2 0)
(evaluate ?distance3 (AbsoluteValueFn (DifferenceFn 30 (AbsoluteValueFn (DifferenceFn ?destination ?position3)))))
(greaterThan ?distance3 0)
(evaluate ?distance4 (AbsoluteValueFn (DifferenceFn 30 (AbsoluteValueFn (DifferenceFn ?destination ?position4)))))
(greaterThan ?distance4 0))
;;; When a piece is about to get HOME, check if the agent is going to win the game
(<== (notWinner ?agent1 ?piece1)
(colorOfAgent ?agent1 ?color1)
(colorOfPiece ?piece1 ?color1)
(colorOfPiece ?piece2 ?color1)
(uninferredSentence (piecePosition ?piece2 66))
(different ?piece1 ?piece2))
(<== (winner ?agent1 ?piece1)
(colorOfAgent ?agent1 ?color1)
(colorOfPiece ?piece1 ?color1)
(colorOfPiece ?piece2 ?color1)
(colorOfPiece ?piece3 ?color1)
(colorOfPiece ?piece4 ?color1)
(piecePosition ?piece2 66)
(piecePosition ?piece3 66)
(piecePosition ?piece4 66)
(different ?piece1 ?piece2 ?piece3 ?piece4))
;;; To check if the agent's pieces all at the start
;;; For Rule 1c
(<== (allAtStart ?agent1)
(colorOfAgent ?agent1 ?color1)
(colorOfPiece ?piece1 ?color1)
(colorOfPiece ?piece2 ?color1)
(colorOfPiece ?piece3 ?color1)
(colorOfPiece ?piece4 ?color1)
(different ?piece1 ?piece2 ?piece3 ?piece4)
(piecePosition ?piece1 0)
(piecePosition ?piece2 0)
(piecePosition ?piece3 0)
(piecePosition ?piece4 0))
(<== (noneAtStart ?agent1)
(colorOfAgent ?agent1 ?color1)
(colorOfPiece ?piece1 ?color1)
(colorOfPiece ?piece2 ?color1)
(colorOfPiece ?piece3 ?color1)
(colorOfPiece ?piece4 ?color1)
(different ?piece1 ?piece2 ?piece3 ?piece4)
(piecePosition ?piece1 ?pos1)
(piecePosition ?piece2 ?pos2)
(piecePosition ?piece3 ?pos3)
(piecePosition ?piece4 ?pos4)
(greaterThan ?pos1 0)
(greaterThan ?pos2 0)
(greaterThan ?pos3 0)
(greaterThan ?pos4 0)
)
;;; For Rule 5 (can be used with Rule 1c)
(<== (cannotMove ?piece ?step)
(piecePosition ?piece 0))
(<== (cannotMove ?piece ?step)
(piecePosition ?piece ?position)
(evaluate ?nextPosition (PlusFn ?position ?step))
(lessThan 66 ?nextPosition))
(<== (allCannotMove ?agent1 ?step)
(colorOfAgent ?agent1 ?color1)
(colorOfPiece ?piece1 ?color1)
(colorOfPiece ?piece2 ?color1)
(colorOfPiece ?piece3 ?color1)
(colorOfPiece ?piece4 ?color1)
(different ?piece1 ?piece2 ?piece3 ?piece4)
(cannotMove ?piece1 ?step)
(cannotMove ?piece2 ?step)
(cannotMove ?piece3 ?step)
(cannotMove ?piece4 ?step)
)
;;; find an opponent piece that is close to home to switch
(<== (findOppoSwitch ?piece1 ?step ?piece2 ?nextPosition1 ?nextPosition2)
(colorOfPiece ?piece1 ?color1)
(colorOfPiece ?piece2 ?color2)
(different ?color1 ?color2)
(swapExists ?piece1 ?step ?piece2)
(piecePosition ?piece1 ?position1)
(piecePosition ?piece2 ?position2)
(getOppoPos ?position1 ?nextPosition2)
(getOppoPos ?position2 ?nextPosition1)
)
;;; find no opponent to switch
(<== (findNoOppoSwitch ?piece ?step)
(piecePosition ?piece ?position)
(evaluate ?destination (PlusFn ?position ?step))
(greaterThan ?destination 60))
(<== (findNoOppoSwitch ?piece ?step)
(colorOfPiece ?piece ?color1)
(colorOfAgent ?agent2 ?color2)
(different ?color1 ?color2)
(allAtStart ?agent2)
)
(<== (findNoOppoSwitch ?piece ?step)
(colorOfPiece ?piece ?color1)
(colorOfPiece ?piece1 ?color2)
(different ?color1 ?color2)
(colorOfPiece ?piece2 ?color2)
(colorOfPiece ?piece3 ?color2)
(colorOfPiece ?piece4 ?color2)
(different ?piece1 ?piece2 ?piece3 ?piece4)
(swapNotExists ?piece ?step ?piece1)
(swapNotExists ?piece ?step ?piece2)
(swapNotExists ?piece ?step ?piece3)
(swapNotExists ?piece ?step ?piece4))
(<== (swapExists ?piece1 ?step ?piece2) ;;; piece1 is your piece, piece2 is opponent piece
(piecePosition ?piece1 ?pos1)
(evaluate ?destination (PlusFn ?pos1 ?step))
(piecePosition ?piece2 ?pos2)
(lessThan ?pos2 61)
(greaterThan ?po2 0)
(evaluate ?pos1Home (DifferenceFn 66 ?destination))
(getOppoPos ?pos2 ?pos2Oppo)
(evaluate ?pos2Home (DifferenceFn 66 ?pos2Oppo))
(lessThanOrEqualTo ?pos2Home ?pos1Home)
)
(<== (swapNotExists ?piece1 ?step ?piece2) ;;; piece1 is your piece, piece2 is opponent piece
(piecePosition ?piece1 ?pos1)
(evaluate ?destination (PlusFn ?pos1 ?step))
(piecePosition ?piece2 ?pos2)
(lessThan ?pos2 61)
(evaluate ?pos1Home (DifferenceFn 66 ?destination))
(getOppoPos ?pos2 ?pos2Oppo)
(evaluate ?pos2Home (DifferenceFn 66 ?pos2Oppo))
(greaterThan ?pos2Home ?pos1Home)
)
(<== (swapNotExists ?piece1 ?step ?piece2) ;;; piece1 is your piece, piece2 is opponent piece
(piecePosition ?piece2 ?pos2)
(greaterThan ?pos2 60)
)
(<== (getOppoPos ?myPos ?oppoPos)
(greaterThan ?myPos 30)
(evaluate ?a (DifferenceFn ?myPos 30))
(unifies ?oppoPos ?a)
)
(<== (getOppoPos ?myPos ?oppoPos)
(lessThan ?myPos 31)
(evaluate ?a (PlusFn ?myPos 30))
(unifies ?oppoPos ?a)
)
;;; cathy's horn clauses part
;;; used in card 7 when arrives at home with extra steps, then check whether this extra steps can be used or not.
;;; 1) not same color ahead (without arriving home), also the piece we can move shouldn't be at home.
(<== (checkisValidRemainingMove ?piece1 ?piece2 ?remainingSteps)
(colorOfPiece ?piece1 ?color)
(colorOfPiece ?piece2 ?color)
(colorOfPiece ?piece3 ?color)
(colorOfPiece ?piece4 ?color)
(different ?piece1 ?piece2 ?piece3 ?piece4)
(piecePosition ?piece2 ?pos2)
;;; 3/9 added: should ensure it's not at the start point
(greaterThan ?pos2 0)
(evaluate ?newPos (PlusFn ?pos2 ?remainingSteps))
(lessThan ?newPos 66)
(uninferredSentence (piecePosition ?piece3 ?newPos))
(uninferredSentence (piecePosition ?piece4 ?newPos)))
;;; 2) with arriving home
(<== (checkisValidRemainingMove ?piece1 ?piece2 ?remainingSteps)
(colorOfPiece ?piece1 ?color)
(colorOfPiece ?piece2 ?color)
(different ?piece1 ?piece2)
(piecePosition ?piece2 ?pos2)
(evaluate ?newPos (PlusFn ?pos2 ?remainingSteps))
(equals ?newPos 66))
;;; cathy's horn clauses part
;;; For Rule 7 (use the remaining steps to recursively select the card)
(<== (chooseCardWithSteps ?card ?steps)
(equals ?steps 1)
(unifies ?card Sorry-Seven-One))
(<== (chooseCardWithSteps ?card ?steps)
(equals ?steps 2)
(unifies ?card Sorry-Seven-Two))
(<== (chooseCardWithSteps ?card ?steps)
(equals ?steps 3)
(unifies ?card Sorry-Seven-Three))
(<== (chooseCardWithSteps ?card ?steps)
(equals ?steps 4)
(unifies ?card Sorry-Seven-Four))
(<== (chooseCardWithSteps ?card ?steps)
(equals ?steps 5)
(unifies ?card Sorry-Seven-Five))
(<== (chooseCardWithSteps ?card ?steps)
(equals ?steps 6)
(unifies ?card Sorry-Seven-Six))
(<== (notInKB ?piece1 ?position)
(colorOfPiece ?piece1 ?color1)
(colorOfPiece ?piece2 ?color1)
(colorOfPiece ?piece3 ?color1)
(colorOfPiece ?piece4 ?color1)
(different ?piece1 ?piece2 ?piece3 ?piece4)
(uninferredSentence (piecePosition ?piece2 ?position))
(uninferredSentence (piecePosition ?piece3 ?position))
(uninferredSentence (piecePosition ?piece4 ?position)))
(<== (notInKBOppo ?piece ?position)
(colorOfPiece ?piece ?color1)
(colorOfPiece ?piece1 ?color2)
(different ?color1 ?color2)
(colorOfPiece ?piece2 ?color2)
(colorOfPiece ?piece3 ?color2)
(colorOfPiece ?piece4 ?color2)
(different ?piece1 ?piece2 ?piece3 ?piece4)
(uninferredSentence (piecePosition ?piece2 ?position))
(uninferredSentence (piecePosition ?piece3 ?position))
(uninferredSentence (piecePosition ?piece4 ?position)))