Author Topic: Word Search  (Read 1156 times)

0 Members and 1 Guest are viewing this topic.

bplus

• Forum Resident
• Posts: 5947
• B+ Knot again!
Word Search
« on: October 18, 2018, 09:23:43 AM »
RE: https://www.qb64.org/forum/index.php?topic=694.0
Halloween Theme Word Search puzzles in replies #9 and #10

Judging from responses at other forums to this challenge, some instructions might be helpful.

First, I did NOT know Rosetta actually had a Word Search challenge, This part of their description was followed in my puzzle:
http://rosettacode.org/wiki/Word_search
Quote
Quote
A word search puzzle typically consists of a grid of letters in which words are hidden.

There are many varieties of word search puzzles. For the task at hand we will use a rectangular grid in which the words may be placed horizontally, vertically, or diagonally. The words may also be spelled backwards.

The words may overlap but are not allowed to zigzag, or wrap around.

zigzag probably means start going one direction and then changing course mid-word.

Here is my BASIC strategy for finding words:

For each word in search list
1. Take the first letter and run through the grid of letters for a match.
2. For a matching first letter, check each of 8 directions and see if the length of the word will fit the grid in that direction.
3. If so, build the word from the grid in that direction and length (or check letter by letter and bug out if mismatch).
4. See if it matches the word being searched, if so, count it, display it and/or record the find.
5. Repeat until all words have been searched over the entire grid ie continue with remaining directions then continue with remaining grid, unless you know there is only one word positioned in the puzzle (but my challenge is a twist on the this standard newspaper puzzle).

A BASIC strategy for the 8 directions:
I set up two arrays (or use one of vectors). I called them DX() and DY() because they are the changes (D is for Delta which is Geek for change) of position when added to (x, y) coordinate of a location.

A normal word direction (say direction 1) is from left to right due East change X by +1 and Y by 0 DX(1) = 1, DY(1) = 0
SouthEast call direction 2, DX(2) = 1, DY(2) = 1 AKA diagonal down to the right
South call direction 3, DX(3) = 0, DY(3) = 1 AKA down vertically
SouthWest call direction 4, DX(4) = -1, DY(4) = 1 AKA diagonal down to left
...
DX(1) = 1 : DY(1) = 0
DX(2) = 1 : DY(2) = 1
DX(3) = 0 : DY(3) = 1
DX(4) = -1 : DY(4) = 1
DX(5) = -1 : DY(5) = 0
DX(6) = -1 : DY(6) = -1
DX(7) = 0 : DY(7) = -1
DX(8) = 1 : DY(8) = -1

There's a good chunk of the code done for you now!

Now there is another challenge, find the words by rotating and/or reflecting the grid of letters. Sound like fun?
Eh, probably not for Beginner's ASIC.

Ha! maybe only B+ thinks that might be fun?
« Last Edit: October 18, 2018, 09:32:24 AM by bplus »

bplus

• Forum Resident
• Posts: 5947
• B+ Knot again!
Re: Word Search
« Reply #1 on: October 19, 2018, 09:54:58 AM »
Update:

Yesterday, I got started on the array rotations idea and was making good progress until the phone started ringing like... every minute. Hey wait a minute, didn't I just last week sign up for no more Robo and some level of call blocking...? Dang! Another talk with the tech guy at cable company after getting through the maze of god awful multiple choices with bot.

It turns out that rotating arrays was the easy part. Not so easy is locating the position found by INSTR() back to the original Letters\$() array.

