Author Topic: My First InForm Program - Trackword  (Read 46501 times)

0 Members and 1 Guest are viewing this topic.

FellippeHeitor

  • Guest
Re: My First InForm Program - Trackword
« Reply #30 on: August 08, 2018, 02:19:22 pm »
Does QB64 Team have another meaning?

Well, kind of. Luke, STxAxTIC and I maintain qb64.org under that name, so I guess that's what you meant after all?
« Last Edit: August 08, 2018, 02:31:23 pm by FellippeHeitor »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My First InForm Program - Trackword
« Reply #31 on: August 08, 2018, 04:51:23 pm »
Does QB64 Team have another meaning?

Well, kind of. Luke, STxAxTIC and I maintain qb64.org under that name, so I guess that's what you meant after all?

Hi Fellippe,

Well I know you 3 above in quote as Odin from here of course, and I remember you using the "QB64 Team" name with the Christmas Challenge on Facebook (from NET) and assumed you were referencing all the people who submitted code, STxAxTIC and Luke had not participated then with that as I recall.

I am totally unfamiliar with Twitter stuff and link, so I didn't know.

If "QB64 Team" name is "taken", I am sure we can come up with something else that is satisfactory to all.

Maybe "Team QB64"? ;-))

 
Append:
Oh it was Happy 2017 thing not Christmas:

BTW, only time I spent any time on Facebook was to check that 2017 thing out.
Happy 2017 from QB64Team.PNG
* Happy 2017 from QB64Team.PNG (Filesize: 12.13 KB, Dimensions: 375x241, Views: 558)
« Last Edit: August 08, 2018, 05:10:38 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: My First InForm Program - Trackword
« Reply #32 on: August 08, 2018, 06:13:51 pm »
Maybe "Team QB64"? ;-))

How about The QBCoders?  With a nice QBC logo drawn over by a 64 for a pretty visual.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My First InForm Program - Trackword
« Reply #33 on: August 08, 2018, 07:12:04 pm »
Maybe QB64 Synergy

the interaction or cooperation of two or more organizations, substances, or other agents to produce a combined effect greater than the sum of their separate effects.

Nice goal.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: My First InForm Program - Trackword
« Reply #34 on: August 10, 2018, 04:52:38 am »
Nearly ready to update program with mods as discussed above.

Fellippe, you mentioned making the program portable which is a good idea.

If you wanted to make it more portable, you'd need to include 4 extra files in your zip, so that one wanting to run your program but not interested in the full InForm package could still do so:

    InForm/InForm.ui
    InForm/xp.uitheme
    InForm/InFormVersion.bas
    falcon.h


I tried moving the four files into the Trackword folder, and changed
'$INCLUDE:'..\InForm\InForm.ui'
'$INCLUDE:'..\InForm\xp.uitheme'

to
'$INCLUDE:'InForm.ui'
'$INCLUDE:'xp.uitheme'

The IDE was happy, but failed C++ compilation.  As you know I like to supply all my work in a folder which can be deleted when no longer required - it makes it easier than trying to remove individual files from the QB64 directory.  At the moment, then, I haven't learnt how to make the program independent of InForm.

Richard

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: My First InForm Program - Trackword
« Reply #35 on: August 10, 2018, 05:12:37 am »
I'm somewhat bewildered by the above discussion about names to credit.  I hope that nobody will mind if my code starts with lines:
': Trackword Solver by QWERKEY (Richard Notley) 09-08-2018
': bplus created search algorithms
': This program uses
': InForm - GUI library for QB64 - Beta version 7
': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - @fellippeheitor
': https://github.com/FellippeHeitor/InForm

The first line is untrammelled vanity by Qwerkey.
The second maintains bplus's privacy.
The next lines come automatically from the InForm compilation, and rightly acknowledge Fellippe's magnificent work.
We acknowledge the QB64 Team (Team QB64?) by default.

Incidentally, I'm slightly mystified by the Team names "Odin" (I am picturing a stereotypic wise old Nordic god) and "The Librarian" (I am picturing a stereotypic bespectacled quinquagenarian spinster)?

Richard

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My First InForm Program - Trackword
« Reply #36 on: August 10, 2018, 09:37:19 am »
Hi Richard,

There are 4 files to be included in the InForm project folder (and YES! A folder is best way to distribute.)

