|
Post by Rod on Dec 6, 2021 5:10:41 GMT -5
I am a bit late starting this but I wanted a Scrabble assistant that would help track the scoring and verify gameplay. DKL's word puzzle set me going. Anatoly helped with the binary selection of subsets. So this is the first tentative step. Give it a word, it creates a sorted anagram and subsets of that anagram. This will be used to find all possible word combinations from a set of letters in the dictionary. I hope!
dim w$(15) dim s$(100)
numberOfAnagrams=subset(anagram$("CARET"))
for n= 1 to numberOfAnagrams print s$(n) next wait
function subset(w$) redim s$(100) ns=1 n=len(w$) for i = 0 to 2^n-1 subset$="" for j = 0 to n-1 if i and (2^j) then subset$=subset$+mid$(w$,j+1,1) next if len(subset$)>1 then s$(ns)=subset$ : ns=ns+1 next sort s$(,1,ns subset=ns end function
function anagram$(w$) l=len(w$) redim w$(l) for i= 1 to l w$(i)=mid$(w$,i,1) next ag$="" sort w$(,1,l for i= 1 to l ag$=ag$+w$(i) next anagram$=ag$ end function
|
|
|
Post by dan1101 on Dec 7, 2021 14:17:14 GMT -5
It took me a while to realize that the output represents all the possible UNIQUE LETTER SETS, rather than all the possible anagrams, which would be a much longer list.
I am interested to see where you are going with this. The next step might be to rearrange each of the letter sets into all their possible combinations. For example, in the case of CARET, it produces the letter set ACER, which would then need to be rearranged into ACRE, CARE, RACE, etc.
By the way, if you use a test word with more than six letters you need to increase the redim s$(100). A ten-letter word produces over 1000 unique letter sets.
|
|
|
Post by Rod on Dec 7, 2021 15:33:42 GMT -5
Yes, sorting is the key to all of this. Firstly I sort the letters of the initial word. This creates an ordered anagram that will easily match other ordered anagrams of other words using similar letters. Then I get all subsets of the ordered anagram so that I may find shorter words on a similar basis. This list of ordered anagrams is itself sorted.
I also have the dict.file in two columns, the word and it’s ordered anagram, sorted in anagram order. Now all similar anagrams are side by side. I can now check the list against the dict.file moving through the file just once checking A against A then B against B and so on.
Net result is all possible words from a set of letters in moments.
I have it working with arrays but because of the problem specifying the array dimension I have decided to pass the lists as strings . The size is less important then.
Will post code soon and all will become clear.
|
|
|
Post by Rod on Dec 8, 2021 5:05:28 GMT -5
This is where I am with the graphics. I have no game logic in the graphics code. All that can be done right now is to drag and drop tiles. The board is created and an array holds the multipliers. Also the bag of tiles has been created, shuffled and the first seven drawn from the bag. It is a sprite based solution and works well. I have also included subset.bas in the .zip and this is the code that finds matching words. It returns the words in w$() sorted alphabetically. It takes about fifteen seconds to find the words on my PC. The dictionary that DKL linked to has been processed and now exists as a list of words and ordered anagrams. 270,000 words or more. Feel free to add whatever game code you like and have a play with the graphics. It will be fun to see what folks might add over the holidays. The zip file linkClicking this link will get a .zip downloaded to your downloads directory. Navigate to downloads directory click on the .zip and then select extract all. You will be allowed to choose a directory to extract to. The zip creates a ScrabbleAssist folder in that directory, the .bas and resource files are all contained within this folder. Once you have played about, delete the folder and your PC will be completely clean again.
|
|
|
Post by Rod on Dec 8, 2021 7:07:47 GMT -5
This is the subset.bas code. You give it a set of letters, it then creates an ordered anagram of these letters. So RACE becomes ACER. The ordered anagram is then easily compared to other ordered anagrams CARE also becomes ACER, so we just need to compare the ordered anagrams to find matches. Another bonus is that if the ordered anagrams are themselves in alphabetical order then all similar anagrams are listed one after the other. This speeds up finding them enormously.
On top of that I break the letters down into subsets. I do this by using a binary representation of the letters, 0000 which cycles 0001 0010 0011 and so on. 0 means ignore the letter 1 means include it, thus creating subsets of the characters. Now we are also able to find shorter words that can be constructed from the letters.
The final step is to search in the dictionary which is a two column file containing 270000+ words and their ordered anagram, all held in anagram order. so AA first and ZZZ last. Now we take the first ordered anagram made from the letters and find it in the file, since we are in alpha order Axx is found first, if we exhaust that we start looking for Bxx and so on down the file. The benefit is that we pass through the file once and once only to find all possibilities.
All in all quite a an impressive program. Created on the inspiration of DKL and with help from Anatoly. Feel free to mess about bug hunt and put it to good use creating any game you wish.
dim w$(10)
nw=find(subset$(anagram$("CONCERT"))) for i=1 to nw print w$(i) next wait
function subset$(w$) print "Finding ordered anagram subsets" n=len(w$) for i = 0 to 2^n-1 sub$="" for j = 0 to n-1 if i and (2^j) then sub$=sub$+mid$(w$,j+1,1) next if len(sub$)>1 then subset$=subset$+sub$+" " :ns=ns+1 next redim w$(ns) for i=1 to ns w$(i)=word$(subset$,i," ") next sort w$(,1,ns subset$="" for i=1 to ns subset$=subset$+w$(i)+" " next
end function
function anagram$(w$) print "Building ordered anagram" l=len(w$) redim w$(l) for i= 1 to l w$(i)=mid$(w$,i,1) next ag$="" sort w$(,1,l for i= 1 to l ag$=ag$+w$(i) next anagram$=ag$ end function
function find(w$) print "Seeking ordered anagrams in dictionary" open "scrabbledict.txt" for input as #1 i=1 ww$=word$(w$,i," ") while ww$<>"" do line input #1,l$ wa$=trim$(word$(l$,2,chr$(9))) loop while wa$<ww$
if wa$=ww$ then wl$=wl$+trim$(word$(l$,1,chr$(9)))+" " :find=find+1
do line input #1,l$ wa$=trim$(word$(l$,2,chr$(9))) if wa$=ww$ then wl$=wl$+trim$(word$(l$,1,chr$(9)))+" " : find=find+1 loop while wa$=ww$ i=i+1 ww$=word$(w$,i," ") wend close #1 redim w$(find) for i=1 to find w$(i)=word$(wl$,i," ") next sort w$(,1,find print "Search complete." end function
Just to add, running this on my new Windows PC takes 15 seconds for CONCERT. Running it on my iMac M1 under Parallels takes a lot longer, perhaps a minute and a half, so your delay will vary.
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on Dec 9, 2021 1:23:52 GMT -5
HOW....love that Rod! It looks great and exactly what I need to peruse, in order to help me with a few new ideas I have for my next creation! LOL I'm certainly going to have fun searching through your code and learning about sprites and how to set up grids etc I've just added scrabble tile bitmaps to my word puzzle game, so I'm interested to learn how you did yours.
I'm glad the Dictionary came in handy.FYI - running the subset on 'CONCERT' took 5 sec for my comp. It took the same amount of time doing the same search in my Anagram programme V2. Many Thanks PS Hope you enjoyed the Scottish Countryside on your recent travels.
|
|
|
Post by Rod on Dec 21, 2021 7:20:37 GMT -5
Ok, too near the holidays to do much more. This is just a view of where I am. This isn't going to be a complete Scrabble engine. It is intended to help play the game by placing the tiles, checking the words and counting players scores. I envisage using my touch screen tablet in place of the real board and paper dictionary. I still have lots to do, as of now you can move tiles and have the word checked but it does not as yet go on to the next player. Many bugs to squash. This is the latest zip
|
|
|
Post by Rod on Dec 23, 2021 13:42:39 GMT -5
I now have it playing player to player and counting and displaying their scores.
However I still need to code in the crossword checking of other words created in the opposite direction of play.
So sounds complex but it is just an iterative step, finding the played tiles on the main word and then checking if it creates a new complete word in the opposite plane!
Might take a while!
|
|
|
Post by Rod on Jan 3, 2022 7:01:41 GMT -5
There is an updated file here Now you can drag the tiles about and rearrange them. You must follow the normal rules of Scrabble. If you think you have a word legally placed then click on play and you will either get points or be told it is an illegal word. The next players tiles are then shown. The current player is shown in the scoring box. It now recognises and scores cross over words which was a task and a half! If you cant play click on Skip turn. It will need to allow a player to hand back his tile set and recognise winning play but neither is coded yet. So you can play against yourself, computer play is some way off! The mainwin lists what is being checked. There will be bugs but I am pretty pleased with the results so far.
|
|
|
Post by Rod on Jan 4, 2022 8:46:14 GMT -5
I see it locks up if you click "play word" without having a tile on the board. First of many bugs to fix.
Edit: and edge of board issues as well, one man debugging is hard work!
|
|
|
Post by Rod on Jan 5, 2022 8:04:29 GMT -5
This has a good few bugs squashed. I have learned new aspects of the rules, particularly about cross over word multipliers. As a family we never allowed doubles or trebles to be counted twice but apparently thats the rules. This code does not baulk at no play, manages the edges of the board better and now doubles up the use of multipliers on cross over words created. You will need the resources from the .zip but here is the updatated .bas
snipped
|
|
|
Post by Rod on Jan 7, 2022 5:04:47 GMT -5
Final version for now, it plays 1 to 4 players, normal scrabble rules, the dictionary is a bit eclectic I am used to Oxford English. It recognises close of play and correctly gives the first player out the benefit of the other players tiles. The only thing I have on the to do list is to allow double and triple word scores to double or triple up! I did not know but if your word gets two double word squares you get four times the value, two triple squares and nine times the value! Anyways it seems to follow all other rules (bug reports welcome). gamebin.webs.com/ScrabbleAssist.zip
|
|
|
Post by tsh73 on Jan 7, 2022 15:23:18 GMT -5
It's interesting but version I used to play (with Cyrillic letters) has no rule along "if you add new letters it should form words BOTH horizontally and vertically". So I was surprised it said my go is invalid after obviously finding that word I intended (printed to a mainwin).
|
|
|
Post by Rod on Jan 8, 2022 2:56:03 GMT -5
Need more info please. You should be able to extend any word already on the board, you should be able to add a word to the side of any word already on the board. The only rule really is that you cant just lay an unattached new word on the board. It must attach to a letter already on the board.
If you have the mainwin in view it should give a clue as to what part of the check failed.
Edit fixed a bug that froze the game if you clicked off board and not in the tile rack.
|
|
|
Post by Rod on Jan 8, 2022 3:53:20 GMT -5
I wonder if it is my checking routine that confuses. I do always check for cross over words but they need not be there! The rules of Scrabble for those who have never played before www.wikihow.com/Play-Scrabble
|
|