2B continued... (unless it completely bombs like WordCrack idea :(  )

SMcNeill

• QB64 Developer
• Forum Resident
• Posts: 3234
Re: Word Search
« Reply #2 on: October 19, 2018, 05:23:46 PM »
My little take on the BAT search:

Code: QB64: [Select]
1. '*****************************
2. '  TEXT FRAMES LIBRARY CODE
3. '*****************************
4.
5. TYPE TextArea
6.     InUse AS INTEGER
7.     x1 AS LONG 'left
8.     y1 AS LONG 'top
9.     w AS LONG 'width
10.     h AS LONG 'height
11.     FrameColor AS _UNSIGNED LONG
12.     BackColor AS _UNSIGNED LONG
13.     Xpos AS INTEGER
14.     Ypos AS INTEGER
15.     VerticalAlignment AS INTEGER
16.     Justification AS INTEGER
17.     UpdateMethod AS INTEGER
18.     TextColor AS _UNSIGNED LONG
19.     TextBackgroundColor AS _UNSIGNED LONG
20.     SavedBackground AS INTEGER
21.     HideFrame AS INTEGER
22.     ScreenX AS INTEGER
23.     ScreenY AS INTEGER
24.
25. REDIM SHARED TextHandles(0) AS TextArea
26.
27. CONST True = -1, False = 0
28. CONST LeftJustify = -1, CenterJustify = -2, RightJustify = -3, NoJustify = 0
29. CONST OnLine = 0, CenterLine = -1, TopLine = 1, BottomLine = -2
30. CONST NoUpdate = 0, DoUpdate = 1, NewLine = 2
31.
32. '**********************************
33. '*   PROGRAM CODE
34. '**********************************
35.
36.
37.
38.
39.
40.
41. CONST FileName\$ = "bat.txt"
42.
43.
44. REDIM SHARED WordGrid(0, 0) AS STRING * 1
45. REDIM SHARED YLines(0, 0) AS STRING
46. REDIM SHARED XLines(0, 0) AS STRING
47.
48. DIM SHARED SearchTerms(0) AS STRING
49. SearchTerms(0) = "BAT"
50.
51.
52. DIM SHARED LeftFrame AS INTEGER, RightFrame AS INTEGER
53.
54.
55. SCREEN _NEWIMAGE(1280, 720, 32) '720p HD just cause I like it as a standard
56.
57.
58. LeftFrame = NewTextArea(0, 0, 400, _HEIGHT - 1, False)
59. ColorTextArea LeftFrame, _RGB32(255, 255, 255), _RGB32(0, 0, 128)
60. DrawTextArea LeftFrame
61.
62. RightFrame = NewTextArea(401, 0, _WIDTH - 1, _HEIGHT - 1, False)
63. ColorTextArea RightFrame, _RGB32(255, 255, 255), _RGB32(0, 0, 0)
64. DrawTextArea RightFrame
65.
66.
67.
69. MakeDirectional
70. ShowGrid
71. FindWords
72.
73.
74.
75. SUB FindWords
76.     FOR j = 0 TO UBOUND(SearchTerms)
77.         PrintOut RightFrame, "SEARCHING FOR " + SearchTerms(j)
78.         PrintOut RightFrame, ""
79.         PrintOut RightFrame, "Finding Left to Right Matches"
80.         FOR i = 1 TO Y
81.             foundone = 0
82.                 foundone = INSTR(foundone + 1, YLines(1, i), SearchTerms(j))
83.                 IF foundone THEN
84.                     OUT\$ = OUT\$ + "(Line" + STR\$(i) + ", Position" + STR\$(foundone) + "), "
85.                     tc = tc + 1
87.         PrintOut RightFrame, OUT\$
88.
89.         OUT\$ = ""
90.         PrintOut RightFrame, ""
91.         PrintOut RightFrame, "Finding Right to Left Matches"
92.         FOR i = 1 TO Y
93.             foundone = 0
94.                 foundone = INSTR(foundone + 1, YLines(2, i), SearchTerms(j))
95.                 IF foundone THEN
96.                     OUT\$ = OUT\$ + "(Line" + STR\$(i) + ", Position" + STR\$(X - foundone + 1) + "), "
97.                     tc = tc + 1
99.         PrintOut RightFrame, OUT\$
100.
101.         OUT\$ = ""
102.         PrintOut RightFrame, ""
103.         PrintOut RightFrame, "Finding Up to Down Matches"
104.         FOR i = 1 TO X
105.             foundone = 0
106.                 foundone = INSTR(foundone + 1, XLines(1, i), SearchTerms(j))
107.                 IF foundone THEN
108.                     OUT\$ = OUT\$ + "(Line" + STR\$(foundone) + ", Position" + STR\$(i) + "), "
109.                     tc = tc + 1
111.         PrintOut RightFrame, OUT\$
112.
113.         OUT\$ = ""
114.         PrintOut RightFrame, ""
115.         PrintOut RightFrame, "Finding Down to Up Matches"
116.         FOR i = 1 TO X
117.             foundone = 0
118.                 foundone = INSTR(foundone + 1, XLines(2, i), SearchTerms(j))
119.                 IF foundone THEN
120.                     OUT\$ = OUT\$ + "(Line" + STR\$(foundone) + ", Position" + STR\$(i) + "), "
121.                     tc = tc + 1
123.         PrintOut RightFrame, OUT\$
124.
125.         PrintOut RightFrame, ""
126.         PrintOut RightFrame, ""
127.         PrintOut RightFrame, STR\$(tc) + " total matches found."
128.
129.
130.
131. SUB ShowGrid
132.     'Print the words in the grid
133.     SetTextColor LeftFrame, _RGB32(255, 255, 0), 0
134.     PrintOut LeftFrame, ""
135.     PrintOut LeftFrame, "                     WORD GRID"
136.     PrintOut LeftFrame, ""
137.     SetTextColor LeftFrame, _RGB32(255, 255, 255), 0
138.     FOR i = 1 TO Y
139.         PrintOut LeftFrame, "  " + YLines(1, i)
140.
141.
142.
143.
145.     OPEN FileName\$ FOR BINARY AS #1
146.     DO UNTIL EOF(1)
147.         LINE INPUT #1, junk\$
148.         Y = Y + 1
149.     X = LEN(junk\$): Y = Y
150.     SEEK #1, 1
151.
152.     REDIM WordGrid(1 TO X, 1 TO Y) AS STRING * 1 'Properly size our grid, with borders
153.     REDIM YLines(2, Y) AS STRING
154.     REDIM XLines(2, X) AS STRING
155.
156.     FOR i = 1 TO Y
157.         LINE INPUT #1, junk\$
158.         FOR j = 1 TO X
159.             WordGrid(j, i) = MID\$(junk\$, j) 'Fill in the grid with the letters
160.     CLOSE #1
161.
162. SUB MakeDirectional
163.     FOR i = 1 TO Y: FOR j = 1 TO X
164.             YLines(1, i) = YLines(1, i) + WordGrid(i, j) 'Left to Right Lines
165.     NEXT j, i
166.     FOR i = 1 TO Y: FOR j = X TO 1 STEP -1
167.             YLines(2, i) = YLines(2, i) + WordGrid(i, j) 'Right to Left Lines
168.     NEXT j, i
169.     FOR i = 1 TO Y: FOR j = 1 TO X
170.             XLines(1, i) = XLines(1, i) + WordGrid(j, i) 'Up to Down Lines
171.     NEXT j, i
172.     FOR i = 1 TO Y: FOR j = X TO 1 STEP -1
173.             XLines(2, i) = XLines(1, i) + WordGrid(j, i) 'Right to Left Lines
174.     NEXT j, i
175.
176. '*****************************
177. '  TEXT FRAMES LIBRARY CODE
178. '*****************************
179.
180. SUB PrintOut (WhichHandle AS INTEGER, What AS STRING)
181.     u = UBOUND(TextHandles)
182.     Handle = WhichHandle
183.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
184.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
185.     Where = TextHandles(Handle).VerticalAlignment
186.     How = TextHandles(Handle).Justification
187.     UpdatePrintPosition = TextHandles(Handle).UpdateMethod
188.     PlaceText Handle, Where, How, What, UpdatePrintPosition
189.
190.
191. SUB PlaceText (WhichHandle AS INTEGER, Where AS INTEGER, How AS INTEGER, What AS STRING, UpdatePrintPosition AS INTEGER)
192.     'WhichHandle is the handle which designates which text area we want to use
193.     'Where is where we want it to go in that text area
194.     '  -- Online prints the text to the current print position line in that text area.
195.     '  -- CenterLine centers the text to the center of that text area.
196.     '  -- any other value will print to that line positon in that particular box.
197.     'How tells us how we want to place that text (LeftJustified, RightJustified,CenterJustified, or NoJustify)
198.     'What is the text that we want to print in our text area
199.     'UpdatePrintPosition lets us know if we need to move to a newline or stay on the same line.  (Think PRINT with a semicolon vs PRINT without a semicolon).
200.
201.     D = _DEST: S = _SOURCE
202.
203.
204.     u = UBOUND(TextHandles)
205.     fh = _FONTHEIGHT
206.     pw = _PRINTWIDTH(What)
207.     Handle = WhichHandle
208.
209.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
210.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
211.     IF TextHandles(Handle).HideFrame THEN
212.         _DEST TextHandles(Handle).SavedBackground
213.         _SOURCE TextHandles(Handle).SavedBackground
214.     h = TextHandles(Handle).h - 4
215.     w = TextHandles(Handle).w - 4
216.
217.     SELECT CASE Where
218.         CASE BottomLine
219.             TextFrameY = h \ fh
220.         CASE OnLine
221.             TextFrameY = TextHandles(Handle).Ypos
222.             IF TextFrameY = 0 THEN TextFrameY = 1
223.         CASE CenterLine
224.             linesused = 0
225.             tpw = pw: tw = w: tWhat\$ = What
226.             DO UNTIL tpw <= tw
227.                 textallowed = WordBreak(LEFT\$(tWhat\$, w \ _FONTWIDTH))
228.                 text\$ = RTRIM\$(LEFT\$(tWhat\$, textallowed))
229.                 linesused = linesused + 1
230.                 tWhat\$ = MID\$(tWhat\$, textallowed + 1)
231.                 tpw = _PRINTWIDTH(tWhat\$)
232.             linesused = linesused + 1
233.             py = (h - linesused * fh) \ 2
234.             TextFrameY = py \ fh + 1
235.             IF TextFrameY < 1 THEN TextFrameY = 1
236.             TextFrameY = Where
237.
238.     IF TextFrameY < 1 THEN ERROR 5: EXIT FUNCTION 'We don't print above the allocated text area.
239.     blend = _BLEND
240.     DO UNTIL TextFrameY * fh < h 'We need to scroll the text area up, if someone is trying to print below it.
241.         'first let's get a temp image handle for the existing area of the screen.
242.         x1 = TextHandles(Handle).x1 + 2
243.         y1 = TextHandles(Handle).y1 + 2
244.         x2 = TextHandles(Handle).x1 + w
245.         y2 = TextHandles(Handle).y1 + h
246.         nh = y2 - y1 + 1 - fh
247.         nw = x2 - x1 + 1
248.         tempimage = _NEWIMAGE(nw, nh, 32) 'Really, I should swap this to a routine to pick which screen mode the user is in, but I'll come back to that later.
249.         _PUTIMAGE , , tempimage, (x1, y1 + fh)-(x2, y2)
250.         DrawTextArea Handle
251.         _PUTIMAGE (x1, y1)-(x2, y2 - fh), tempimage
252.         TextFrameY = TextFrameY - 1
253.     IF blend THEN _BLEND
254.
255.     COLOR TextHandles(Handle).TextColor, TextHandles(Handle).TextBackgroundColor
256.
257.     SELECT CASE How
258.         CASE LeftJustify
259.             TextFrameX = 0
260.             IF pw > w THEN
261.                 textallowed = WordBreak(LEFT\$(What, w \ _FONTWIDTH))
262.                 text\$ = RTRIM\$(LEFT\$(What, textallowed))
263.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), text\$
264.                 PlaceText Handle, TextFrameY + 1, LeftJustify, MID\$(What, textallowed + 1), 0
265.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), What
266.                 finished = -1
267.         CASE CenterJustify
268.             IF pw > w THEN
269.                 textallowed = WordBreak(LEFT\$(What, w \ _FONTWIDTH))
270.                 text\$ = RTRIM\$(LEFT\$(What, textallowed))
271.                 TextFrameX = (w - _PRINTWIDTH(text\$)) \ 2
272.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), text\$
273.                 PlaceText Handle, TextFrameY + 1, CenterJustify, MID\$(What, textallowed + 1), NoUpdate
274.                 TextFrameX = (w - pw) \ 2
275.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), What
276.                 finished = -1
277.         CASE RightJustify
278.             IF pw > w THEN
279.                 textallowed = WordBreak(LEFT\$(What, w \ _FONTWIDTH))
280.                 text\$ = RTRIM\$(LEFT\$(What, textallowed))
281.                 TextFrameX = w - _PRINTWIDTH(text\$)
282.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), text\$
283.                 PlaceText Handle, TextFrameY + 1, RightJustify, MID\$(What, textallowed + 1), 0
284.                 TextFrameX = w - pw
285.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), What
286.                 finished = -1
287.         CASE NoJustify
288.             TextFrameX = TextHandles(Handle).Xpos
289.             firstlinelimit = (w - TextFrameX) \ _FONTWIDTH 'the limit of characters on the first line
290.             IF LEN(What) > firstlinelimit THEN
291.                 textallowed = WordBreak(LEFT\$(What, firstlinelimit))
292.                 text\$ = RTRIM\$(LEFT\$(What, textallowed))
293.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), text\$
294.                 PlaceText Handle, TextFrameY + 1, LeftJustify, MID\$(What, textallowed + 1), 0 'After the first line we start printing over on the left, after a line break
295.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), What
296.                 finished = -1
297.
298.     IF finished THEN
299.         SELECT CASE TextHandles(Handle).UpdateMethod
300.             CASE NoUpdate 'We don't update the position at all.
301.             CASE DoUpdate
302.                 TextHandles(Handle).Xpos = TextFrameX + pw
303.                 TextHandles(Handle).Ypos = TextFrameY
304.             CASE NewLine
305.                 TextHandles(Handle).Ypos = TextFrameY + 1
306.                 TextHandles(Handle).Xpos = 1
307.         _DEST D: _SOURCE S
308.         COLOR FG, BG
309.
310. SUB SetTextForeground (Handle AS INTEGER, Foreground AS _UNSIGNED LONG)
311.     u = UBOUND(TextHandles)
312.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
313.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
314.     TextHandles(Handle).TextColor = Foreground
315.
316.
317. SUB SetTextBackground (Handle AS INTEGER, Background AS _UNSIGNED LONG)
318.     u = UBOUND(TextHandles)
319.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
320.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
321.     TextHandles(Handle).TextBackgroundColor = Background
322.
323.
324.
325. SUB SetTextColor (Handle AS INTEGER, Foreground AS _UNSIGNED LONG, Background AS _UNSIGNED LONG)
326.     u = UBOUND(TextHandles)
327.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
328.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
329.     TextHandles(Handle).TextColor = Foreground
330.     TextHandles(Handle).TextBackgroundColor = Background
331.
332.
333. SUB SetPrintUpdate (Handle AS INTEGER, Method AS INTEGER)
334.     u = UBOUND(TextHandles)
335.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
336.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
337.     IF Method < 0 OR Method > 2 THEN ERROR 5: EXIT FUNCTION
338.     TextHandles(Handle).UpdateMethod = Method
339.
340.
341. SUB SetPrintPosition (Handle AS INTEGER, TextFrameX AS INTEGER, TextFrameY AS INTEGER)
342.     u = UBOUND(TextHandles)
343.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
344.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
345.     SELECT CASE TextFrameY
346.         CASE BottomLine
347.             TextHandles(Handle).VerticalAlignment = -2
348.         CASE CenterLine
349.             TextHandles(Handle).VerticalAlignment = -1
350.             TextHandles(Handle).VerticalAlignment = 0
351.     IF TextFrameX < 1 AND TextFrameX > -4 THEN
352.         TextHandles(Handle).Justification = TextFrameX
353.         TextHandles(Handle).Xpos = TextFrameX
354.     IF TextFrameY < 1 THEN EXIT SUB
355.     TextHandles(Handle).Ypos = TextFrameY
356.
357. SUB SetPrintPositionX (Handle AS INTEGER, TextFrameX AS INTEGER)
358.     u = UBOUND(TextHandles)
359.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
360.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
361.     IF TextFrameX < 1 AND TextFrameX > -4 THEN
362.         TextHandles(Handle).Justification = TextFrameX
363.         TextHandles(Handle).Xpos = TextFrameX
364.
365. SUB SetPrintPositionY (Handle AS INTEGER, TextFrameY AS INTEGER)
366.     u = UBOUND(TextHandles)
367.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
368.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
369.     SELECT CASE TextFrameY
370.         CASE BottomLine
371.             TextHandles(Handle).VerticalAlignment = -2
372.         CASE CenterLine
373.             TextHandles(Handle).VerticalAlignment = -1
374.             TextHandles(Handle).VerticalAlignment = 0
375.     IF TextFrameY < 1 THEN EXIT SUB
376.     TextHandles(Handle).Ypos = TextFrameY
377.
378.
379. FUNCTION GetPrintPositionY (Handle AS INTEGER)
380.     u = UBOUND(TextHandles)
381.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
382.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
383.     GetPrintPositionY = TextHandles(Handle).Ypos
384.
385. FUNCTION GetPrintPositionX (Handle AS INTEGER)
386.     u = UBOUND(TextHandles)
387.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
388.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
389.     GetPrintPositionX = TextHandles(Handle).Xpos
390.
391.
392.
393. FUNCTION WordBreak (text\$)
394.     CONST Breaks = " ;,.?!-"
395.     FOR i = LEN(text\$) TO 0 STEP -1
396.         IF INSTR(Breaks, MID\$(text\$, i, 1)) THEN EXIT FOR
397.         loopcount = loopcount + 1
398.     IF i = 0 THEN i = LEN(text\$)
399.     WordBreak = i
400.
401.
402.
403. SUB ClearTextArea (Handle AS INTEGER)
404.     u = UBOUND(TextHandles)
405.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
406.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
407.     IF TextHandles(Handle).SavedBackground THEN
408.         w = TextHandles(Handle).w
409.         h = TextHandles(Handle).h
410.         x1 = TextHandles(Handle).ScreenX
411.         y1 = TextHandles(Handle).ScreenY
412.         x2 = x1 + w - 1
413.         y2 = y1 + h - 1
414.         blend = _BLEND
415.         _PUTIMAGE (x1, y1)-(x2, y2), TextHandles(Handle).SavedBackground
416.         IF blend THEN _BLEND
417.     DrawTextArea Handle
418.
419.
420.
421. SUB DrawTextArea (Handle AS INTEGER)
422.     u = UBOUND(TextHandles)
423.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
424.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
425.     w = TextHandles(Handle).w
426.     h = TextHandles(Handle).h
427.     x1 = TextHandles(Handle).ScreenX
428.     y1 = TextHandles(Handle).ScreenY
429.     x2 = x1 + w - 1
430.     y2 = y1 + h - 1
431.
432.     LINE (x1, y1)-(x2, y2), TextHandles(Handle).BackColor, BF
433.     LINE (x1, y1)-(x2, y2), TextHandles(Handle).FrameColor, B
434.
435.
436.
437. SUB ColorTextArea (Handle AS INTEGER, FrameColor AS _UNSIGNED LONG, BackColor AS _UNSIGNED LONG)
438.     u = UBOUND(TextHandles)
439.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
440.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
441.     TextHandles(Handle).FrameColor = FrameColor
442.     TextHandles(Handle).BackColor = BackColor
443.
444.
445.
446. FUNCTION NewTextArea% (tx1 AS INTEGER, ty1 AS INTEGER, tx2 AS INTEGER, ty2 AS INTEGER, SaveBackground AS INTEGER)
447.     x1 = tx1: y1 = ty1 'We pass temp variables to the function so we can swap values if needed without altering user variables
448.     x2 = tx2: y2 = ty2
449.     IF x1 > x2 THEN SWAP x1, x2
450.     IF y1 > y2 THEN SWAP y1, y2
451.     w = x2 - x1 + 1
452.     h = y2 - y1 + 1
453.     IF w = 0 AND h = 0 THEN ERROR 5: EXIT FUNCTION 'Illegal Function Call if the user tries to define an area with no size
454.     'Error checking for if the user sends coordinates which are off the screen
455.     IF x1 < 0 OR x2 > _WIDTH - 1 THEN ERROR 5: EXIT FUNCTION
456.     IF y1 < 0 OR y2 > _HEIGHT - 1 THEN ERROR 5: EXIT FUNCTION
457.
458.     u = UBOUND(TextHandles)
459.     FOR i = 1 TO u 'First let's check to see if we have an open handle from where one was freed earlier
460.         IF TextHandles(i).InUse = False THEN Handle = i: EXIT FOR
461.     IF Handle = 0 THEN 'We didn't have an open spot, so we need to add one to our list
462.         Handle = u + 1
463.         REDIM _PRESERVE TextHandles(Handle) AS TextArea
464.     TextHandles(Handle).x1 = x1
465.     TextHandles(Handle).y1 = y1
466.     TextHandles(Handle).w = w: TextHandles(Handle).h = h
467.     TextHandles(Handle).InUse = True
468.     TextHandles(Handle).Xpos = 0
469.     TextHandles(Handle).Ypos = 1
470.     TextHandles(Handle).UpdateMethod = NewLine
471.     TextHandles(Handle).TextColor = _RGB32(255, 255, 255) 'White text
472.     TextHandles(Handle).TextBackgroundColor = _RGB32(0, 0, 0) 'Black background
473.
474.     IF SaveBackground THEN
475.         imagehandle = _NEWIMAGE(w, h, 32)
476.         _PUTIMAGE , 0, imagehandle, (x1, y1)-(x2, y2)
477.         TextHandles(Handle).SavedBackground = imagehandle
478.     TextHandles(Handle).ScreenX = x1
479.     TextHandles(Handle).ScreenY = y1
480.
481.     NewTextArea% = Handle
482.
483. SUB FreeTextArea (Handle AS INTEGER)
484.     IF Handle > 0 AND Handle <= UBOUND(TextHandles) THEN
485.         IF TextHandles(Handle).InUse THEN
486.             TextHandles(Handle).InUse = False
487.             IF TextHandles(Handle).SavedBackground THEN
488.                 IF TextHandles(Handle).HideFrame = 0 THEN 'If the frame isn't hidden, then restore what's supposed to be beneath it
489.                     w = TextHandles(Handle).w
490.                     h = TextHandles(Handle).h
491.                     x1 = TextHandles(Handle).ScreenX
492.                     y1 = TextHandles(Handle).ScreenY
493.                     x2 = x1 + w - 1
494.                     y2 = y1 + h - 1
495.                     blend = _BLEND
496.                     _PUTIMAGE (x1, y1)-(x2, y2), TextHandles(Handle).SavedBackground
497.                     IF blend THEN _BLEND
498.                 'Even if it is hidden though, if we're going to free that frame, we need to free the stored image held with it to reduce memory usage.
499.                 _FREEIMAGE TextHandles(Handle).SavedBackground
500.             ERROR 258 'Invalid handle if the user tries to free a handle which has already been freed.
501.         ERROR 5 'Illegal function call if the user tries to free a handle that doesn't exist at all.
502.
503. SUB HideFrame (Handle AS INTEGER)
504.     IF TextHandles(Handle).HideFrame = 0 THEN 'only if the frame isn't hidden, can we hide it.
505.         TextHandles(Handle).HideFrame = -1
506.         w = TextHandles(Handle).w
507.         h = TextHandles(Handle).h
508.         x1 = TextHandles(Handle).ScreenX
509.         y1 = TextHandles(Handle).ScreenY
510.         x2 = x1 + w - 1
511.         y2 = y1 + h - 1
512.         imagehandle = _NEWIMAGE(TextHandles(Handle).w, TextHandles(Handle).h, 32)
513.         _PUTIMAGE , 0, imagehandle, (x1, y1)-(x2, y2)
514.         IF TextHandles(Handle).SavedBackground THEN
515.             blend = _BLEND
516.             _PUTIMAGE (x1, y1)-(x2, y2), TextHandles(Handle).SavedBackground
517.             _FREEIMAGE TextHandles(Handle).SavedBackground
518.             IF blend THEN _BLEND
519.         TextHandles(Handle).SavedBackground = imagehandle
520.         TextHandles(Handle).x1 = 0 'When the frames are hidden, we calculate our print position based off the hidden image
521.         TextHandles(Handle).y1 = 0 'So we'd start at point (0,0) as being top left
522.
523. SUB RestoreFrame (Handle AS INTEGER)
524.     IF TextHandles(Handle).HideFrame THEN 'only if we have a hidden frame do we have to worry about restoring it
525.         TextHandles(Handle).HideFrame = 0
526.         w = TextHandles(Handle).w
527.         h = TextHandles(Handle).h
528.         x1 = TextHandles(Handle).ScreenX
529.         y1 = TextHandles(Handle).ScreenY
530.         x2 = x1 + w - 1
531.         y2 = y1 + h - 1
532.         imagehandle = _NEWIMAGE(TextHandles(Handle).w, TextHandles(Handle).h, 32)
533.         blend = _BLEND
534.         _PUTIMAGE , 0, imagehandle, (x1, y1)-(x2, y2)
535.         _PUTIMAGE (x1, y1)-(x2, y2), TextHandles(Handle).SavedBackground ', 0, (0, 0)-(w, h)
536.         _FREEIMAGE TextHandles(Handle).SavedBackground
537.         IF blend THEN _BLEND
538.         TextHandles(Handle).SavedBackground = imagehandle
539.         TextHandles(Handle).x1 = x1 'When the frames are frames are restored, we need to recalculate our print position
540.         TextHandles(Handle).y1 = y1 'as we're no longer going over the image cooridinates, but the screen location of the top left corner instead.
541.
542. SUB MoveFrame (Handle AS INTEGER, x1 AS INTEGER, y1 AS INTEGER)
543.     'Only two coordinates here, so we'll be positioning our frames new movement by the top left corner.
544.     u = UBOUND(TextHandles)
545.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
546.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
547.     HideFrame Handle
548.     TextHandles(Handle).ScreenX = x1
549.     TextHandles(Handle).ScreenY = y1
550.     RestoreFrame Handle
551.

