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

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
My First InForm Program - Trackword
« on: August 06, 2018, 05:32:00 am »
This is my first program created with InForm.  Firstly, I must reiterate members' comments on what a superb achievement is Fellippe's work in creating InForm.  I have previously attempted to code in Microsoft's Visual Basic 6 (just about usable with no graphics available) and then their Visual Studio (completely unworkable).  Fellippe has achieved everything that we should have desired from the Microsoft stuff with much easier usage and integrated into all that we wish to do in QB64.  Hats off again to Fellippe.

The program provides all the solutions to a particular kind of puzzle (Trackword) which appears in a specialist magazine.  Many years ago, I originally created a program for this in QuickBasic 2, and I have used this as a basis for learning to use InForm.  InForm is so user-friendly that there was only a little work needed to convert from the original text-only program.  In fact, the programming difficulty and interest was in the original work in creating the algorithm which finds all the solutions (and only those which are valid).  Looking at the code now, it is quite difficult to work out how the algorithm works exactly.  I must have been brighter all those years ago.

Should you be interested to run this specialist program, you will need to download the pdf.  The solving routine needs tens of thousands of computational cycles and needs a modern fast machine.  A slower machine will give a noticeable pause before answers are displayed.  I should have programmed a progress bar, but I thought that this little starter project did not justify it.

Richard

[Edit:  Manual updated 16/2/19]
screenshot.jpg
* screenshot.jpg (Filesize: 57.37 KB, Dimensions: 426x606, Views: 590)
* Trackword User Manual.pdf (Filesize: 73.09 KB, Downloads: 803)
« Last Edit: February 23, 2019, 10:33:58 am by Qwerkey »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: My First InForm Program - Trackword
« Reply #1 on: August 06, 2018, 09:03:53 am »
Hi Qwerkey,

Once again my system is hung by having to remove ../ from include files but after that everything worked great!

33 words found in "Trackword" word.

Very nice use of Inform!

So it's not just the permutations of 9 letters but all the permutations of letters up to 9 and then checking it's a word.
But you probably don't check all permutations (because on my system that takes a while just to do 9 letters) but just find words with same group of letters? Darn quick finds anyway!
« Last Edit: August 06, 2018, 12:44:11 pm by odin »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: My First InForm Program - Trackword
« Reply #2 on: August 06, 2018, 09:20:40 am »
Wait, it could probably be done with one pass through dictionary!

Just check each word to see if it has same letters as in the starting 9.

That algo might be same as bulls and cows (but only checking cows), except you can quit word as soon as there is no matching letter.
« Last Edit: August 06, 2018, 12:44:20 pm by odin »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: My First InForm Program - Trackword
« Reply #3 on: August 06, 2018, 09:35:22 am »
oops... I just tried BPLUSLOOPS and neither PLUS nor LOOP nor LOOPS came up but with LOOPSBPLUS, PLUS did come up.

I am going dig up my algo for counting cattle.

EDIT double check BPLUSLOOP no loop, loops or plus, but LOOPBPLUS is good!
« Last Edit: August 06, 2018, 12:44:27 pm by odin »

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Re: My First InForm Program - Trackword
« Reply #4 on: August 06, 2018, 09:38:57 am »
Hi bplus, thanks for trying it.  I honestly thought that this was so specialist (specific to me) that nobody else would want to try it - I just put it here for reference.

Wait, it could probably be done with one pass through dictionary!

Just check each word to see if it has same letters as in the starting 9.

That algo might be same as bulls and cows (but only checking cows), except you can quit word as soon as there is no matching letter.

The puzzle is specific in that  the word has to snake through the grid, so letter order is specific.  I am spending some time to speed up the search algorithm, so any additional ideas will be gratefully accepted.  The computing time time taken up forming all the 10,256 allowed letter combinations, not so much checking the dictionary.

