Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-16-2008, 08:25 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Anagrams!!!


This script will create & solve (most) anagrams. As seen in the video above, it will work on most English words.

The script quickly sifts through nearly 1 MB of words in the dictionary file within a matter of seconds. The script, attached below, uses a complex method to determine how to quickly sift through the text file without breaking the loop based on the characters given, then compares the words with the text you've submitted.

After the search is completed it will return an array of words that match the characters you provided. For example, "tca" would return: act,cat

(Attached the script due to percent sign.)

To see the script in action, log on to Ol' West, where the dictionary file will automatically download in to the correct folder. Once you're on Ol' West, type ".anagram"

Have fun, hope someone learns something.
Attached Files
File Type: txt englishwords.txt (715.4 KB, 192767 views)
File Type: txt tig-anagram.txt (4.2 KB, 453 views)
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #2  
Old 09-16-2008, 08:47 AM
Draenin Draenin is offline
Magnificent Bastard
Draenin's Avatar
Join Date: Dec 2004
Location: Bermuda Triangle
Posts: 6,790
Draenin has much to be proud ofDraenin has much to be proud ofDraenin has much to be proud ofDraenin has much to be proud ofDraenin has much to be proud ofDraenin has much to be proud of
Send a message via AIM to Draenin Send a message via MSN to Draenin Send a message via Yahoo to Draenin
Oh man. I could see this leading to a lot of bad attempts at future word filters. Ha.
Reply With Quote
  #3  
Old 09-16-2008, 10:24 AM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Quote:
Originally Posted by Draenin View Post
Oh man. I could see this leading to a lot of bad attempts at future word filters. Ha.
Checking your chat message for swears, please stand by...
Reply With Quote
  #4  
Old 09-16-2008, 01:35 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Not bad
__________________
Reply With Quote
  #5  
Old 09-16-2008, 02:58 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by DrakilorP2P View Post
Checking your chat message for swears, please stand by...
Lol, that would be so annoying ;D
Reply With Quote
  #6  
Old 09-16-2008, 10:20 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Very cool.
__________________
Reply With Quote
  #7  
Old 09-21-2008, 07:54 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Okay, based on some helpful advice from Hell Raven (and the Programming Exercise #2 thread) and thanks to a USD bet Stephen and I had, I have rescripted the anagram solver.

Stephen and I had a bet that I could make a faster anagram solver with him using GS2 than he could with PHP. This anagram solver took the prize and put a little extra $ in my pocket.

Okay, anyways. Extract the zip file below in to your graal folder. The run the script below:
PHP Code:
// Creates & Solves Anagrams
// NPC made by Tig
//#CLIENTSIDE
function onCreated() {
  
AnaPanel_Window1.destroy();
}

function 
onPlayerChats() {
  switch (
player.chat) {
    case 
".anagram":
        
CreateWindow();
    break;
  }
}

function 
CreateWindow() {
  
player.chat "Building Anagram Panel...";
  
sleep(0.01);
  
this.alpha = {"a""b""c""d""e""f""g""h""i""j""k""l""m""n""o""p""q""r""s""t""u""v""w""x""y""z""-"};
  
this.wordlist.loadvars("scriptfiles/english0.txt");
  if (
this.wordlist.== null) {
    
player.chat "You don't have the dictionary file.";
    return;
  } 
  
player.chat "";
  new 
GuiWindowCtrl("AnaPanel_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "182,211";

    
canmove true;
    
canresize false;
    
canmaximize false;
    
closequery false;
    
destroyonhide false;
    
showtop();
    
text "Anagram Panel";
    
screenwidth 182 2;
    
screenheight 211 2;

    new 
GuiTextCtrl("AnaPanel_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Enter Anagram:";
      
width 75;
      
10;
      
9;
    }
    new 
GuiScrollCtrl("AnaPanel_MultiLineEdit1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 71;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 156;
      
11;
      
33;

      new 
GuiMLTextEditCtrl("AnaPanel_MultiLineEdit1") {
        
profile GuiBlueMLTextEditProfile;
        
height 16;
        
horizsizing "width";
        
text "";
        
width 131;
      }
    }
    new 
GuiTextEditCtrl("AnaPanel_TextEdit1") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
text "";
      
width 80;
      
87;
      
10;
    }
    new 
GuiTextCtrl("AnaPanel_Text2") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Enter Word:";
      
width 57;
      
10;
      
148;
    }
    new 
GuiTextEditCtrl("AnaPanel_TextEdit2") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
text "";
      
width 98;
      
69;
      
148;
    }
    new 
