-
Notifications
You must be signed in to change notification settings - Fork 0
/
laba6.CLP
177 lines (151 loc) · 5.55 KB
/
laba6.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
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
(deffacts the-initial-state
(state w w w 0 b b b))
(defrule move2_1
(state 0 ?p2 ?p3 ?p4 ?p5 ?p6 ?p7)
(not (exists (state ?p2 0 ?p3 ?p4 ?p5 ?p6 ?p7)))
=>
(assert(state ?p2 0 ?p3 ?p4 ?p5 ?p6 ?p7))
(assert (swap 0 ?p2 ?p3 ?p4 ?p5 ?p6 ?p7 to ?p2 0 ?p3 ?p4 ?p5 ?p6 ?p7)))
(defrule move2_2
(state 0 ?p2 ?p3 ?p4 ?p5 ?p6 ?p7)
(not (exists (state ?p3 ?p2 0 ?p4 ?p5 ?p6 ?p7)))
=>
(assert(state ?p3 ?p2 0 ?p4 ?p5 ?p6 ?p7))
(assert (swap 0 ?p2 ?p3 ?p4 ?p5 ?p6 ?p7 to ?p3 ?p2 0 ?p4 ?p5 ?p6 ?p7)))
(defrule move3_1
(state ?p1 0 ?p3 ?p4 ?p5 ?p6 ?p7)
(not (exists (state 0 ?p1 ?p3 ?p4 ?p5 ?p6 ?p7)))
=>
(assert(state 0 ?p1 ?p3 ?p4 ?p5 ?p6 ?p7))
(assert (swap ?p1 0 ?p3 ?p4 ?p5 ?p6 ?p7 to 0 ?p1 ?p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?p6 ?p7 to ?p11 ?p22 ?p33 ?p44 ?p55 ?p66 ?p77 ?res)
(swap ?p11 ?p22 ?p33 ?p44 ?p55 ?p66 ?p77 to ?p111 ?p222 ?p333 ?p444 ?p555 ?p666 ?p777)
=>
(assert (path ?p11 ?p22 ?p33 ?p44 ?p55 ?p66 ?p77 to ?p111 ?p222 ?p333 ?p444 ?p555 ?p666 ?p777
(str-cat ?res " - [" ?p111 ?p222 ?p333 ?p444 ?p555 ?p666 ?p777 "]"))))
(defrule print_solutions
(salience 30)
(path w 0 b b w w b to w b b 0 w w b $?res)
=>
(printout t $?res crlf))