Works with CONST FileName\$ = "bat.txt", cause I'm too lazy to type the full file name."  :P

This should also work with trick and treat, with minor alterations, which I'll post soon(tm).
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

SMcNeill

• QB64 Developer
• Forum Resident
• Posts: 3234
Re: Word Search
« Reply #3 on: October 19, 2018, 05:42:35 PM »
Code: QB64: [Select]
1. '*****************************
2. '  TEXT FRAMES LIBRARY CODE
3. '*****************************
4.
5. TYPE TextArea
6.     InUse AS INTEGER
7.     x1 AS LONG 'left
8.     y1 AS LONG 'top
9.     w AS LONG 'width
10.     h AS LONG 'height
11.     FrameColor AS _UNSIGNED LONG
12.     BackColor AS _UNSIGNED LONG
13.     Xpos AS INTEGER
14.     Ypos AS INTEGER
15.     VerticalAlignment AS INTEGER
16.     Justification AS INTEGER
17.     UpdateMethod AS INTEGER
18.     TextColor AS _UNSIGNED LONG
19.     TextBackgroundColor AS _UNSIGNED LONG
20.     SavedBackground AS INTEGER
21.     HideFrame AS INTEGER
22.     ScreenX AS INTEGER
23.     ScreenY AS INTEGER
24.
25. REDIM SHARED TextHandles(0) AS TextArea
26.
27. CONST True = -1, False = 0
28. CONST LeftJustify = -1, CenterJustify = -2, RightJustify = -3, NoJustify = 0
29. CONST OnLine = 0, CenterLine = -1, TopLine = 1, BottomLine = -2
30. CONST NoUpdate = 0, DoUpdate = 1, NewLine = 2
31.
32. '**********************************
33. '*   PROGRAM CODE
34. '**********************************
35.
36.
37.
38.
39.
40.
41. CONST FileName\$ = "tt.txt"
42.
43.
44. REDIM SHARED WordGrid(0, 0) AS STRING * 1
45. REDIM SHARED YLines(0, 0) AS STRING
46. REDIM SHARED XLines(0, 0) AS STRING
47.
48. DIM SHARED SearchTerms(1) AS STRING
49. SearchTerms(0) = "TRICK": SearchTerms(1) = "TREAT"
50.
51.
52. DIM SHARED LeftFrame AS INTEGER, RightFrame AS INTEGER
53.
54.
55. SCREEN _NEWIMAGE(1280, 720, 32) '720p HD just cause I like it as a standard
56.
57.
58. LeftFrame = NewTextArea(0, 0, 400, _HEIGHT - 1, False)
59. ColorTextArea LeftFrame, _RGB32(255, 255, 255), _RGB32(0, 0, 128)
60. DrawTextArea LeftFrame
61.
62. RightFrame = NewTextArea(401, 0, _WIDTH - 1, _HEIGHT - 1, False)
63. ColorTextArea RightFrame, _RGB32(255, 255, 255), _RGB32(0, 0, 0)
64. DrawTextArea RightFrame
65.
66.
67.
69. MakeDirectional
70. ShowGrid
71. FindWords
72.
73.
74.
75. SUB FindWords
76.     FOR j = 0 TO UBOUND(SearchTerms)
77.         PrintOut RightFrame, "SEARCHING FOR " + SearchTerms(j)
78.         PrintOut RightFrame, ""
79.         PrintOut RightFrame, "Finding Left to Right Matches"
80.         FOR i = 1 TO Y
81.             foundone = 0
82.                 foundone = INSTR(foundone + 1, YLines(1, i), SearchTerms(j))
83.                 IF foundone THEN
84.                     OUT\$ = OUT\$ + "(Line" + STR\$(i) + ", Position" + STR\$(foundone) + "), "
85.                     tc = tc + 1
87.         PrintOut RightFrame, OUT\$
88.
89.         OUT\$ = ""
90.         PrintOut RightFrame, ""
91.         PrintOut RightFrame, "Finding Right to Left Matches"
92.         FOR i = 1 TO Y
93.             foundone = 0
94.                 foundone = INSTR(foundone + 1, YLines(2, i), SearchTerms(j))
95.                 IF foundone THEN
96.                     OUT\$ = OUT\$ + "(Line" + STR\$(i) + ", Position" + STR\$(X - foundone + 1) + "), "
97.                     tc = tc + 1
99.         PrintOut RightFrame, OUT\$
100.
101.         OUT\$ = ""
102.         PrintOut RightFrame, ""
103.         PrintOut RightFrame, "Finding Up to Down Matches"
104.         FOR i = 1 TO X
105.             foundone = 0
106.                 foundone = INSTR(foundone + 1, XLines(1, i), SearchTerms(j))
107.                 IF foundone THEN
108.                     OUT\$ = OUT\$ + "(Line" + STR\$(foundone) + ", Position" + STR\$(i) + "), "
109.                     tc = tc + 1
111.         PrintOut RightFrame, OUT\$
112.
113.         OUT\$ = ""
114.         PrintOut RightFrame, ""
115.         PrintOut RightFrame, "Finding Down to Up Matches"
116.         FOR i = 1 TO X
117.             foundone = 0
118.                 foundone = INSTR(foundone + 1, XLines(2, i), SearchTerms(j))
119.                 IF foundone THEN
120.                     OUT\$ = OUT\$ + "(Line" + STR\$(foundone) + ", Position" + STR\$(i) + "), "
121.                     tc = tc + 1
123.         PrintOut RightFrame, OUT\$
124.         PrintOut RightFrame, ""
125.         PrintOut RightFrame, ""
126.         PrintOut RightFrame, STR\$(tc) + " total matches found."
127.         PrintOut RightFrame, ""
128.         PrintOut RightFrame, ""
129.         tc = 0
130.
131.
132.
133. SUB ShowGrid
134.     'Print the words in the grid
135.     SetTextColor LeftFrame, _RGB32(255, 255, 0), 0
136.     PrintOut LeftFrame, ""
137.     PrintOut LeftFrame, "                     WORD GRID"
138.     PrintOut LeftFrame, ""
139.     SetTextColor LeftFrame, _RGB32(255, 255, 255), 0
140.     FOR i = 1 TO Y
141.         PrintOut LeftFrame, "  " + YLines(1, i)
142.
143.
144.
145.
147.     OPEN FileName\$ FOR BINARY AS #1
148.     DO UNTIL EOF(1)
149.         LINE INPUT #1, junk\$
150.         Y = Y + 1
151.     X = LEN(junk\$): Y = Y
152.     SEEK #1, 1
153.
154.     REDIM WordGrid(1 TO X, 1 TO Y) AS STRING * 1 'Properly size our grid, with borders
155.     REDIM YLines(2, Y) AS STRING
156.     REDIM XLines(2, X) AS STRING
157.
158.     FOR i = 1 TO Y
159.         LINE INPUT #1, junk\$
160.         FOR j = 1 TO X
161.             WordGrid(j, i) = MID\$(junk\$, j) 'Fill in the grid with the letters
162.     CLOSE #1
163.
164. SUB MakeDirectional
165.     FOR i = 1 TO Y
166.         FOR j = 1 TO X
167.             YLines(1, i) = YLines(1, i) + WordGrid(j, i) 'Left to Right Lines
168.     NEXT j, i
169.     FOR i = 1 TO Y: FOR j = X TO 1 STEP -1
170.             YLines(2, i) = YLines(2, i) + WordGrid(j, i) 'Right to Left Lines
171.     NEXT j, i
172.     FOR i = 1 TO Y: FOR j = 1 TO X
173.             XLines(1, i) = XLines(1, i) + WordGrid(j, i) 'Up to Down Lines
174.     NEXT j, i
175.     FOR i = 1 TO Y: FOR j = X TO 1 STEP -1
176.             XLines(2, i) = XLines(1, i) + WordGrid(j, i) 'Right to Left Lines
177.     NEXT j, i
178.
179. '*****************************
180. '  TEXT FRAMES LIBRARY CODE
181. '*****************************
182.
183. SUB PrintOut (WhichHandle AS INTEGER, What AS STRING)
184.     u = UBOUND(TextHandles)
185.     Handle = WhichHandle
186.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
187.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
188.     Where = TextHandles(Handle).VerticalAlignment
189.     How = TextHandles(Handle).Justification
190.     UpdatePrintPosition = TextHandles(Handle).UpdateMethod
191.     PlaceText Handle, Where, How, What, UpdatePrintPosition
192.
193.
194. SUB PlaceText (WhichHandle AS INTEGER, Where AS INTEGER, How AS INTEGER, What AS STRING, UpdatePrintPosition AS INTEGER)
195.     'WhichHandle is the handle which designates which text area we want to use
196.     'Where is where we want it to go in that text area
197.     '  -- Online prints the text to the current print position line in that text area.
198.     '  -- CenterLine centers the text to the center of that text area.
199.     '  -- any other value will print to that line positon in that particular box.
200.     'How tells us how we want to place that text (LeftJustified, RightJustified,CenterJustified, or NoJustify)
201.     'What is the text that we want to print in our text area
202.     'UpdatePrintPosition lets us know if we need to move to a newline or stay on the same line.  (Think PRINT with a semicolon vs PRINT without a semicolon).
203.
204.     D = _DEST: S = _SOURCE
205.
206.
207.     u = UBOUND(TextHandles)
208.     fh = _FONTHEIGHT
209.     pw = _PRINTWIDTH(What)
210.     Handle = WhichHandle
211.
212.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
213.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
214.     IF TextHandles(Handle).HideFrame THEN
215.         _DEST TextHandles(Handle).SavedBackground
216.         _SOURCE TextHandles(Handle).SavedBackground
217.     h = TextHandles(Handle).h - 4
218.     w = TextHandles(Handle).w - 4
219.
220.     SELECT CASE Where
221.         CASE BottomLine
222.             TextFrameY = h \ fh
223.         CASE OnLine
224.             TextFrameY = TextHandles(Handle).Ypos
225.             IF TextFrameY = 0 THEN TextFrameY = 1
226.         CASE CenterLine
227.             linesused = 0
228.             tpw = pw: tw = w: tWhat\$ = What
229.             DO UNTIL tpw <= tw
230.                 textallowed = WordBreak(LEFT\$(tWhat\$, w \ _FONTWIDTH))
231.                 text\$ = RTRIM\$(LEFT\$(tWhat\$, textallowed))
232.                 linesused = linesused + 1
233.                 tWhat\$ = MID\$(tWhat\$, textallowed + 1)
234.                 tpw = _PRINTWIDTH(tWhat\$)
235.             linesused = linesused + 1
236.             py = (h - linesused * fh) \ 2
237.             TextFrameY = py \ fh + 1
238.             IF TextFrameY < 1 THEN TextFrameY = 1
239.             TextFrameY = Where
240.
241.     IF TextFrameY < 1 THEN ERROR 5: EXIT FUNCTION 'We don't print above the allocated text area.
242.     blend = _BLEND
243.     DO UNTIL TextFrameY * fh < h 'We need to scroll the text area up, if someone is trying to print below it.
244.         'first let's get a temp image handle for the existing area of the screen.
245.         x1 = TextHandles(Handle).x1 + 2
246.         y1 = TextHandles(Handle).y1 + 2
247.         x2 = TextHandles(Handle).x1 + w
248.         y2 = TextHandles(Handle).y1 + h
249.         nh = y2 - y1 + 1 - fh
250.         nw = x2 - x1 + 1
251.         tempimage = _NEWIMAGE(nw, nh, 32) 'Really, I should swap this to a routine to pick which screen mode the user is in, but I'll come back to that later.
252.         _PUTIMAGE , , tempimage, (x1, y1 + fh)-(x2, y2)
253.         DrawTextArea Handle
254.         _PUTIMAGE (x1, y1)-(x2, y2 - fh), tempimage
255.         TextFrameY = TextFrameY - 1
256.     IF blend THEN _BLEND
257.
258.     COLOR TextHandles(Handle).TextColor, TextHandles(Handle).TextBackgroundColor
259.
260.     SELECT CASE How
261.         CASE LeftJustify
262.             TextFrameX = 0
263.             IF pw > w THEN
264.                 textallowed = WordBreak(LEFT\$(What, w \ _FONTWIDTH))
265.                 text\$ = RTRIM\$(LEFT\$(What, textallowed))
266.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), text\$
267.                 PlaceText Handle, TextFrameY + 1, LeftJustify, MID\$(What, textallowed + 1), 0
268.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), What
269.                 finished = -1
270.         CASE CenterJustify
271.             IF pw > w THEN
272.                 textallowed = WordBreak(LEFT\$(What, w \ _FONTWIDTH))
273.                 text\$ = RTRIM\$(LEFT\$(What, textallowed))
274.                 TextFrameX = (w - _PRINTWIDTH(text\$)) \ 2
275.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), text\$
276.                 PlaceText Handle, TextFrameY + 1, CenterJustify, MID\$(What, textallowed + 1), NoUpdate
277.                 TextFrameX = (w - pw) \ 2
278.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), What
279.                 finished = -1
280.         CASE RightJustify
281.             IF pw > w THEN
282.                 textallowed = WordBreak(LEFT\$(What, w \ _FONTWIDTH))
283.                 text\$ = RTRIM\$(LEFT\$(What, textallowed))
284.                 TextFrameX = w - _PRINTWIDTH(text\$)
285.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), text\$
286.                 PlaceText Handle, TextFrameY + 1, RightJustify, MID\$(What, textallowed + 1), 0
287.                 TextFrameX = w - pw
288.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), What
289.                 finished = -1
290.         CASE NoJustify
291.             TextFrameX = TextHandles(Handle).Xpos
292.             firstlinelimit = (w - TextFrameX) \ _FONTWIDTH 'the limit of characters on the first line
293.             IF LEN(What) > firstlinelimit THEN
294.                 textallowed = WordBreak(LEFT\$(What, firstlinelimit))
295.                 text\$ = RTRIM\$(LEFT\$(What, textallowed))
296.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), text\$
297.                 PlaceText Handle, TextFrameY + 1, LeftJustify, MID\$(What, textallowed + 1), 0 'After the first line we start printing over on the left, after a line break
298.                 _PRINTSTRING (TextFrameX + 2 + TextHandles(Handle).x1, (TextFrameY - 1) * fh + TextHandles(Handle).y1 + 2), What
299.                 finished = -1
300.
301.     IF finished THEN
302.         SELECT CASE TextHandles(Handle).UpdateMethod
303.             CASE NoUpdate 'We don't update the position at all.
304.             CASE DoUpdate
305.                 TextHandles(Handle).Xpos = TextFrameX + pw
306.                 TextHandles(Handle).Ypos = TextFrameY
307.             CASE NewLine
308.                 TextHandles(Handle).Ypos = TextFrameY + 1
309.                 TextHandles(Handle).Xpos = 1
310.         _DEST D: _SOURCE S
311.         COLOR FG, BG
312.
313. SUB SetTextForeground (Handle AS INTEGER, Foreground AS _UNSIGNED LONG)
314.     u = UBOUND(TextHandles)
315.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
316.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
317.     TextHandles(Handle).TextColor = Foreground
318.
319.
320. SUB SetTextBackground (Handle AS INTEGER, Background AS _UNSIGNED LONG)
321.     u = UBOUND(TextHandles)
322.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
323.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
324.     TextHandles(Handle).TextBackgroundColor = Background
325.
326.
327.
328. SUB SetTextColor (Handle AS INTEGER, Foreground AS _UNSIGNED LONG, Background AS _UNSIGNED LONG)
329.     u = UBOUND(TextHandles)
330.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
331.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
332.     TextHandles(Handle).TextColor = Foreground
333.     TextHandles(Handle).TextBackgroundColor = Background
334.
335.
336. SUB SetPrintUpdate (Handle AS INTEGER, Method AS INTEGER)
337.     u = UBOUND(TextHandles)
338.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
339.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
340.     IF Method < 0 OR Method > 2 THEN ERROR 5: EXIT FUNCTION
341.     TextHandles(Handle).UpdateMethod = Method
342.
343.
344. SUB SetPrintPosition (Handle AS INTEGER, TextFrameX AS INTEGER, TextFrameY AS INTEGER)
345.     u = UBOUND(TextHandles)
346.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
347.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
348.     SELECT CASE TextFrameY
349.         CASE BottomLine
350.             TextHandles(Handle).VerticalAlignment = -2
351.         CASE CenterLine
352.             TextHandles(Handle).VerticalAlignment = -1
353.             TextHandles(Handle).VerticalAlignment = 0
354.     IF TextFrameX < 1 AND TextFrameX > -4 THEN
355.         TextHandles(Handle).Justification = TextFrameX
356.         TextHandles(Handle).Xpos = TextFrameX
357.     IF TextFrameY < 1 THEN EXIT SUB
358.     TextHandles(Handle).Ypos = TextFrameY
359.
360. SUB SetPrintPositionX (Handle AS INTEGER, TextFrameX AS INTEGER)
361.     u = UBOUND(TextHandles)
362.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
363.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
364.     IF TextFrameX < 1 AND TextFrameX > -4 THEN
365.         TextHandles(Handle).Justification = TextFrameX
366.         TextHandles(Handle).Xpos = TextFrameX
367.
368. SUB SetPrintPositionY (Handle AS INTEGER, TextFrameY AS INTEGER)
369.     u = UBOUND(TextHandles)
370.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
371.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
372.     SELECT CASE TextFrameY
373.         CASE BottomLine
374.             TextHandles(Handle).VerticalAlignment = -2
375.         CASE CenterLine
376.             TextHandles(Handle).VerticalAlignment = -1
377.             TextHandles(Handle).VerticalAlignment = 0
378.     IF TextFrameY < 1 THEN EXIT SUB
379.     TextHandles(Handle).Ypos = TextFrameY
380.
381.
382. FUNCTION GetPrintPositionY (Handle AS INTEGER)
383.     u = UBOUND(TextHandles)
384.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
385.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
386.     GetPrintPositionY = TextHandles(Handle).Ypos
387.
388. FUNCTION GetPrintPositionX (Handle AS INTEGER)
389.     u = UBOUND(TextHandles)
390.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
391.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
392.     GetPrintPositionX = TextHandles(Handle).Xpos
393.
394.
395.
396. FUNCTION WordBreak (text\$)
397.     CONST Breaks = " ;,.?!-"
398.     FOR i = LEN(text\$) TO 0 STEP -1
399.         IF INSTR(Breaks, MID\$(text\$, i, 1)) THEN EXIT FOR
400.         loopcount = loopcount + 1
401.     IF i = 0 THEN i = LEN(text\$)
402.     WordBreak = i
403.
404.
405.
406. SUB ClearTextArea (Handle AS INTEGER)
407.     u = UBOUND(TextHandles)
408.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
409.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
410.     IF TextHandles(Handle).SavedBackground THEN
411.         w = TextHandles(Handle).w
412.         h = TextHandles(Handle).h
413.         x1 = TextHandles(Handle).ScreenX
414.         y1 = TextHandles(Handle).ScreenY
415.         x2 = x1 + w - 1
416.         y2 = y1 + h - 1
417.         blend = _BLEND
418.         _PUTIMAGE (x1, y1)-(x2, y2), TextHandles(Handle).SavedBackground
419.         IF blend THEN _BLEND
420.     DrawTextArea Handle
421.
422.
423.
424. SUB DrawTextArea (Handle AS INTEGER)
425.     u = UBOUND(TextHandles)
426.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
427.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
428.     w = TextHandles(Handle).w
429.     h = TextHandles(Handle).h
430.     x1 = TextHandles(Handle).ScreenX
431.     y1 = TextHandles(Handle).ScreenY
432.     x2 = x1 + w - 1
433.     y2 = y1 + h - 1
434.
435.     LINE (x1, y1)-(x2, y2), TextHandles(Handle).BackColor, BF
436.     LINE (x1, y1)-(x2, y2), TextHandles(Handle).FrameColor, B
437.
438.
439.
440. SUB ColorTextArea (Handle AS INTEGER, FrameColor AS _UNSIGNED LONG, BackColor AS _UNSIGNED LONG)
441.     u = UBOUND(TextHandles)
442.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
443.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
444.     TextHandles(Handle).FrameColor = FrameColor
445.     TextHandles(Handle).BackColor = BackColor
446.
447.
448.
449. FUNCTION NewTextArea% (tx1 AS INTEGER, ty1 AS INTEGER, tx2 AS INTEGER, ty2 AS INTEGER, SaveBackground AS INTEGER)
450.     x1 = tx1: y1 = ty1 'We pass temp variables to the function so we can swap values if needed without altering user variables
451.     x2 = tx2: y2 = ty2
452.     IF x1 > x2 THEN SWAP x1, x2
453.     IF y1 > y2 THEN SWAP y1, y2
454.     w = x2 - x1 + 1
455.     h = y2 - y1 + 1
456.     IF w = 0 AND h = 0 THEN ERROR 5: EXIT FUNCTION 'Illegal Function Call if the user tries to define an area with no size
457.     'Error checking for if the user sends coordinates which are off the screen
458.     IF x1 < 0 OR x2 > _WIDTH - 1 THEN ERROR 5: EXIT FUNCTION
459.     IF y1 < 0 OR y2 > _HEIGHT - 1 THEN ERROR 5: EXIT FUNCTION
460.
461.     u = UBOUND(TextHandles)
462.     FOR i = 1 TO u 'First let's check to see if we have an open handle from where one was freed earlier
463.         IF TextHandles(i).InUse = False THEN Handle = i: EXIT FOR
464.     IF Handle = 0 THEN 'We didn't have an open spot, so we need to add one to our list
465.         Handle = u + 1
466.         REDIM _PRESERVE TextHandles(Handle) AS TextArea
467.     TextHandles(Handle).x1 = x1
468.     TextHandles(Handle).y1 = y1
469.     TextHandles(Handle).w = w: TextHandles(Handle).h = h
470.     TextHandles(Handle).InUse = True
471.     TextHandles(Handle).Xpos = 0
472.     TextHandles(Handle).Ypos = 1
473.     TextHandles(Handle).UpdateMethod = NewLine
474.     TextHandles(Handle).TextColor = _RGB32(255, 255, 255) 'White text
475.     TextHandles(Handle).TextBackgroundColor = _RGB32(0, 0, 0) 'Black background
476.
477.     IF SaveBackground THEN
478.         imagehandle = _NEWIMAGE(w, h, 32)
479.         _PUTIMAGE , 0, imagehandle, (x1, y1)-(x2, y2)
480.         TextHandles(Handle).SavedBackground = imagehandle
481.     TextHandles(Handle).ScreenX = x1
482.     TextHandles(Handle).ScreenY = y1
483.
484.     NewTextArea% = Handle
485.
486. SUB FreeTextArea (Handle AS INTEGER)
487.     IF Handle > 0 AND Handle <= UBOUND(TextHandles) THEN
488.         IF TextHandles(Handle).InUse THEN
489.             TextHandles(Handle).InUse = False
490.             IF TextHandles(Handle).SavedBackground THEN
491.                 IF TextHandles(Handle).HideFrame = 0 THEN 'If the frame isn't hidden, then restore what's supposed to be beneath it
492.                     w = TextHandles(Handle).w
493.                     h = TextHandles(Handle).h
494.                     x1 = TextHandles(Handle).ScreenX
495.                     y1 = TextHandles(Handle).ScreenY
496.                     x2 = x1 + w - 1
497.                     y2 = y1 + h - 1
498.                     blend = _BLEND
499.                     _PUTIMAGE (x1, y1)-(x2, y2), TextHandles(Handle).SavedBackground
500.                     IF blend THEN _BLEND
501.                 'Even if it is hidden though, if we're going to free that frame, we need to free the stored image held with it to reduce memory usage.
502.                 _FREEIMAGE TextHandles(Handle).SavedBackground
503.             ERROR 258 'Invalid handle if the user tries to free a handle which has already been freed.
504.         ERROR 5 'Illegal function call if the user tries to free a handle that doesn't exist at all.
505.
506. SUB HideFrame (Handle AS INTEGER)
507.     IF TextHandles(Handle).HideFrame = 0 THEN 'only if the frame isn't hidden, can we hide it.
508.         TextHandles(Handle).HideFrame = -1
509.         w = TextHandles(Handle).w
510.         h = TextHandles(Handle).h
511.         x1 = TextHandles(Handle).ScreenX
512.         y1 = TextHandles(Handle).ScreenY
513.         x2 = x1 + w - 1
514.         y2 = y1 + h - 1
515.         imagehandle = _NEWIMAGE(TextHandles(Handle).w, TextHandles(Handle).h, 32)
516.         _PUTIMAGE , 0, imagehandle, (x1, y1)-(x2, y2)
517.         IF TextHandles(Handle).SavedBackground THEN
518.             blend = _BLEND
519.             _PUTIMAGE (x1, y1)-(x2, y2), TextHandles(Handle).SavedBackground
520.             _FREEIMAGE TextHandles(Handle).SavedBackground
521.             IF blend THEN _BLEND
522.         TextHandles(Handle).SavedBackground = imagehandle
523.         TextHandles(Handle).x1 = 0 'When the frames are hidden, we calculate our print position based off the hidden image
524.         TextHandles(Handle).y1 = 0 'So we'd start at point (0,0) as being top left
525.
526. SUB RestoreFrame (Handle AS INTEGER)
527.     IF TextHandles(Handle).HideFrame THEN 'only if we have a hidden frame do we have to worry about restoring it
528.         TextHandles(Handle).HideFrame = 0
529.         w = TextHandles(Handle).w
530.         h = TextHandles(Handle).h
531.         x1 = TextHandles(Handle).ScreenX
532.         y1 = TextHandles(Handle).ScreenY
533.         x2 = x1 + w - 1
534.         y2 = y1 + h - 1
535.         imagehandle = _NEWIMAGE(TextHandles(Handle).w, TextHandles(Handle).h, 32)
536.         blend = _BLEND
537.         _PUTIMAGE , 0, imagehandle, (x1, y1)-(x2, y2)
538.         _PUTIMAGE (x1, y1)-(x2, y2), TextHandles(Handle).SavedBackground ', 0, (0, 0)-(w, h)
539.         _FREEIMAGE TextHandles(Handle).SavedBackground
540.         IF blend THEN _BLEND
541.         TextHandles(Handle).SavedBackground = imagehandle
542.         TextHandles(Handle).x1 = x1 'When the frames are frames are restored, we need to recalculate our print position
543.         TextHandles(Handle).y1 = y1 'as we're no longer going over the image cooridinates, but the screen location of the top left corner instead.
544.
545. SUB MoveFrame (Handle AS INTEGER, x1 AS INTEGER, y1 AS INTEGER)
546.     'Only two coordinates here, so we'll be positioning our frames new movement by the top left corner.
547.     u = UBOUND(TextHandles)
548.     IF Handle < 1 OR Handle > u THEN ERROR 5: EXIT FUNCTION
549.     IF TextHandles(Handle).InUse = False THEN ERROR 5: EXIT FUNCTION
550.     HideFrame Handle
551.     TextHandles(Handle).ScreenX = x1
552.     TextHandles(Handle).ScreenY = y1
553.     RestoreFrame Handle
554.

