-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminesweeper.clp
87 lines (87 loc) · 2 KB
/
minesweeper.clp
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
(deftemplate bomb-pos
(slot x (type NUMBER))
(slot y (type NUMBER))
)
(deftemplate empty-slot
(slot x (type NUMBER))
(slot y (type NUMBER))
)
(deftemplate safe-pos
(slot x (type NUMBER))
(slot y (type NUMBER))
(slot val (type NUMBER))
)
(deftemplate is-safe-around
(slot x (type NUMBER))
(slot y (type NUMBER))
)
(deftemplate is-unsafe-around
(slot x (type NUMBER))
(slot y (type NUMBER))
)
(deftemplate bomb-at
(slot x (type NUMBER))
(slot y (type NUMBER))
)
(deftemplate safe-at
(slot x (type NUMBER))
(slot y (type NUMBER))
)
(defrule mark-bomb
(index-x $? ?ax ?x ?bx $?)
(index-y $? ?ay ?y ?by $?)
(empty-slot (x ?x) (y ?y))
(or
(or
(or
(is-unsafe-around (x ?ax) (y ?ay))
(is-unsafe-around (x ?ax) (y ?y))
)
(or
(is-unsafe-around (x ?ax) (y ?by))
(is-unsafe-around (x ?x) (y ?ay))
)
)
(or
(or
(is-unsafe-around (x ?x) (y ?by))
(is-unsafe-around (x ?bx) (y ?ay))
)
(or
(is-unsafe-around (x ?bx) (y ?y))
(is-unsafe-around (x ?bx) (y ?by))
)
)
)
=>
(assert (bomb-at (x ?x) (y ?y)))
)
(defrule mark-safe
(index-x $? ?ax ?x ?bx $?)
(index-y $? ?ay ?y ?by $?)
(empty-slot (x ?x) (y ?y))
(or
(or
(or
(is-safe-around (x ?ax) (y ?ay))
(is-safe-around (x ?ax) (y ?y))
)
(or
(is-safe-around (x ?ax) (y ?by))
(is-safe-around (x ?x) (y ?ay))
)
)
(or
(or
(is-safe-around (x ?x) (y ?by))
(is-safe-around (x ?bx) (y ?ay))
)
(or
(is-safe-around (x ?bx) (y ?y))
(is-safe-around (x ?bx) (y ?by))
)
)
)
=>
(assert (safe-at (x ?x) (y ?y)))
)