Boggle code
I recently got Small BASIC and wrote the following as a test to see how it works:
rem Written October 2009 by Marc Glasby
rem This works best when the largest text size is used CTRL ]
rem There isnt much checking for correct input from the user
rem and the program isnt as elegant as it could be but hey, its free
rem and it works. If you want to contect me you can find my info at
rem http://www.nowandthen.noadsfree.com
dim dice(16,6),diceresult(16),finaldice(16)
rem The data is taken from an original set of BOGGLE dice
data "C ","I ","M ","O ","T ","U "
data "A ","F ","F ","K ","P ","S "
data "A ","B ","B ","J ","O ","O "
data "D ","E ","I ","L ","R ","X "
data "A ","A ","E ","E ","J ","N "
data "A ","C ","S ","O ","P ","H "
data "E ","S ","T ","O ","I ","S "
data "Qu","N ","M ","I ","H ","U "
data "T ","Y ","R ","L ","E ","T "
data "D ","I ","Y ","S ","T ","T "
data "W ","E ","G ","H ","N ","E "
data "T ","H ","R ","V ","W ","E "
data "E ","R ","L ","V ","D ","Y "
data "N ","Z ","N ","R ","L ","H "
data "S ","I ","E ","N ","U ","E "
data "W ","A ","L ","T ","O ","T "
randomize timer
rem Read the above data into an array
for x = 1 to 16
for y = 1 to 6
read dice(x,y)
next y
next x
rem Set special character constants
boldon=chr$(27)+"[1m"
underlineon=chr$(27)+"[4m"
boldoff=chr$(27)+"[21m"
underlineoff=chr$(27)+"[24m"
rem clear the screen and ask user if a timer is to be used
9 cls
AT 375,1
print boldon;"GOGGLE LETTER GENERATOR Ver 1.2 by Marc Glasby"
AT 280,40
print "use timer (Y/N default = N) or enter I for instructions ";
input timeyn$
if timeyn$ = "i" or timeyn$ = "I"
gosub 999
goto 9
end if
rem If a timer is to be used get the number of minutes
rem Minutes must be 2 or more
if timeyn$="y" or timeyn$ = "Y" then
15 AT 220,70
print "Enter number of minutes for timer to run (default = 3)";
input numbermins
numbermin = round(numbermins)
if numbermin < 2 then numbermin = 3
end if
rem Multiply minutes by seconds for timer
nummins = numbermin * 60
rem Generate random dice data using the data array
for i = 1 to 16
21 pick1 = int(rnd*6 + 1)
rem Some random number generators need a pause to generate
rem better random selections, this is that pause
for q = 1 to 99999
next q
diceresult(i) = dice(i,pick1)
next i
rem Now put the dice into a random order ready for displaying
for k = 1 to 16
51 diceused = int(rnd*16+1)
finaldice(k) = diceused
rem Check that the same dice is not used twice
if k > 2 then
for l = 1 to k - 1
if finaldice(l) = finaldice(k) then 51
next l
end if
next k
rem now clear the screen ready to display the results
cls
AT 550,0
print boldon;underlineon;"G O G G L E";underlineoff
RECT 400,90,870,570
COLOR 9,15
rem Loop 16 times to display each dice
for n = 1 to 16
ans = diceresult(finaldice(n))
rem set the column and row positions to display each dice
if n = 1 then col = 420: row = 100
if n = 2 then col = 540: row = 100
if n = 3 then col = 660: row = 100
if n = 4 then col = 780: row = 100
if n = 5 then col = 420: row = 220
if n = 6 then col = 540: row = 220
if n = 7 then col = 660: row = 220
if n = 8 then col = 780: row = 220
if n = 9 then col = 420: row = 340
if n = 10 then col = 540: row = 340
if n = 11 then col = 660: row = 340
if n = 12 then col = 780: row = 340
if n = 13 then col = 420: row = 460
if n = 14 then col = 540: row = 460
if n = 15 then col = 660: row = 460
if n = 16 then col = 780: row = 460
rem Display large characters
if ans = "A " then gosub 10
if ans = "B " then gosub 20
if ans = "C " then gosub 30
if ans = "D " then gosub 40
if ans = "E " then gosub 50
if ans = "F " then gosub 60
if ans = "G " then gosub 70
if ans = "H " then gosub 80
if ans = "I " then gosub 90
if ans = "J " then gosub 100
if ans = "K " then gosub 110
if ans = "L " then gosub 120
if ans = "M " then gosub 130
if ans = "N " then gosub 140
if ans = "O " then gosub 150
if ans = "P " then gosub 160
if ans = "Qu" then gosub 170
if ans = "R " then gosub 180
if ans = "S " then gosub 190
if ans = "T " then gosub 200
if ans = "U " then gosub 210
if ans = "V " then gosub 220
if ans = "W " then gosub 230
if ans = "X " then gosub 240
if ans = "Y " then gosub 250
if ans = "Z " then gosub 260
next n
goto 99
10 AT col,row
PRINT " AAA"
AT col,row+20
PRINT "A A"
AT col,row+40
PRINT "AAAAA"
AT col,row+60
PRINT "A A"
at col,row+80
PRINT "A A"
return
20 AT col,row
PRINT "BBBB"
AT col,row+20
PRINT "B B"
AT col,row+40
PRINT "BBBBB"
AT col,row+60
PRINT "B B"
at col,row+80
PRINT "BBBB"
return
30 AT col,row
PRINT " CCCC"
AT col,row+20
PRINT "C"
AT col,row+40
PRINT "C"
AT col,row+60
PRINT "C"
at col,row+80
PRINT " CCCC"
return
40 AT col,row
PRINT "DDDD"
AT col,row+20
PRINT "D D"
AT col,row+40
PRINT "D D"
AT col,row+60
PRINT "D D"
at col,row+80
PRINT "DDDD"
return
50 AT col,row
PRINT "EEEEE"
AT col,row+20
PRINT "E"
AT col,row+40
PRINT "EEEE"
AT col,row+60
PRINT "E"
at col,row+80
PRINT "EEEEE"
return
60 AT col,row
PRINT "FFFFF"
AT col,row+20
PRINT "F"
AT col,row+40
PRINT "FFFF"
AT col,row+60
PRINT "F"
at col,row+80
PRINT "F"
return
70 AT col,row
PRINT "GGGGG"
AT col,row+20
PRINT "G"
AT col,row+40
PRINT "G GG"
AT col,row+60
PRINT "G G"
at col,row+80
PRINT "GGGGG"
return
80 AT col,row
PRINT "H H"
AT col,row+20
PRINT "H H"
AT col,row+40
PRINT "HHHHH"
AT col,row+60
PRINT "H H"
at col,row+80
PRINT "H H"
return
90 AT col,row
PRINT "IIIII"
AT col,row+20
PRINT " I"
AT col,row+40
PRINT " I"
AT col,row+60
PRINT " I"
at col,row+80
PRINT "IIIII"
return
100 AT col,row
PRINT "JJJJJ"
AT col,row+20
PRINT " J"
AT col,row+40
PRINT " J"
AT col,row+60
PRINT "J J"
at col,row+80
PRINT " JJJ "
return
110 AT col,row
PRINT "K K"
AT col,row+20
PRINT "K K"
AT col,row+40
PRINT "K K"
AT col,row+60
PRINT "K K"
at col,row+80
PRINT "K K"
return
120 AT col,row
PRINT "L"
AT col,row+20
PRINT "L"
AT col,row+40
PRINT "L"
AT col,row+60
PRINT "L"
at col,row+80
PRINT "LLLLL"
return
130 AT col,row
PRINT "M M"
AT col,row+20
PRINT "MM MM"
AT col,row+40
PRINT "M M M"
AT col,row+60
PRINT "M M M"
at col,row+80
PRINT "M M"
return
140 AT col,row
PRINT "N N"
AT col,row+20
PRINT "NN N"
AT col,row+40
PRINT "N N N"
AT col,row+60
PRINT "N NN"
at col,row+80
PRINT "N N"
return
150 AT col,row
PRINT " OOO"
AT col,row+20
PRINT "O O"
AT col,row+40
PRINT "O O"
AT col,row+60
PRINT "O O"
at col,row+80
PRINT " OOO"
return
160 AT col,row
PRINT "PPPP"
AT col,row+20
PRINT "P P"
AT col,row+40
PRINT "PPPP"
AT col,row+60
PRINT "P"
at col,row+80
PRINT "P"
return
170 AT col,row
PRINT " QQQ"
AT col,row+20
PRINT "Q Q"
AT col,row+40
PRINT "Q Q Q"
AT col,row+60
PRINT "Q QQ"
at col,row+80
PRINT " QQ QU"
return
180 AT col,row
PRINT "RRRR"
AT col,row+20
PRINT "R R"
AT col,row+40
PRINT "RRRR"
AT col,row+60
PRINT "R R"
at col,row+80
PRINT "R R"
return
190 AT col,row
PRINT "SSSSS"
AT col,row+20
PRINT "S"
AT col,row+40
PRINT "SSSSS"
AT col,row+60
PRINT " S"
at col,row+80
PRINT "SSSSS"
return
200 AT col,row
PRINT "TTTTT"
AT col,row+20
PRINT " T"
AT col,row+40
PRINT " T"
AT col,row+60
PRINT " T"
at col,row+80
PRINT " T"
return
210 AT col,row
PRINT "U U"
AT col,row+20
PRINT "U U"
AT col,row+40
PRINT "U U"
AT col,row+60
PRINT "U U"
at col,row+80
PRINT "UUUUU"
return
220 AT col,row
PRINT "V V"
AT col,row+20
PRINT "V V"
AT col,row+40
PRINT "V V"
AT col,row+60
PRINT " V V"
at col,row+80
PRINT " V"
return
230 AT col,row
PRINT "W W"
AT col,row+20
PRINT "W W W"
AT col,row+40
PRINT "W W W"
AT col,row+60
PRINT "WW WW"
at col,row+80
PRINT "W W"
return
240 AT col,row
PRINT "X X"
AT col,row+20
PRINT " X X"
AT col,row+40
PRINT " X"
AT col,row+60
PRINT " X X"
at col,row+80
PRINT "X X"
return
250 AT col,row
PRINT "Y Y"
AT col,row+20
PRINT " Y Y "
AT col,row+40
PRINT " Y"
AT col,row+60
PRINT " Y"
at col,row+80
PRINT " Y"
return
260 AT col,row
PRINT "ZZZZZ"
AT col,row+20
PRINT " Z"
AT col,row+40
PRINT " Z"
AT col,row+60
PRINT " Z"
at col,row+80
PRINT "ZZZZZ"
return
999 cls
AT 500,10
PRINT underlineon;"I N S T R U C T I O N S";underlineoff
print
print " To play this game you can use the built in timer if you want a timed game. The"
print " default timer time limit is 3 minutes but you can select more than that if "
print " you like. If you want an untimed game simply accept the default setting 'N' "
print
print " The game is played by finding as many words as you can from the random "
print " letters displays in the 4 x 4 grid. Words must be 3 letters or more long and "
print " the letters of each word must be connected to each other in order of use. "
print " Letters in each word found cannot be used more than once each and plural "
print " words count as seperate from singular words."
print
print " Words can be formed by horizontal, vertical and diagonal connections of letters."
print
print " When the game ends scoring is done as follows. 1 point for 3 and 4 letter "
print " words, 2 points for 5 and 6 letter words and 3 points for anythig larger. "
print
print
AT 490,600
PRINT "Press RETURN to continue";
INPUT null
return
rem draw a box around the results to make it look nice
99 color 0,15
LINE 400,210,870,210
LINE 400,330,870,330
LINE 400,450,870,450
LINE 520,90,520,570
LINE 640,90,640,570
LINE 760,90,760,570
LINE 520,90,520,570
PAINT 421,101,7
PAINT 541,101,11
PAINT 661,101,7
PAINT 781,101,11
PAINT 421,221,11
PAINT 541,221,7
PAINT 661,221,11
PAINT 781,221,7
PAINT 421,341,7
PAINT 541,341,11
PAINT 661,341,7
PAINT 781,341,11
PAINT 421,461,11
PAINT 541,461,7
PAINT 661,461,11
PAINT 781,461,7
rem If the timer is used warn the players when there is only one minute left
rem and sound an alarm when the game is over
111 if timeyn$="Y" or timeyn$="y" then
a=timer
s=ticks
while (timer-a < (nummins - 60) ) : WEND
AT 390,20
print "Only one minute left, better hurry up"
while (timer-a < nummins ) : WEND
AT 565,50
print "Times up !"
play "MFL1O1AC"
e=ticks
end if
rem See if the players want another game
151 AT 430,580
print "run again (Y/N Default = Y) ";
input yn$
if yn$="" then yn$="Y"
if yn$ = "Y" or yn$ = "y" then 9
print "Ok, bye bye...."
stop
end
end