For the second puzzle, where I was lazy and renamed the tirck and treat file to "tt.txt".

Feel free to change the internals as needed for different word search puzzles, with these lines:

Code: QB64: [Select]
1. CONST FileName\$ = "tt.txt"
2.
3.
4. REDIM SHARED WordGrid(0, 0) AS STRING * 1
5. REDIM SHARED YLines(0, 0) AS STRING
6. REDIM SHARED XLines(0, 0) AS STRING
7.
8. DIM SHARED SearchTerms(1) AS STRING
9. SearchTerms(0) = "TRICK": SearchTerms(1) = "TREAT"
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

bplus

• Forum Resident
• Posts: 5947
• B+ Knot again!
Re: Word Search
« Reply #4 on: October 19, 2018, 05:50:55 PM »
Hi Steve,

RE: the first post (you posted again as I was composing this reply)

Your count is low, (I get 44 bats counted (< 50%) when I run your program after I fix the file name :P ) I suspect you are NOT checking the 4 diagonal directions for words.

Code: QB64: [Select]
1. 6   7   8
2.  D  D  D
3.   R R R
4.    OOO
5. 5DROWORD1
6.    OOO
7.   R R R
8.  D  D  D
9. 4   3   2
10.

Let me know if you want to see my 71 line BAT counter, that is not generalized enough to do TRICK TREAT but with a few quick mods can easily. When you run mine, the BAT's flutter around the screen if you lean on the enter key.