These are over and above the minimal two you develop for your particular app.

Your folder still needs the falcon.h and the InForm.bas file you created your InForm .bas and .frm files with.
Fellippe called that one InFormVersion.bas (not to be confused with the .bas file you create).

I think the falcon.h file might have to be stored in same folder as the QB64.exe version you are using. It is hard to tell because that is where mine is. I suppose I could test by renaming and seeing if the falcon.h file works from the project folder.

These 4 files are needed to reconstruct and compile the .exe from QB64 so that the exe is for the users platform.


Also the Binary search routine:
When I tested for differences between / and \ ( no difference) I did discover I did not set the Lo low enough and the Hi high enough at  the start of the search, did you catch that when rewriting the code? If you missed it the first and last words from the dictionary will not be "found" by the function of that name and it will return a false false (a 0 when it should return 1 for found).
« Last Edit: August 10, 2018, 09:53:02 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My First InForm Program - Trackword
« Reply #37 on: August 10, 2018, 10:19:23 am »
Confirmed:

On my system I had a folder with the falcon.h file on same level as .bas for app and also in the Inform subfolder of the project.
I renamed my falcon.h in my QB64.exe folder falconX.h and the app would not run, but would run when I renamed the falcon.h in folder with QB64.exe.

So those instructions might also be included in the project folder distribution: "Move (or copy) the falcon.h file to the same folder as QB64.exe if you don't already have one there."
« Last Edit: August 10, 2018, 10:22:48 am by bplus »

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: My First InForm Program - Trackword
« Reply #38 on: August 11, 2018, 05:46:00 am »
The final version is now ready, and I confirm bplus's observation that the file falcon.h needs to be in the QB64 folder, but no other part of InForm needs to be present.

The bplus search method gives a much improved search time, now about 0.1s.  This compares to 0.05s which the full bplus method gives.  My sort method for the found words slows it down a little and Inform increases the time by a tiny fraction.  Even on a slow machine of mine it's pretty instantaneous.  We are there!

I thought that I might try to understand the binary search method in detail, and so I went to Wikipedia's expert where the following is given:

Procedure

Given an array A of n elements with values or records A0, A1, ..., An-1, sorted such that A0 = A1 = ... = An-1, and target value T, the following subroutine uses binary search to find the index of T in A.

1.    Set L to 0 and R to n - 1.
2.    If L > R, the search terminates as unsuccessful.
3.    Set m (the position of the middle element) to the floor, [the greatest integer less than or equal to], (L + R)?/?2.
4.    If Am < T, set L to m + 1 and go to step 2.
5.    If Am > T, set R to m - 1 and go to step 2.
6.    Now Am = T, the search is done; return m.

This iterative procedure keeps track of the search boundaries with the two variables. The procedure may be expressed in pseudocode as follows, where the variable names and types remain the same as above, floor is the floor function, and unsuccessful refers to a specific variable that conveys the failure of the search.

Our dictionary array has elements from 1 to 155237 (rather than from "0 to n-1"), so just add 1 to everything.

Then, the following routine (which I have always used in the past) follows this procedure exactly:

Code: QB64: [Select]
  1. Located` = False: P0& = 1: P100& = Entries&
  2. WHILE P0& <= P100& AND NOT Located`
  3.         P50& = INT((P0& + P100&) / 2)
  4.         GET #4, P50&
  5.         InWord$ = RTRIM$(Lex$)
  6.         IF Tt$ = InWord$ THEN
  7.                 Located` = True
  8.         ELSEIF Tt$ > InWord$ THEN
  9.                 P0& = P50& + 1
  10.         ELSE
  11.                 P100& = P50& - 1
  12.         END IF
  13.  

You can see that it works by thinking through an array with 1 to 4 elements and then with 1 to 5 elements.  So, I have used this method in the search function instead of bplus's.  In the actual Trackword program, the BIT variable Located` is replaced by a BYTE variable Located%% as BIT variables are not successfully transferred to/from Functions or Subroutines.

I constructed a program which created an ordered dictionary file with elements 1 to 150,000 and then checked that every element is correctly found and that any word between every element is not found and that a word before and a word after the dictionary elements is not found.