The ../ which I put (was not in Fellippe's original), I thought was necessary because of the /Trackwork extra folder layer and I thought the ../ wasrequired  to get back to the QB64 root folder.  Another thing that I have failed to understand.  I shall stand in the corner with a pointed hat on.

Richard
« Last Edit: August 06, 2018, 12:44:34 pm by odin »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: My First InForm Program - Trackword
« Reply #5 on: August 06, 2018, 09:46:56 am »
Oh sorry, I was not familiar with game, so the word has to appear in the grid in some order ie "snake through grid"?
« Last Edit: August 06, 2018, 12:44:40 pm by odin »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: My First InForm Program - Trackword
« Reply #6 on: August 06, 2018, 10:03:16 am »
Quote
I am spending some time to speed up the search algorithm, so any additional ideas will be gratefully accepted.

Hi again,

Steve has a Spellcheck program here:
http://qb64.freeforums.net/thread/33/spellcheck

I will bet it is pretty darn quick!

Do the words have to appear like in WordSearch in the grid, ie backwords or forwards, across, up/down or diagonal?
« Last Edit: August 06, 2018, 12:45:02 pm by odin »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: My First InForm Program - Trackword
« Reply #7 on: August 06, 2018, 10:11:42 am »
Oh they have to connect: http://happysoft.org.uk/countdown/trackword.php

EDIT: Oh and the speed bump is NOT looking up the words but running the snakes.
« Last Edit: August 06, 2018, 12:45:10 pm by odin »

FellippeHeitor

  • Guest
Re: My First InForm Program - Trackword
« Reply #8 on: August 06, 2018, 12:57:54 pm »
This is my first program created with InForm.  Firstly, I must reiterate members' comments on what a superb achievement is Fellippe's work in creating InForm.  I have previously attempted to code in Microsoft's Visual Basic 6 (just about usable with no graphics available) and then their Visual Studio (completely unworkable).  Fellippe has achieved everything that we should have desired from the Microsoft stuff with much easier usage and integrated into all that we wish to do in QB64.  Hats off again to Fellippe.

Thank you so much, Richard! That makes me want to go even further in the development of InForm, I really appreciate it.

The program provides all the solutions to a particular kind of puzzle (Trackword) which appears in a specialist magazine.  Many years ago, I originally created a program for this in QuickBasic 2, and I have used this as a basis for learning to use InForm.  InForm is so user-friendly that there was only a little work needed to convert from the original text-only program.  In fact, the programming difficulty and interest was in the original work in creating the algorithm which finds all the solutions (and only those which are valid).  Looking at the code now, it is quite difficult to work out how the algorithm works exactly.  I must have been brighter all those years ago.

Should you be interested to run this specialist program, you will need to download the pdf.  The solving routine needs tens of thousands of computational cycles and needs a modern fast machine.  A slower machine will give a noticeable pause before answers are displayed.  I should have programmed a progress bar, but I thought that this little starter project did not justify it.

Richard

I love it! You seem to have gone through InForm's wiki since you used many methods we didn't even get to discuss over email. Great job there.

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

One last thing I forgot to ask: Did you download the zip package for InForm or did you use the installer?
« Last Edit: August 06, 2018, 01:10:24 pm by FellippeHeitor »

Offline Aurel

  • Forum Regular
  • Posts: 167
Re: My First InForm Program - Trackword
« Reply #9 on: August 06, 2018, 03:06:24 pm »
Nice
I don't know that qb64 can produce" native" GUI apps.
So i s that wrapped trough sdl libs or is used native wrapper to win32 api calls( CDCL).
Why i babeling about this is that i have written almost complete set of GUI funcs but writtebn in o2
BUT can be build into one dll.
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: My First InForm Program - Trackword
« Reply #10 on: August 07, 2018, 01:16:34 am »
Quote
The puzzle is specific in that  the word has to snake through the grid, so letter order is specific.  I am spending some time to speed up the search algorithm, so any additional ideas will be gratefully accepted.  The computing time time taken up forming all the 10,256 allowed letter combinations, not so much checking the dictionary.

Hi Qwerkey,

I have worked out a 2 part system:
Part 1 builds a one time only, Master Snakes.txt file, that contains the 10256 letter snakes that can be formed on the 3x3 grid.
The snakes are listed as strings of square numbers. This is done once for all time, no need to do again.

Part 2:
Loads the snake patterns, the dictionary words and gets down to business by translating the square numbers to letters in the given word grid or just a 9 letter word string. With the word formed it checks the word list with binary search and stores all matches in array that is sorted and then displays and recounts only unique words.

You might like to see the little recursive gem that is only about a dozen lines called "build2" that gets all snake patterns for each square of grid, the heart of the whole thing.

TrackWord LOOPBPLUS.PNG
* TrackWord LOOPBPLUS.PNG (Filesize: 62.13 KB, Dimensions: 1170x594, Views: 510)
* Recursive Algo and 2 part TrackWord pack.zip (Filesize: 443.28 KB, Downloads: 291)

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Re: My First InForm Program - Trackword
« Reply #11 on: August 07, 2018, 04:03:35 am »
Quote
The puzzle is specific in that  the word has to snake through the grid, so letter order is specific.  I am spending some time to speed up the search algorithm, so any additional ideas will be gratefully accepted.  The computing time time taken up forming all the 10,256 allowed letter combinations, not so much checking the dictionary.

Hi Qwerkey,

I have worked out a 2 part system:
Part 1 builds a one time only, Master Snakes.txt file, that contains the 10256 letter snakes that can be formed on the 3x3 grid.
The snakes are listed as strings of square numbers. This is done once for all time, no need to do again.

Part 2:
Loads the snake patterns, the dictionary words and gets down to business by translating the square numbers to letters in the given word grid or just a 9 letter word string. With the word formed it checks the word list with binary search and stores all matches in array that is sorted and then displays and recounts only unique words.

You might like to see the little recursive gem that is only about a dozen lines called "build2" that gets all snake patterns for each square of grid, the heart of the whole thing.

bplus, wow you've certainly taken an interest in this.  I have just started a method where the 10,256 confiurations are created then used (and maybe on 5,128 and then reverse the word), so I'll certainly look inot what you've done.

Thanks very much, Richard

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Re: My First InForm Program - Trackword
« Reply #12 on: August 07, 2018, 04:08:05 am »
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:

One last thing I forgot to ask: Did you download the zip package for InForm or did you use the installer?

Fellippe, I'll look into the portability thing.  That looks more flexible.  I've more reading of the wiki to do - you did a great job with that, as well.  I used the Installer from the Website.

Richard

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Re: My First InForm Program - Trackword
« Reply #13 on: August 07, 2018, 05:53:39 am »
A quick look into timings goes as follows:

Existing method (non-Inform, tetxt only): 0.768s
Pre-prepared (as bplus, but my coding): 0.69s
Existing method in Inform: 1.15s

So, firstly changing to InForm, but exactly the same search/check routine slows the process down (not quite sure why).  Secondly, there is a slight improvement with the pre-prepared method, but I've not yet optimised this or used bplus exact method.

Richard

FellippeHeitor

  • Guest
Re: My First InForm Program - Trackword
« Reply #14 on: August 07, 2018, 06:20:24 am »
Try adding this before your search routine:

Code: QB64: [Select]
  1.     TIMER(__UI_EventsTimer) OFF
  2.     TIMER(__UI_RefreshTimer) OFF

Just don't forget to turn those timers back on after you're done:

Code: QB64: [Select]
  1.     TIMER(__UI_EventsTimer) ON
  2.     TIMER(__UI_RefreshTimer) ON

InForm's events and repaint routines are timer-based and that surely takes up some cycles. The tradeoff of the above method is that your interface will remain unresponsive while the calculations take place. You must judge if the speed gain is considerable enough to justify the tweak.