SMcNeill

• QB64 Developer
• Forum Resident
• Posts: 3234
Re: Word Search
« Reply #5 on: October 19, 2018, 05:54:29 PM »
I wasn't checking diagonally.  :P

I'm used to up/down/left/right checking.   It's easy enough to add the other ways though, but that'll have to wait till later.   The wife says, "We're going shopping!"

/cry
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

bplus

• Forum Resident
• Posts: 5947
• B+ Knot again!
Re: Word Search
« Reply #6 on: October 19, 2018, 05:59:07 PM »
I give you a B+ for being the first responder here and the first to do verticals.

BTW, 630+ lines??? man aren't you the guy that got the pig code from 32 to 17 lines. ;D

I suspect you are re-purposing other code procedures, allot of them! ;D

SMcNeill

• QB64 Developer
• Forum Resident
• Posts: 3234
Re: Word Search
« Reply #7 on: October 19, 2018, 06:11:02 PM »
I give you a B+ for being the first responder here and the first to do verticals.

BTW, 630+ lines??? man aren't you the guy that got the pig code from 32 to 17 lines. ;D

I suspect you are re-purposing other code procedures, allot of them! ;D

Most of it is just an insertion of my TextFrame library, which lets us designate specific frames to print in, and 90% of that library isn't even used.

