Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 21:33 02 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Developing scrabble for the PicoMiteVGA

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 05:56pm 09 Apr 2024
Copy link to clipboard 
Print this post

Since Scrabble is in the news at the moment I thought I'd have a go at developing a version for the PicoMiteVGA

This will be a significant development - anyone interested?

At the moment I have drawn a board, loaded and indexed a dictionary and built a function for testing a word against the dictionary

To run the code you will need PicoMiteVGA V5.09.00RC4 running on a Pico with at least a 4Mb flash memory running as fast as you can get it.

PicoMiteVGAV5.09.00RC4.zip

and you will need to set up a very large modbuffer able to hold 2707014 characters. i.e.  OPTION MODBUFF ENABLE 2644

RC4 includes a couple of tweaks to make this all work:

FLASH MODBUFF LOAD fname$
MM.INFO(MODBUFF ADDRESS)

Attached below is the dictionary file which should be copied to the B: drive

sowpods.zip

The first time you run the program it will copy the dictionary into the modbuffer and build an index into the dictionary - this takes a long time. It will then draw a scrabble board on the screen and enter a loop asking for words which it then tests against the dictionary - that's all at the moment


Option explicit
Option default integer
Dim nred,nblue,ncyan,nmag,x,y,i,j,k,l,dic=MM.Info(modbuff address)
Dim offsets(26,26)
Dim letters(26),letterscore(26)
Dim aa=Asc("a"), zz=Asc("z")
Dim word$
If Peek(byte dic)<>aa Or Peek(byte dic+1)<>aa Or Peek(byte dic+2)<>10 Then
 Print "Loading dictionary"
 Flash modbuff load "b:/sowpods.txt"
EndIf
VAR restore
If offsets(1,1)<>dic Then
 Print "Building dictionary indicies"
 i=aa
 j=dic
 k=1
 offsets(1,1)=dic
 Do While Peek(byte j)<> 255
   Do While Peek(byte j)<>10 'step to the end of the word
     Inc j
   Loop
   Inc j
   If Peek(byte j)>=aa And Peek(byte j)<=zz And Peek(byte j)<> i Then
     Inc k
     offsets(k,1)=j
     Inc i
     Print Chr$(i)
   EndIf
 Loop
 k=aa
 For i=1 To 26
   j=offsets(i,1)
   Do While Peek(byte j)=aa+i-1
     Do While Peek(byte j)<>10 'step to end of the word
       Inc j
     Loop
     Inc j
     If Peek(byte j)=aa+i-1 Then
       If Peek(byte j+1)<> k Then 'start of new second letter
         offsets(i,Peek(byte j+1)-aa+1)=j
         k=Peek(byte j+1)
         Print Chr$(Peek(byte j));Chr$(Peek(byte j+1))
       EndIf
     EndIf
   Loop
 Next
EndIf
VAR save offsets()
TILE height 32
CLS 0
TILE 10,0,RGB(black),RGB(white),60,16
Read nred
For i=1 To nred
Read x: Read y
TILE tilepos(x),y-1,RGB(black),RGB(red),4
Next
Read nblue
For i=1 To nblue
Read x: Read y
TILE tilepos(x),y-1,RGB(black),RGB(blue),4
Next
Read ncyan
For i=1 To ncyan
Read x: Read y
TILE tilepos(x),y-1,RGB(black),RGB(cyan),4
Next
Read nmag
For i=1 To nmag
Read x: Read y
TILE tilepos(x),y-1,RGB(black),RGB(magenta),4
Next
For i=0 To 15*32 Step 32
Line 80,i,MM.HRes-80,i
Line 80+i,0,80+i,MM.VRes-1
Next
j=0
For i=0 To 26
Read letters(i)
Inc j,letters(i)
Next
'Print j 'should be 100
j=0
For i=0 To 26
Read letterscore(i)
Inc j,letterscore(i)*letters(i)
Next
'Print j ' should be 187
'
Do
  Input word$;
  Print checkword(word$)
Loop

Function tilepos(n As integer)
tilepos=n*4+6
End Function
'
Function checkword(s$ As string) As integer
 s$=LCase$(s$)
 Local i=Asc(s$)
 Local j=Asc(Mid$(s$,2,1))
 Local k=offsets(i-aa+1,j-aa+1)
 Local w$
 checkword=0
 If k<>0 Then
   Do While Peek(byte k)=i And Peek(byte k+1)=j
     w$=Chr$(Peek(byte k))
     Inc k
     Do While Peek(byte k)<>10
       Inc w$,Chr$(Peek(byte k))
       Inc k
     Loop
     If w$=s$ Then
       checkword=1
       Exit Function
     EndIf
     Inc k
   Loop
 EndIf
End Function
'triple word
Data 8,1,1,8,1,15,1,1,8,15,8,1,15,8,15,15,15
'triple letter
Data 12,6,2,10,2,2,6,6,6,10,6,14,6,2,10,6,10,10,10,14,10,6,14,10,14
'doubble letter
Data 24,4,1,12,1,7,3,9,3,1,4,8,4,15,4,3,7,7,7,9,7,13,7,4,8,12,8,3,9,7,9,9,9,13,9
Data 1,12,8,12,15,12,7,13,9,13,4,15,12,15
'double word
Data 17,2,2,14,2,3,3,13,3,4,4,12,4,5,5,11,5,8,8,5,11,11,11,4,12,12,12,3,13,13,13
Data 2,14,14,14
'letter count
Data 2,9,2,2,4,12,2,3,2,9,1,1,4,2,6,8,2,1,6,4,6,4,2,2,1,2,1
'letter score
Data 0,1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10




Edited 2024-04-10 04:00 by matherp
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3551
Posted: 06:51am 10 Apr 2024
Copy link to clipboard 
Print this post

Hi Peter,

It is a nice board, drawn in mode 1, should be workable. To make the game 2 player with dictionary checking seems a relatively simple task from here. But to play against the pico (the AI) is a different cooky.

When generating the index already takes significant time, finding just any word that fits on a certain location on the board will be similar to worse(*). And then find the best word (most points) is factors slower. And then expand that to "any word, anywhere on the board".

I do not think this is something for me. Too complex.

Volhout

(*) let's assume there is an "A" the board on location (5,5). You no only have to process all words that start with "A" in 2 directions, but also second letter (so the "xA" words in 2 directions. And these are indexed. But also all words in the dictionary that have the "A" as the third letter, or the 4'th. And it gets insanely more work when there is a "D" in location (7,5). The rules to do this are pretty simple, and for each word you can calculate the value, and decide for the best. But it will be very time consuming. Actually... if you look what you will have to do for the AI, I think the indexing won't help at all. The indexing will be usefull to decide quickly that the word typed in by the human, is approved.
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3551
Posted: 05:06pm 10 Apr 2024
Copy link to clipboard 
Print this post

Just realized English is simpler than Dutch.
Dutch combines words. So in Dutch you can have a single word “redlightdistrict” wher English would have 2 or 3 words “red” “light” and “district”
It is in Dutch scrabble not uncommon to have words that are 12 characters long.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 903
Posted: 05:48pm 10 Apr 2024
Copy link to clipboard 
Print this post

  Volhout said  
It is in Dutch scrabble not uncommon to have words that are 12 characters long.
Volhout

This is not just a Dutch problem
'no comment
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024