testing Boggle
Hi Marc,
This looks like a substantial project!
I must admit, I've never played Boggle, tho I might have heard of it.
I copied the code and loaded it into my new v0.10.5 ... and ran into a hangup right away.
The first IO, "use timer (Y/N default = N) or enter I for instructions ", only worked for me using Y explicitly.
The 2nd IO, "Enter number of minutes for timer to run (default = 3)", did not work with 1, with ENTER, or with 3, for me. I could not advance past this IO.
[My new v0.10.5 also just failed again with a "This program (Sbasici) will be shut down" error, which makes just about each time I've ran it, since getting it a few days ago.]
Ok ... I loaded my old v0.9.5, and despite that it lacks support for IO methods used in the code, it accepted blind IO, and then attempted to create what I take to be the game-screen: matrices of letters in line-boxes. While coloring the background cyan, etc, the program then locked up 'for good' ... but its relative success suggest the issue is not in your code. :)
I also have v0.10.1. It fails on the program similar to v0.10.5, but upon using Break places the cursor on the code-line where it was interrupted; on line 92:
91 for q = 1 to 99999
92 next q
v0.10.5 quickly & quietly clicks twice when I use Break, and the cursor is then at the beginning of the code, which seems different than expected.
I do have an old machine, and old Windows ... but I now have a nice new-to-me XP box and will soon have SmallBASIC on it. The new computer may solve many problems...
Well, Marc, hopefully my case is an anomaly and other testers are Boggling happily away with your code! ;-)
Ted Clayton
Boggle problems
Hi,
Sorry you didn't manage to run the boggle code without problems. I am runnign Small BASIC FLTK Version 0.10.5 on Vista home basic and haven't had the problems you mentioned so I guess there may be something else going wrong.
I am about to upload another small game that uses the draw function. Mostly I am just mucking about with the language to get to see how it works and I'm not really writing very organised code.
I ran the program again without any hassles. One thing I have noticed with Small BASIC is that the enlarge text function CTRL ] only works if you do it first in the source code screen and then run the program.
Regards,
Marc
Hi Marc, Thanks for posting
Hi Marc,
Thanks for posting the code !
You could try using the "DELAY" function in lieu of the timer loop. That way you can pause without consuming CPU. Btw, your home page looks interesting - I'd love to be able to visit the west sometime.
Ted - In version 0.10.5 a new option was introduced called "break to line" (probably needs a better name) which controls whether the cursor will be positioned on the last program line upon hitting break.
Cheers,
Chris
Boggle
Hi Chris,
I haven't really got into learing all the reserved words for Small BASIC yet but will probably do more when time permits. I have very limited access to the net so haven't read all the info on the language yet.
Regards,
Marc