I just like the ease of being able to print in various sections of the screen, with automatic word-wrap, line scrolling, and hideable/moveable all set up and ready to go.

NewTextArea(0, 0, 400, _HEIGHT - 1, False)
ColorTextArea LeftFrame, _RGB32(255, 255, 255), _RGB32(0, 0, 128)
DrawTextArea LeftFrame

RightFrame = NewTextArea(401, 0, _WIDTH - 1, _HEIGHT - 1, False)
ColorTextArea RightFrame, _RGB32(255, 255, 255), _RGB32(0, 0, 0)
DrawTextArea RightFrame

Once the library is loaded, it's basically that easy to designate different text areas to print to.
« Last Edit: October 19, 2018, 06:13:10 PM by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

codeguy

• Forum Regular
• Posts: 180
Re: Word Search
« Reply #8 on: October 20, 2018, 12:31:41 AM »
did you know 8 items taken at a time from 26 items gives you 1562275 distinct combinations? How to find these distinct combinations, you ask? (Not the same as permutations)
Code: QB64: [Select]
1. n = 25
2. DIM array2combine(0 TO n) AS _UNSIGNED _BYTE '* could be the ascii values of letters - even strings if modified
3. FOR i = 0 TO n
4.     array2combine(i) = i + 1
5. r = 7
6. DIM result(0 TO r) AS _UNSIGNED _BYTE
7.
8. CombinationsNR array2combine(), r, LBOUND(array2combine), result(), combinations&
9. ' *_CLIPBOARD\$ = LTRIM\$(STR\$(combinations&))
10. PRINT "Combination("; n + 1; "taken "; r + 1; ") at a time."; combinations&
11.
The sub producing non-repeating combinations.
Code: QB64: [Select]
1. SUB CombinationsNR (array2combine() AS _UNSIGNED _BYTE, chosen AS LONG, startPosition AS LONG, result() AS _UNSIGNED _BYTE, combinations&)
2.     IF (chosen < 0) THEN
3.         combinations& = combinations& + 1
4.         FOR i = 0 TO UBOUND(result)
5.             PRINT result(i);
6.     FOR i = startPosition TO UBOUND(array2combine) - chosen
7.         result(UBOUND(result) - chosen) = array2combine(i)
8.         CombinationsNR array2combine(), chosen - 1, i + 1, result(), combinations&
9.