The Wikipedia instruction is that rounding down must be used (as does this function), but I think that because of the P0& = P50& + 1 and P100& = P50& - 1 statements, rounding up also probably works.  Anyway, I'm confident that we've done it correctly.

The simplest procedure for me will be to replace the User Manual in the first section of this post with my updated version, but there is no "Modify" procedure on this website.  Is there a way to modify what's already there?  If I've missed the obvious in usage of the site, I apologise.

Richard

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My First InForm Program - Trackword
« Reply #39 on: August 11, 2018, 09:44:17 am »
Hi Qwerkey,

Code: QB64: [Select]
  1. The final version is now ready,...

Remember you don't need all of the 4 files Fellippe listed but someone who doesn't have InForm does need all 4 files and to move the Falcon.h to same folder as QB64.exe as mentioned before but doesn't hurt to repeat.

Are you still using disk file access for the Binary search?

Just post the code, forget about modifying a previous post. (Can you tell I am eager to test code?)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My First InForm Program - Trackword
« Reply #40 on: August 11, 2018, 11:01:18 am »
I see a number of improvements in this over the Binary search code I had posted:

Located` = False: P0& = 1: P100& = Entries&  '<<< this starts with Lo one step higher and Hi one step lower
WHILE P0& <= P100& AND NOT Located`
   P50& = INT((P0& + P100&) / 2)              '<<< this is one less calculation than what I had and I wish now I had started with average instead of average of difference! (It would have saved me from the f... comment!
   GET #4, P50&                                       '<<< this, disk file access I still think is slower but are you using that in TrackWord?
   InWord$ = RTRIM$(Lex$)
   IF Tt$ = InWord$ THEN
      Located` = True
   ELSEIF Tt$ > InWord$ THEN
      P0& = P50& + 1                            '<<< ah! a step closer and why not!?
   ELSE
      P100& = P50& - 1                          '<<< ah! also a step closer and why not!?
   END IF
WEND

Plus all the variables are typed better.


Append:
An improvement on this code might be to exit the sub as soon as the word is matched and the function return value is set.

With that done the line
WHILE P0& <= P100& AND NOT Located`

can be reduced to just:
 WHILE P0& <= P100&

Which is one less logical calculation check and one less variable needed: Located`
« Last Edit: August 11, 2018, 11:52:17 am by bplus »

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: My First InForm Program - Trackword
« Reply #41 on: August 11, 2018, 11:55:50 am »
Apologies, bplus.  You may use the existing User Manual.  It will have the correct download pointer.  The updated Manual just has updated instructions (InForm not needed, falcon.h copying required).  Just overwrite everything in the Trackword folder.  The file "HalfABC.rnd" is equivalent to" Master Snakes.txt".  The updated Manual will be clearer for new users.

Of course this program uses dictionary searching within an array and not from the disc file (pardon me for the confusion).  So, the program load time is now a little longer, but not really noticeable.  However, I still use my old method for sorting the found words (which is the part that slows it down a little).

I got the search code from some "standard files" that came with Quickbasic 2.0.  Not mine at all.

Richard

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My First InForm Program - Trackword
« Reply #42 on: August 11, 2018, 12:02:21 pm »
Oh ha! I had forgotten, the link to the download files was in the manual. OK thanks!

Append (why start another reply?):
Code: QB64: [Select]
  1. I got the search code from some "standard files" that came with Quickbasic 2.0.  Not mine at all.

This may explain why EXIT FUNCTION was not used and the flag, Located`, was used.

« Last Edit: August 11, 2018, 12:12:54 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My First InForm Program - Trackword
« Reply #43 on: August 11, 2018, 12:30:54 pm »
Yeah! Works right out of the box.

I see a surprise! The number snakes cut in half, you are using word reverse for the symmetric snake that has letters reversed, so from the Master Snakes.txt file you removed all the symmetric reverse snakes. Nice touch!

Now here is the million dollar question (well 25 cents at least) what 9 letter word gives us the most words made from snakes of 3x3 grid? I bet this has been found already, if I know my word enthusiasts.
« Last Edit: August 11, 2018, 12:32:58 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My First InForm Program - Trackword
« Reply #44 on: August 11, 2018, 05:54:52 pm »
And the results are in:

Max words for nine letter word.PNG
« Last Edit: August 11, 2018, 08:34:53 pm by odin »