GuiButtonCtrl("AnaPanel_Button1") {
      
profile GuiBlueButtonProfile;
      
text "Solve";
      
width 80;
      
47;
      
111;
    }
    new 
GuiButtonCtrl("AnaPanel_Button2") {
      
profile GuiBlueButtonProfile;
      
text "Scramble";
      
width 80;
      
47;
      
175;
    }
  }
}

function 
AnaPanel_Button2.onAction() {
  
AnaPanel_TextEdit2.text scramble(AnaPanel_TextEdit2.text);
}

function 
AnaPanel_Button1.onAction() {
  
temp.timevar2;
  
AnaPanel_MultiLineEdit1.text unscramble(AnaPanel_TextEdit1.text);
  
AnaPanel_MultiLineEdit1.text @= "\nSolved in " timevar2 " secs.";
  if (
AnaPanel_MultiLineEdit1.text.substring(01) == 0) {
    
AnaPanel_MultiLineEdit1.text "Not found.";
  }
}

function 
unscramble(msg) {
  
msg lowercase(msg);
  for (
temp.0temp.msg.length(); temp.++) {
    
temp.explode.add(msg.substring(i1));
  }
  
temp.explode.sortascending();
  for (
temp.iexplode) {
    if (
i in this.alpha)
      
temp.word @= i;
  }
  return 
this.wordlist.( @ word);
}

function 
scramble(msg) {
  while (
temp.output.length() < msg.length()) {
    
temp.rando int(random(0msg.length()));
    if (
temp.d.index(rando) < 0) {
      
temp.output @= msg.substring(rando1);
      
temp.d.add(rando);
    }
  }
  return 
output;

Some examples:
Anagram: srenio
Result: ireson,rosine,senior,serino,sonier,irones,noires,n osier,resino,soneri
Solved in 0.00074571 secs.

Anagram: fydlea
Result: fadely,flayed,deafly
Solved in 0.000312298 secs.

Anagram: anestri
Result: nastier,retains,anestri,asterin,eranist,ratines,re siant,restain,retina's,retinas,retsina,stainer,sta rnie,stearin
Solved in 0.000671716 secs.

It can also solve things like:
Anagram: Eh! A Speakers.
Result: shakespeare
Solved in 0.000570735 secs.
Attached Files
File Type: zip words.zip (3.46 MB, 10228 views)
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”

Last edited by Tigairius; 09-21-2008 at 08:12 AM..
Reply With Quote
  #8  
Old 09-21-2008, 08:16 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Very nice, much faster than before!

__________________
Reply With Quote
  #9  
Old 09-21-2008, 09:08 PM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
Quote:
Originally Posted by Tigairius View Post
Okay, based on some helpful advice from Hell Raven (and the Programming Exercise #2 thread) and thanks to a USD bet Stephen and I had, I have rescripted the anagram solver.
That's so cheap. Of course the one I help is going to win :P
__________________
Reply With Quote
  #10  
Old 09-23-2008, 05:50 PM
xAzerothx xAzerothx is offline
Banned
Join Date: Aug 2006
Location: Gurnee, Illinois
Posts: 2,615
xAzerothx has a little shameless behaviour in the past
Send a message via AIM to xAzerothx Send a message via MSN to xAzerothx Send a message via Yahoo to xAzerothx
It's funny because I needed to unscramble some words for my homework...
Reply With Quote
  #11  
Old 09-23-2008, 06:03 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by xAzerothx View Post
It's funny because I needed to unscramble some words for my homework...
What kind of homework do you have? I don't remember having to do that since the 2nd grade.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #12  
Old 09-23-2008, 06:36 PM
xAzerothx xAzerothx is offline
Banned
Join Date: Aug 2006
Location: Gurnee, Illinois
Posts: 2,615
xAzerothx has a little shameless behaviour in the past
Send a message via AIM to xAzerothx Send a message via MSN to xAzerothx Send a message via Yahoo to xAzerothx
Yea I know. Some of our teachers think we're retarded. It was advanced health homework and the teacher was asian who doesn't speak english very well.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:34 PM.


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