This may also help in your wordsearch.
« Last Edit: October 20, 2018, 12:44:23 AM by codeguy »

bplus

• Forum Resident
• Posts: 5947
• B+ Knot again!
Re: Word Search
« Reply #9 on: October 20, 2018, 09:38:31 AM »
Hi codeguy,

Like with WordCrack, I am not seeing how what you offer fits in with Word Search.

I am becoming very surprised how little the BASIC programmers I hang out with know of Word Search. But I guess people don't get daily newspapers as regularly as the old days. But it also makes sense, if you have BASIC to play with, why waste time with newspaper games like Sudoku, Crosswords, and WordSearch? ;-))

So anyway, codeguy, have you been following the Pig thread? I could use code to calculate frequency tables of dice combinations to calculate odds of dice coming up with 1's give n amount of dice thrown in a turn, eg throw 5 dice what are the chances of 1 di having a 1, 2 di having a 1, 3 di having a 1, 4 di having a 1 and all 5 di having a 1.

bplus

• Forum Resident
• Posts: 5947
• B+ Knot again!
Re: Word Search
« Reply #10 on: October 20, 2018, 10:00:30 AM »
Update: While you guys are working out your first version of Word Search code, or not ;-))  I have finally got the long and tedious method of "rotating" the array of letters to search using INSTR for the find word. I am sure that INSTR will work faster when all the strings are setup but it is complex / tricky to translate back to the Letters\$() array the position found with INSTR.

But, thanks to pulling the plug on the phone, I have it working for word list searching, at least the couple of examples I've tested.

Next up make the whole thing generic for any letters\$ array and Word List of find words up to say 20 x 20 grid and any amount of words you can jam into that array. Do this for BOTH methods, my first straight forward finder as described above and for the rotated arrays finder method. Also while doing this, add the capacity to find the word several times throughout the Letters\$() array and list the counts next to the Word Find List, so my Halloween BAT and TRICK TREAT puzzles would also work along with normal newspaper style Word Search puzzles.

So as TempodiBasic likes to say, "Thanks for reading!"

bplus

• Forum Resident
• Posts: 5947
• B+ Knot again!
Re: Word Search
« Reply #11 on: October 21, 2018, 11:50:15 PM »
OK done!

Included in the attached are 4 .bas files: 2 designed just for the Halloween Challenge of counting BAT in one Word Search Letter block and TRICK TREAT in the other.

A generic Word Search code v1 for any Word Search letter block up to 40 letters wide and 20 rows and a 48 max Word list (fitting it all in Screen 0 default).

v2 has v1 code to compare to the "Rotating Array Strings Search Method" I was curious about. The code there has number labels for the rows and columns of the letters array.

3 more Puzzle sets and a Read Me Notes txt file for more details.

« Last Edit: October 22, 2018, 12:08:59 AM by bplus »

