Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Programming Exercise #5: Solving Boggle?! (https://forums.graalonline.com/forums/showthread.php?t=80139)

Kristi 06-19-2008 02:08 AM

Programming Exercise #5: Solving Boggle?!
 
For those of you who know not what Boggle is:
http://en.wikipedia.org/wiki/Boggle

So today boys and... boys, our task is to make a word finder in Boggle.
Given a word list, find all the words from that list you can make on an x by x Boggle board (the game itsself is a 4x4 board, but we can do better :D)

Expert Level: Do the above task with recursion :)

Addeum: We can use the TWL06 as our word list.
http://www.cs.bu.edu/fac/byers/cours...ndouts/TWL.txt

Chompy 06-19-2008 12:14 PM

So, the algorithm to find all words in a Boggle board in the most efficient way?

And, just pick random letters and find words by them? Are there any rules (Hard letters like K (2 or more), U, X, Z etc.) of letters that can be used to produce the board?

zokemon 06-19-2008 01:15 PM

Arguments please.

Kristi 06-19-2008 03:10 PM

Quote:

Originally Posted by zokemon (Post 1398009)
Arguments please.

If someone wants to go grab a boggle board and put up a random example, feel free to do so.

As for the rules, that is the reason I linked the wiki...

Tolnaftate2004 06-20-2008 12:55 AM

try:
http://i4.photobucket.com/albums/y14...up/boggle2.jpg

zokemon 06-20-2008 10:19 AM

I'm asking what should be passed to the function x_x.

Kristi 06-20-2008 03:53 PM

Quote:

Originally Posted by zokemon (Post 1398217)
I'm asking what should be passed to the function x_x.

I left that up to you guys since the answer was obvious i thought.

You pass the board its self. That is the only thing you would ever need. If you want to give it pointers to different word lists too that is your choice.

Dan 06-20-2008 06:08 PM

Do 2 letters have to link to form a word or can you pick any letter from any position to form a word?

zokemon 06-20-2008 06:12 PM

Ahh, didn't see that you added a wordlist above.

Rufus 06-20-2008 06:15 PM

Sudoku is better than Boggle!

Crow 06-20-2008 06:36 PM

Quote:

Originally Posted by Rufus (Post 1398279)
Sudoku

Crosswords for dyslexic people.

Kristi 06-20-2008 07:30 PM

Quote:

Originally Posted by Dan (Post 1398273)
Do 2 letters have to link to form a word or can you pick any letter from any position to form a word?

have to link, and you can't reuse letters.

_Z3phyr_ 08-02-2008 11:39 AM

Quote:

Originally Posted by Kristi (Post 1397978)
Given a word list, find all the words from that list you can make on an x by x Boggle board (the game itsself is a 4x4 board, but we can do better :D)

Addeum: We can use the TWL06 as our word list.
http://www.cs.bu.edu/fac/byers/cours...ndouts/TWL.txt

Expert Level: Do the above task with recursion

you can find all of the words on an x by x boggle board, as long as you can find all of the words on an x by x boggle board.

edit- answer:



Let M be an n x n matrix. (meaning, let M be an n-1 x n-1 array)
Let W be the set of accepted words.

if a set of entries of M, called X, where each entry of M in X is adjacent to the one both preceding and following, is an element of W, then there is a word in the matrix.

Problem: define the set of all possible values for X
(note: the maximum length of X is n*n)

how to do this:

loop through all entries of M sub 'i,j', (we don't need to check if it is apart of the alphabet because this is a boggle board) then check for each entry that:
  • M sub 'i+1,j' is an element of W.substring(0,1)
  • M sub 'i-1,j' is an element of W.substring(0,1)
  • M sub 'i,j+1' is an element of W.substring(0,1)
  • M sub 'i,j-1' is an element of W.substring(0,1)
  • M sub 'i+1,j+1' is an element of W.substring(0,1)
  • M sub 'i-1,j-1' is an element of W.substring(0,1)
  • M sub 'i+1,j-1' is an element of W.substring(0,1)
  • M sub 'i-1,j+1' is an element of W.substring(0,1)

if any of those are true (and if not then move onto the next entry in the matrix), repeat the process with the new entry and see if it is an element of W.substring(1,2). if that is true, do it again with W.substring(2,3), then (3,4), and so on.


how all of that looks in code talk
PHP Code:

2-dimensional string array of length n-1 by n-1 containing only letters of the alphabet because arrays start at index 0 and not 1;

string array containing all of the acceptable wordsone word per entry;

for (
i=0;i<n-1;i++) { //row # of the matrix
  
for (j=0;j<n-1;j++) { //column # of the matrix
    
check(i,j,0);
  }
}
check(rsp) {
  
p;
  for (
k=0;k<&& t==p;k++) { //8 because there are 8 directions to check
    
if (k==&& r-1>=0) { //look above the entry, if its not at the top
      
for (l=0;l<W.length();l++) { //for each word in W
        
if (M[r][sin W[l].substring(p,p+1)) { 
          
//p is used to check the pth letter of the lth string in W.
          
p++; //<--move onto the next letter and...
          
check(r-1sp); //start over
        
}
      }
    } else if (
k==&& r+1<=n-1) {//look below, if its not at the bottom
      
...
    } else if (
k==&& s-1>=0) {//look left, if its not at the left edge
      
...
    }

    
//dot dot dot

  
}


since i'm being asked to show what words can be found:

add the string W[l] to a separate array every time
M[r][s] in W[l].substring(p,p+1) && p == W[l].size(), and then break; so that the search can continue.

Kristi 08-08-2008 08:02 PM

Quote:

Originally Posted by _Z3phyr_ (Post 1410788)
stuffs

I just quickly glanced this over because I am at work but two things...

I don't see a return value.

I don't see handling of already used letters (you can't use the same letter/piece twice in boggle)


All times are GMT +2. The time now is 09:55 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.