Repository navigation
Expand file tree
/
Copy pathassemblies.fs
More file actions
300 lines (282 loc) · 15 KB
/
Copy pathassemblies.fs
File metadata and controls
300 lines (282 loc) · 15 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
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
require ./chain-ref.fs
require ./newpuzzle.def \ definition of the puzzle to be solved
require ./allpieces.fs \ to make all the pieces
require ./voxel-ref-list.fs
require ./group-lists.fs
require ./Gforth-Objects/mdca-obj.fs
." First setup all the puzzle basic data!" cr
0 puzzle-pieces make-all-pieces heap-new constant map \ this object is used to make reference lists from start pieces it is not used directly but produces ref.
constant ref-piece-list \ this is the reference list of piece`s created above
ref-piece-list chain-ref heap-new constant chain-ref-array \ this object takes reference list from above and makes chain ref array of that data
chain-ref-array fast-puzzle-board heap-new constant the-board \ the main board object for viewing the puzzle ... note it needs the reference created above
chain-ref-array hole-array-piece-list heap-new constant voxel-ref-list
: pause-for-key ( -- nkey ) \ halt until a key is pressed then continue nkey is the key pressed when this word returns
begin key? until
key 10 ms ;
: key-test-wait ( -- nkey ) \ if keyboard is pressed pause until it is pressed again
\ the second key pressed is returned as nkey
key?
if
key drop 10 ms
pause-for-key
else 0
then ;
: solved? ( -- nflag ) \ looks for the total pieces on the-board for done or not
\ nflag is true if puzzle solved
\ nflag is false if puzzle is not solved
the-board [bind] fast-puzzle-board max-board-pieces@
the-board [bind] fast-puzzle-board board-pieces@ = ;
: voxel-blocked? ( nvoxelindex -- nflag ) \ test nvoxelindex for a blocked path
\ nflag is true if nvoxelindex does have a blockage
\ nflag is false if no blockage was found
false { nvoxelindex nflag }
nvoxelindex voxel-ref-list [bind] hole-array-piece-list reset-A-piece-list
begin
nvoxelindex voxel-ref-list [bind] hole-array-piece-list index>xyz \ ( 0 30 at-xy ) .s ." < the xyz location of nvoxelindex" cr
voxel-ref-list [bind] hole-array-piece-list next-ref-piece-in-hole@ \ ( 0 31 at-xy ) .s ." < the reference and flag for the xyz location " cr
false = if \ false not at end
the-board [bind] fast-puzzle-board board-piece? ( dup ) true = if false to nflag true else false then
\ swap . ." < true is no blockage bail and false is blockage try again .. at middle" cr
else \ at end
the-board [bind] fast-puzzle-board board-piece? ( dup ) true = if false to nflag true else true to nflag true then
\ swap . ." < true is no blockage bail and false is blockage try again .. at end " cr
then
until
nflag ;
: blocked-board? ( -- nflag ) \ look at current board and see if there is any blocked parts that will not allow a piece
\ nflag is true if there is a block on the current board
\ nflag is false if no block found
try
the-board [bind] fast-puzzle-board max-board-index@ 0 ?do
i the-board [bind] fast-puzzle-board nvoxel@ true = if \ only test if the board has a hole at the voxel location not if there is a piece there currently
i voxel-blocked? throw \ if this board voxel is blocked it will throw with a true else it will do nothing
then
loop
false
restore
endtry ;
8 group-lists heap-new constant 8-assembly
: pop-8assembly
chain-ref-array [bind] chain-ref quantity@ 0 0 0 0 0 { qnt one two three four five }
qnt 0 ?do \ one
i to one
qnt 0 ?do \ two
i to two
one two chain-ref-array [bind] chain-ref fast-intersect? false = if
qnt 0 ?do \ three
i to three
one three chain-ref-array [bind] chain-ref fast-intersect?
two three chain-ref-array [bind] chain-ref fast-intersect? or false = if
qnt 0 ?do \ four
i to four
one four chain-ref-array [bind] chain-ref fast-intersect?
two four chain-ref-array [bind] chain-ref fast-intersect?
three four chain-ref-array [bind] chain-ref fast-intersect? or or false = if
qnt 0 ?do \ five
i to five
one five chain-ref-array [bind] chain-ref fast-intersect?
two five chain-ref-array [bind] chain-ref fast-intersect?
three five chain-ref-array [bind] chain-ref fast-intersect?
four five chain-ref-array [bind] chain-ref fast-intersect? or or or false = if
qnt 0 ?do \ six
one i chain-ref-array [bind] chain-ref fast-intersect?
two i chain-ref-array [bind] chain-ref fast-intersect?
three i chain-ref-array [bind] chain-ref fast-intersect?
four i chain-ref-array [bind] chain-ref fast-intersect?
five i chain-ref-array [bind] chain-ref fast-intersect? or or or or false = if
qnt 0 ?do \ seven
one i chain-ref-array [bind] chain-ref fast-intersect?
two i chain-ref-array [bind] chain-ref fast-intersect?
three i chain-ref-array [bind] chain-ref fast-intersect?
four i chain-ref-array [bind] chain-ref fast-intersect?
five i chain-ref-array [bind] chain-ref fast-intersect?
j i chain-ref-array [bind] chain-ref fast-intersect? or or or or or false = if
qnt 0 ?do \ eight
one i chain-ref-array [bind] chain-ref fast-intersect?
two i chain-ref-array [bind] chain-ref fast-intersect?
three i chain-ref-array [bind] chain-ref fast-intersect?
four i chain-ref-array [bind] chain-ref fast-intersect?
five i chain-ref-array [bind] chain-ref fast-intersect?
j i chain-ref-array [bind] chain-ref fast-intersect?
k i chain-ref-array [bind] chain-ref fast-intersect? or or or or or or false = if
one two three four five k j i 8-assembly [bind] group-lists group!
8-assembly [bind] group-lists group-dims@ drop 0 10 at-xy . one . two . ." < current size and indexs"
then
loop
then
loop
then
loop
then
loop
then
loop
then
loop
then
loop
loop ;
\ \\\
2 group-lists heap-new constant p-assembly
: make-ppassembly ( -- ) \ populate p-assembly with pairs of reference pieces from chain-ref-array
chain-ref-array [bind] chain-ref quantity@ 0 ?do
i chain-ref-array [bind] chain-ref chain-quantity@ 0 ?do
j j chain-ref-array [bind] chain-ref next-chain@ drop
p-assembly [bind] group-lists group!
loop
loop ;
make-ppassembly
0 value p-assy-array
: make-pparray ( -- )
p-assembly [bind] group-lists group-dims@ swap 2
multi-cell-array heap-new to p-assy-array
p-assembly [bind] group-lists group-dims@ drop 0 ?do
p-assembly [bind] group-lists group@> 2drop
0 i p-assy-array [bind] multi-cell-array cell-array!
1 i p-assy-array [bind] multi-cell-array cell-array!
loop ;
make-pparray
\ p-assembly bind group-lists group-dims@ .s
p-assembly bind group-lists destruct
2 p-assembly bind group-lists construct
\ p-assy-array bind multi-cell-array cell-array-dimensions@ .s
: make-2assembly ( -- ) \ populate p-assembly with pairs of the first order assembly from p-assy-array
p-assy-array [bind] multi-cell-array cell-array-dimensions@ 2drop 200 / 0 ?do
the-board [bind] fast-puzzle-board clear-board
0 i p-assy-array [bind] multi-cell-array cell-array@
the-board [bind] fast-puzzle-board board-piece! drop
1 i p-assy-array [bind] multi-cell-array cell-array@
the-board [bind] fast-puzzle-board board-piece! drop \ test pair now on board
p-assembly [bind] group-lists group-dims@ 0 10 at-xy . . i .
p-assy-array [bind] multi-cell-array cell-array-dimensions@ 2drop 0 ?do
0 i p-assy-array [bind] multi-cell-array cell-array@
the-board [bind] fast-puzzle-board board-piece? invert
1 i p-assy-array [bind] multi-cell-array cell-array@
the-board [bind] fast-puzzle-board board-piece? invert
or false = if \ if false then next pair index can be added to the group
j i p-assembly [bind] group-lists group!
then
loop
loop ;
\ make-2assembly
\ p-assembly bind group-lists group-dims@ .s
p-assembly bind group-lists destruct
6 p-assembly bind group-lists construct
: test4 { ua ub uc ud -- nflag }
\ nflag is false when no intersections are found true when an intersection is found between any piece
ua uc chain-ref-array [bind] chain-ref fast-intersect?
ua ud chain-ref-array [bind] chain-ref fast-intersect?
ub uc chain-ref-array [bind] chain-ref fast-intersect?
ub ud chain-ref-array [bind] chain-ref fast-intersect?
or or or ;
page
: make-6assembly ( -- ) \ populate p-assembly with 6 pairs for a total of 12 pieces
p-assy-array [bind] multi-cell-array cell-array-dimensions@ 2drop 0 0 0 0 0 0 { qnt one two three four five six }
qnt 0 ?do
i to one
p-assembly [bind] group-lists group-dims@ 0 10 at-xy . . i .
qnt 0 ?do
i to two
0 one p-assy-array [bind] multi-cell-array cell-array@
1 one p-assy-array [bind] multi-cell-array cell-array@
0 two p-assy-array [bind] multi-cell-array cell-array@
1 two p-assy-array [bind] multi-cell-array cell-array@
test4 false = if \ if false then next pair index can be tested
qnt 0 ?do
p-assembly [bind] group-lists group-dims@ 0 11 at-xy . . i .
i to three
0 one p-assy-array [bind] multi-cell-array cell-array@
1 one p-assy-array [bind] multi-cell-array cell-array@
0 three p-assy-array [bind] multi-cell-array cell-array@
1 three p-assy-array [bind] multi-cell-array cell-array@
test4
0 two p-assy-array [bind] multi-cell-array cell-array@
1 two p-assy-array [bind] multi-cell-array cell-array@
0 three p-assy-array [bind] multi-cell-array cell-array@
1 three p-assy-array [bind] multi-cell-array cell-array@
test4 or false = if \ if false then next pair index can be tested
qnt 0 ?do
p-assembly [bind] group-lists group-dims@ 0 12 at-xy . . i .
i to four
0 one p-assy-array [bind] multi-cell-array cell-array@
1 one p-assy-array [bind] multi-cell-array cell-array@
0 four p-assy-array [bind] multi-cell-array cell-array@
1 four p-assy-array [bind] multi-cell-array cell-array@
test4
0 two p-assy-array [bind] multi-cell-array cell-array@
1 two p-assy-array [bind] multi-cell-array cell-array@
0 four p-assy-array [bind] multi-cell-array cell-array@
1 four p-assy-array [bind] multi-cell-array cell-array@
test4
0 three p-assy-array [bind] multi-cell-array cell-array@
1 three p-assy-array [bind] multi-cell-array cell-array@
0 four p-assy-array [bind] multi-cell-array cell-array@
1 four p-assy-array [bind] multi-cell-array cell-array@
test4
or or false = if \ if false then next pair index can be tested
qnt 0 ?do
p-assembly [bind] group-lists group-dims@ 0 13 at-xy . . i .
i to five
0 one p-assy-array [bind] multi-cell-array cell-array@
1 one p-assy-array [bind] multi-cell-array cell-array@
0 five p-assy-array [bind] multi-cell-array cell-array@
1 five p-assy-array [bind] multi-cell-array cell-array@
test4
0 two p-assy-array [bind] multi-cell-array cell-array@
1 two p-assy-array [bind] multi-cell-array cell-array@
0 five p-assy-array [bind] multi-cell-array cell-array@
1 five p-assy-array [bind] multi-cell-array cell-array@
test4
0 three p-assy-array [bind] multi-cell-array cell-array@
1 three p-assy-array [bind] multi-cell-array cell-array@
0 five p-assy-array [bind] multi-cell-array cell-array@
1 five p-assy-array [bind] multi-cell-array cell-array@
test4
0 four p-assy-array [bind] multi-cell-array cell-array@
1 four p-assy-array [bind] multi-cell-array cell-array@
0 five p-assy-array [bind] multi-cell-array cell-array@
1 five p-assy-array [bind] multi-cell-array cell-array@
test4
or or or false = if \ if false then next pair index can be tested
qnt 0 ?do
\ p-assembly [bind] group-lists group-dims@ 0 14 at-xy . . i .
i to six
0 one p-assy-array [bind] multi-cell-array cell-array@
1 one p-assy-array [bind] multi-cell-array cell-array@
0 six p-assy-array [bind] multi-cell-array cell-array@
1 six p-assy-array [bind] multi-cell-array cell-array@
test4
0 two p-assy-array [bind] multi-cell-array cell-array@
1 two p-assy-array [bind] multi-cell-array cell-array@
0 six p-assy-array [bind] multi-cell-array cell-array@
1 six p-assy-array [bind] multi-cell-array cell-array@
test4
0 three p-assy-array [bind] multi-cell-array cell-array@
1 three p-assy-array [bind] multi-cell-array cell-array@
0 six p-assy-array [bind] multi-cell-array cell-array@
1 six p-assy-array [bind] multi-cell-array cell-array@
test4
0 four p-assy-array [bind] multi-cell-array cell-array@
1 four p-assy-array [bind] multi-cell-array cell-array@
0 six p-assy-array [bind] multi-cell-array cell-array@
1 six p-assy-array [bind] multi-cell-array cell-array@
test4
0 five p-assy-array [bind] multi-cell-array cell-array@
1 five p-assy-array [bind] multi-cell-array cell-array@
0 six p-assy-array [bind] multi-cell-array cell-array@
1 six p-assy-array [bind] multi-cell-array cell-array@
test4
or or or or false = if \ if false then add all the pairs to the list
one two three four five six p-assembly [bind] group-lists group!
then
loop
then
loop
then
loop
then
loop
then
loop
loop ;
make-6assembly