bplus

• Forum Resident
• Posts: 5947
• B+ Knot again!
Re: Word Search
« Reply #12 on: October 27, 2018, 02:56:25 AM »
WS Editor coming along nicely. I have improved my message box and now created an inputBox\$() function.

Here is a snap of a new Treats and Tricks puzzle with a few more tricks and treats to count in direction rich puzzle plus a snap of new inputBox\$() in action for adding a word.

bplus

• Forum Resident
• Posts: 5947
• B+ Knot again!
Re: Word Search
« Reply #13 on: November 01, 2018, 10:33:21 PM »
First success with Rosetta Code Word Search Challenge, added a couple specs of my own:
Code: QB64: [Select]
1.    0 1 2 3 4 5 6 7 8 9
2.
3. 0   b p l u s m R y t t
4. 1   a u p u s o y O i h
5. 2   s s n o b n e S s u
6. 3   i h i i E s l p i h
7. 4   c T o h t a t a h T
8. 5   z o o a o n a i c A
9. 6   t C p n r t h c r n
10. 7   r n u h O o w y u r
11. 8   c t e d w o t D l a
12. 9   E r e g a e y b a c
13.
14.       1)      basic (0, 0) >>>---> 2      2)       plus (1, 0) >>>---> 0
15.      3)   monsanto (5, 0) >>>---> 2      4)     yeager (6, 9) >>>---> 4
16.      5)    whatley (6, 7) >>>---> 6      6)      lurch (8, 8) >>>---> 6
17.      7)       hoar (1, 3) >>>---> 1      8)        sup (4, 1) >>>---> 4
18.      9)        his (3, 4) >>>---> 5     10)        tin (4, 4) >>>---> 5
19.     11)        huh (9, 1) >>>---> 2     12)        sit (8, 2) >>>---> 6
20.     13)        car (9, 9) >>>---> 6     14)        hun (3, 7) >>>---> 4
21.     15)        cia (7, 6) >>>---> 6     16)        pat (2, 6) >>>---> 7
22.     17)        zoo (0, 5) >>>---> 0     18)        crt (0, 8) >>>---> 6
23.     19)        icy (7, 5) >>>---> 2     20)        ted (1, 8) >>>---> 0
24.     21)        nob (2, 2) >>>---> 0     22)        tow (6, 8) >>>---> 4
25.     23)        hip (9, 3) >>>---> 4     24)        cab (9, 9) >>>---> 4
26.     25)        lao (6, 3) >>>---> 3     26)        nrc (9, 6) >>>---> 4
27.     27)        bun (0, 0) >>>---> 1     28)        tty (9, 0) >>>---> 4
28.     29)        tun (1, 8) >>>---> 7
29.
30.

A tweak of word length limits and almost every run now:
Code: QB64: [Select]
1.    0 1 2 3 4 5 6 7 8 9
2.
3. 0   b p l u s g t b n R
4. 1   a a e c u O a i a k
5. 2   s l e n o n S f k i
6. 3   i d s a o o l E e n
7. 4   c T o b t a t g d T
8. 5   o l b e t s A r e e
9. 6   x i i t C i e s a l
10. 7   r m e s s v O l e m
11. 8   D r b l e a g u e x
12. 9   y a s i s a t s E c
13.
14.       1)      basic (0, 0) >>>---> 2      2)       plus (1, 0) >>>---> 0
15.      3)    celesta (9, 9) >>>---> 5      4)     stasis (7, 9) >>>---> 4
16.      5)   flattery (7, 2) >>>---> 3      6)     ribbon (0, 7) >>>---> 7
17.      7)      naked (8, 0) >>>---> 2      8)        doe (1, 3) >>>---> 1
18.      9)       mart (9, 7) >>>---> 5     10)       siva (5, 5) >>>---> 2
19.     11)       lise (1, 5) >>>---> 1     12)        lee (2, 0) >>>---> 2
20.     13)       ague (5, 8) >>>---> 0     14)       snug (2, 3) >>>---> 7
21.     15)        sex (7, 6) >>>---> 1     16)        kin (9, 1) >>>---> 2
22.     17)        ibm (3, 9) >>>---> 5     18)        coo (3, 1) >>>---> 1
23.     19)        gel (7, 4) >>>---> 1     20)        ban (7, 0) >>>---> 3
24.     21)        pal (1, 0) >>>---> 2     22)        lsi (3, 8) >>>---> 7
25.     23)        cox (0, 4) >>>---> 2     24)        kit (8, 2) >>>---> 5
26.     25)        elm (9, 5) >>>---> 2
27.
28.
« Last Edit: November 01, 2018, 10:54:43 PM by bplus »

bplus

• Forum Resident
• Posts: 5947
• B+ Knot again!
Re: Word Search
« Reply #14 on: November 03, 2018, 12:14:45 PM »
Oh hey Steve, your word generator gave me an idea! But it turns out I got a quicker file made by copy / paste off Wiki alpha listing of keywords (and some edits) st,

This works! (after I allowed words of length 2 to Puzzle Builder.)
Code: QB64: [Select]
1.    0 1 2 3 4 5 6 7 8 9
2.
3. 0   b p l u s C G O D q
4. 1   a A N D L W b N G S
5. 2   s V Q E F A E 6 O I
6. 3   i O A \$ D I M 4 O L
7. 4   c R \$ T _ T q C O S
8. 5   T U P Y N A T b V O
9. 6   I K E Y E L T I N 6
10. 7   X P O K E K E A 4 P
11. 8   E S P C A W N T N q
12. 9   _ R E S I Z E I b 2
13.
14. Directions >>>---> 0 = East, 1 = SE, 2 = South, 3 = SW, 4 = West, 5 = NW, 6 = North, 7 = NE
15.
16.      These are the items from Just QB64 words.txt used TO build the puzzle:
17.
18.       1)      basic (0, 0) >>>---> 2      2)       plus (1, 0) >>>---> 0
19.      3)        KEY (1, 6) >>>---> 0      4)     INKEY\$ (7, 9) >>>---> 5
20.      5)     _ATAN2 (4, 4) >>>---> 1      6)      CLEAR (5, 0) >>>---> 3
21.      7)       WAIT (5, 1) >>>---> 2      8)      IOCTL (9, 2) >>>---> 3
22.      9)       LONG (9, 3) >>>---> 5     10)    _RESIZE (0, 9) >>>---> 0
23.     11)        LET (5, 6) >>>---> 1     12)      _EXIT (0, 9) >>>---> 6
24.     13)       MID\$ (6, 3) >>>---> 4     14)        AND (1, 1) >>>---> 0
25.     15)        EQV (3, 2) >>>---> 4     16)       VIEW (8, 5) >>>---> 3
26.     17)       POKE (1, 7) >>>---> 0     18)        SPC (1, 8) >>>---> 0
27.     19)        COS (7, 4) >>>---> 0     20)        ATN (2, 3) >>>---> 1
28.     21)        SGN (9, 1) >>>---> 4     22)        END (6, 2) >>>---> 7
29.     23)        PUT (2, 5) >>>---> 4     24)        ON (9, 5) >>>---> 3
30.     25)        IF (5, 3) >>>---> 5     26)        AS (4, 8) >>>---> 3
31.     27)        DO (8, 0) >>>---> 4     28)        OR (1, 3) >>>---> 2
32.     29)        INP (7, 9) >>>---> 7
33.
34.      These are the items from Just QB64 words.txt found embedded in the puzzle:
35.
36.       1)     _ATAN2 (4, 4) >>>---> 1      2)      _EXIT (0, 9) >>>---> 6
37.      3)    _RESIZE (0, 9) >>>---> 0      4)        AND (1, 1) >>>---> 0
38.      5)        AS (4, 8) >>>---> 3      6)        ATN (2, 3) >>>---> 1
39.      7)      CLEAR (5, 0) >>>---> 3      8)        COS (7, 4) >>>---> 0
40.      9)        DIM (4, 3) >>>---> 0     10)        DO (8, 0) >>>---> 4
41.     11)        END (6, 2) >>>---> 7     12)        EQV (3, 2) >>>---> 4
42.     13)       EXIT (0, 8) >>>---> 6     14)        IF (5, 3) >>>---> 5
43.     15)     INKEY\$ (7, 9) >>>---> 5     16)        INP (7, 9) >>>---> 7
44.     17)      IOCTL (9, 2) >>>---> 3     18)        KEY (1, 6) >>>---> 0
45.     19)        KEY (5, 7) >>>---> 5     20)        KEY (1, 6) >>>---> 0
46.     21)        KEY (5, 7) >>>---> 5     22)        LET (5, 6) >>>---> 1
47.     23)       LONG (9, 3) >>>---> 5     24)       MID\$ (6, 3) >>>---> 4
48.     25)        ON (7, 0) >>>---> 2     26)        ON (8, 2) >>>---> 5
49.     27)        ON (9, 5) >>>---> 3     28)        OR (1, 3) >>>---> 2
50.     29)       POKE (1, 7) >>>---> 0     30)        PUT (2, 5) >>>---> 4
51.     31)        SGN (9, 1) >>>---> 4     32)        SPC (1, 8) >>>---> 0
52.     33)        TAN (6, 5) >>>---> 4     34)        TAN (6, 6) >>>---> 1
53.     35)       VIEW (8, 5) >>>---> 3     36)       WAIT (5, 1) >>>---> 2
54.
55.