This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Boggle Game Script

Help for those learning Tcl or writing their own scripts.
Post Reply
s
sarius
Voice
Posts: 20
Joined: Fri Aug 05, 2005 10:30 am

Boggle Game Script

Post by sarius »

I tried searching in the TCL archive and also google but I can't one specifically written for tcl or eggdrop. Or maybe it has not been made public =P

Anyway, I'm in the midst of writing one for my own educational purpose, interest and for a bunch of friends in my irc channel.

Here's the gist of it

Code: Select all

set die(0) "lrytte"
set die(1) "vthrwe"
set die(2) "eghwne"
set die(3) "seotis"
set die(4) "anaeeg"
set die(5) "idsytt"
set die(6) "oattow"
set die(7) "mtoicu"
set die(8) "afpkfs"
set die(9) "xlderi"
set die(10) "hcpoas"
set die(11) "ensieu"
set die(12) "yldevr"
set die(13) "znrnhl"
set die(14) "obbaoj"
set die(15) "nmihuq"

proc generateboggle {bog} {
	global die
	set letters ""
	set numbers ""
	set randnum ""
	while { [llength $letters] < 16 } {
		set foundadupe 0
		set randnum [rand 16]
		set counter 0
		while {$counter < [llength $numbers]} {
			set dupenumtocheck [lrange $numbers $counter $counter]
			if {$dupenumtocheck == $randnum} {
	 			set foundadupe 1
			}
			incr counter
		}
		if {$foundadupe == 0} {
			lappend numbers $randnum
			set randletter [string index $die($randnum) [rand 6]]
			lappend letters $randletter
		}
	}
	return $letters
}

proc Boggle {nick uhost hand chan args} {
	global bog
	set bogstring [generateboggle $bog]
	putquick "privmsg #Boggle :[join [split [lrange $bogstring 0 3] " "] "  "]"
	putquick "privmsg #Boggle :[join [split [lrange $bogstring 4 7] " "] "  "]"
	putquick "privmsg #Boggle :[join [split [lrange $bogstring 8 11] " "] "  "]"
	putquick "privmsg #Boggle :[join [split [lrange $bogstring 12 15] " "] "  "]"
	utimer 360 "EndofRound #Boggle"
}
This is basically just for generating the a 4x4 Boggle board. The next step (which I have not written) is to feed this board into a Boggle solver written in C.
The boggle solver will generate a list of all the possible words based on a dictionary text file.
The eggdrop will then match the answers typed in by the players against this list.
The Boggle solver was obtained from here

Ideally, I would like to convert the C code into tcl, but my knowledge in C is pretty limited.

Anyway, I would like to know how to use the egg to feed the letters into the Solver. To run the solver, I have to type ./boggle2 and press enter. Then I have to type the letters on the boggle board one by one, pressing enter after each one.

After all the letters have been entered, the solver will print the list of words on the console screen. I need to change it to print to a text file.

I think I should be able to manage the matching of answers to the text file after this. Hopefully! :lol:

Any comments/advice/suggestions will be greatly appreciated!
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

assuming that boggle reads board's data from standard input, you need to open a pipeline and write to it:

Code: Select all

set f [open "|boggle >output.txt" w]
foreach {k data} [array get die] {puts $f $data}
close $f
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
s
sarius
Voice
Posts: 20
Joined: Fri Aug 05, 2005 10:30 am

Post by sarius »

Hi demond. Thanks for such a prompt reply.

It seems to be working without foreach. I just used \n.

Hmm... will update more when I finish the rest of the script :D
s
sarius
Voice
Posts: 20
Joined: Fri Aug 05, 2005 10:30 am

Post by sarius »

The script is more or less done. However I can't release it as a standalone tcl script because it requires the Boggle Solver to work. But I'll be more than happy to share the code if anyone's interested.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

you could try to embed boggle's C code into your Tcl script using Critcl, but I'd suggest you learn C and port boggle to Tcl; if you are ever to do anything serious in programming, you will need to know C anyway, so learning it would only be beneficial
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

You are funny, you could have given me the link for that post on IRC, might have been easier for me to give you a help for your case :D.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Post Reply