AutoHotkey Community

It is currently May 26th, 2012, 5:38 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: HangMan Solver
PostPosted: April 22nd, 2009, 3:05 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Heres a simple script that uses OneLook.com's wildcard dictionary searches to give posible matches for a game of hangman. Say the board looks like this:
Quote:
HA_GM_N
Then put HA?GM?N in the input box.

Code:
;Hangman Solver
Top:
InputBox, Input, Hangman Solver, Enter what you have so far`, for letters you don't know use a question mark (?).  Example: Han?m?n
If !Input
  ExitApp
URLDownloadtoFile, http://onelook.com/?w=%Input%&scwo=1&sswo=1, Search.html
FileRead, Html, Search.html
FileDelete, Search.html
Words =
Loop, Parse, HTML, `n, `r
  If RegExMatch(A_LoopField, "\d\. (.*?)>(.*?)</a>", Match)
  {
    Match := RegExReplace(Match, "\d\. (.*?)>")
    StringReplace, Match, Match, </a>
    Words .= Match . "`n"
  }
Msgbox, 0, Posible Matches:, %Words%
Goto, Top


Update: Look 5 posts down for an updated version. It doesn't use InputBox or even require pressing {Enter} :D

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Last edited by Frankie on August 2nd, 2011, 5:32 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2009, 5:38 am 
Offline

Joined: August 8th, 2008, 7:26 pm
Posts: 117
Location: Raahe, Finland
Awesome script :D

I Really like it!

_________________
Hezzu - excuse the english!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2009, 2:08 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Thanks :D

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: HangMan Solver
PostPosted: March 30th, 2010, 6:45 pm 
at_a_ _e

_ _c _u _ Also 2nd word has a (a/n) in it but I don't know where they go

clues are
long term
could grow


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 30th, 2011, 1:28 pm 
Hezzu wrote:
Awesome script :D

I Really like it!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 2nd, 2011, 5:29 am 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
The script in my first post is pretty basic. I used goto... :roll:

Here's an updated version. It searches while you type.
Code:
; An updated Hangman Solver script by Frankie
; This script is released into the public domain
; AutoHotkey forum thread: http://www.autohotkey.com/forum/viewtopic.php?t=43482
Default_Text := "w?o?d"

Gui, +Resize
Gui, Margin, 10 5
Gui, Font, s18
Gui, Add, Edit, vInput gInputChange, % Default_Text
Gui, Font, s13
Gui, Add, ListView, r10 vOutput, Matches
LV_ModifyCol(1, "Integer Left")
Gui, Show, w300, H?ngman Solv?r
GuiControlGet, Output, Pos
GoSub, InputChange
return

InputChange:
GuiControlGet, Input
If (Input = Default_Text || Input = "")
{
   Gui, Font, cBBBBBB
   GuiControl, Font, Input
   GuiControl,, Input, % Default_Text
   SendInput {End} ; Hacky, but it works
   return
}
else If InStr(Input, Default_Text)
{   
   Gui, Font, c000000
   GuiControl, Font, Input
   StringReplace, NewText, Input, % Default_Text
   GuiControl,, Input, % NewText
   SendInput {End}
}
else if (InStr(Input, "?") = false)
       && (InStr(Input, "*") = false) || (StrLen(Input) < 3)
   return
Input := RegExReplace(Input, "([^/])\?", "$1%3F")
URLDownloadToFile, http://onelook.com/?w=%Input%&scwo=1&sswo=1, Hangman_Temp_File.html
FileRead, HTML, Hangman_Temp_File.html
FileDelete, Hangman_Temp_File.html
GuiControl, -ReDraw, Output
LV_Delete()
while (Pos>StrLen(Html)||!Pos ? Pos:=1 : Pos) := RegExMatch(HTML
      , "(?P<Index>\d+)\. <.*?>(?P<Word>\w+)(?=</a>)"
      , Match, Pos+StrLen(Match))
   LV_Add("", MatchIndex . ": " MatchWord)
LV_ModifyCol()
GuiControl, +ReDraw, Output
return

GuiSize:
If (A_EventInfo != 1) ; Do nothing when minimized
{
   ; Fit the Input and Output controls to the new window size
   GuiControl, Move, Output
      , % "w" (A_GuiWidth - 20) A_Space "h" (A_GuiHeight - OutputY - 10)
   GuiControl, Move, Input
      , % "w" (A_GuiWidth - 20)
}
return

GuiClose:
ExitApp

I have no idea why it sometimes (about 1/5 chance) doesn't show the listview. If it happens just resize the window by dragging the corner.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: HangMan Solver
PostPosted: August 2nd, 2011, 6:08 am 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
jeannette wrote:
at_a_ _e

_ _c _u _ Also 2nd word has a (a/n) in it but I don't know where they go

clues are
long term
could grow
Sorry for the late reply. If you're still trying to figure it out, and haven't used all your guesses, try "attache lockup".

HTH :wink:

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject: easier way
PostPosted: December 13th, 2011, 11:14 pm 
just do:
Ctrl+u

go down and find at the end of a line:

value="(the answer)"

it is as easy as that


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2011, 4:03 am 
Offline

Joined: December 18th, 2009, 6:08 pm
Posts: 63
nice script frankie! works great, now you need to add an 'excluded letters' option, example.. if S isnt in the answer, exclude all the remaining words with S, etc.. that will narrow the list down much faster i think.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2011, 4:06 am 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Good idea. I'll get on that!

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2011, 4:16 am 
Offline

Joined: December 18th, 2009, 6:08 pm
Posts: 63
Frankie wrote:
Good idea. I'll get on that!



great.. also... ??an shouldnt show adan, akan, alan, etc.. because A is known letter.. please get these implemented so i can pwn some fools in some hangman.. lol. :P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2012, 10:47 pm 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
Here's my version. I just whipped this up now and won't develop it any further.
If you're looking for H_NGM_N, enter h.ngm.n in the first box.
The second box is letters not included. E.g. if you picked 'e' and the word was hangman, you'd put 'e' in this box.
The third is letters already included. This is not generated from the first box because some regEx options and symbols are non-literal letters.
Code:
SetBatchLines -1
#NoEnv

GoSub, DownloadWordList ; if there isn't a local wordlist.txt for the program to use, download it
Loop
{
   InputBox Pattern,, Regular Expression Pattern,,,,,,,, %Pattern%
   InputBox BadLetters,, Letters not included in the word or phrase (comma delimited),,,,,,,, %BadLetters%
   InputBox NoSuggest,, Letters already in words (comma delimited),,,,,,,, %NoSuggest%
   if ErrorLevel
      Break
   count := {}, PossibleWords := ""
   Loop Read, %WordListFile%
   {
      if !Contains(A_LoopReadLine, BadLetters) and RegExMatch(A_LoopReadLine,"i)^(" Pattern ")$"){ ; if this word is a possible choice
         Loop Parse, A_LoopReadLine ; count up its letters
            if is(A_LoopField, "alpha") and !InStr(NoSuggest, A_LoopField) ; but only count the letters
                  count[A_LoopField] := count[A_LoopField] ? count[A_LoopField] + 1 : 1
         PossibleWords .= A_LoopReadLine . "`n"
      }
   }
   MaxCount := 0
   for letter, LetterCount in count
      if (LetterCount > MaxCount)
         MaxCount := LetterCount, MaxLetter := letter
   MsgBox 4,, I suggest '%MaxLetter%'. Is it included?
   IfMsgBox Yes
      NoSuggest .= (NoSuggest = "" ? "" : ",") . MaxLetter
   IfMsgBox No
      BadLetters .= (BadLetters = "" ? "" : ",") . MaxLetter
}
return

DownloadWordList:
if !FileExist("WordList.txt") {
   URLDownloadToFile http://www.autohotkey.net/~berban/WordList.TXT, Wordlist.txt
   if (ErrorLevel) {
      MsgBox Could not download a word list. Please choose one.
      GoSub, SelectWordList
   }
   else
      WordListFile := "WordList.txt"
}
else
{
   Loop WordList.txt
   {
      WordListFile := A_LoopFileLongPath
      break
   }
   MsgBox, 4,, Found %WordListFile%. Use it?
   IfMsgBox No
      GoSub, SelectWordList
}
return

SelectWordList:
FileSelectFile WordListFile, 11, , Select a word list
if (ErrorLevel)
   ExitApp
return

Contains(a, b){
   if a contains %b%
      return true
   return false
}

is(a, b) {
   if a is %b%
      return true
   return false
}

It works reasonably fast and well for me.
Quote:
"attache lockup"

Actually, I'd suggest "attache cactus", based on the (a/n) hint and the "could grow" hint.

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2012, 11:05 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Looking back... that wouldn't even be possible. When you get the first 't', if the third letter was a 't' it would also be revealed.

Nice work nimda. Hopeful I'll be getting a new computer soon; which means I'll get Windows back; which means I'll be able to do more AutoHotkey stuff.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 13th, 2012, 10:05 pm 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
Frankie wrote:
Looking back... that wouldn't even be possible. When you get the first 't', if the third letter was a 't' it would also be revealed.
We need a bigger dictionary...

Quote:
Nice work nimda. Hopeful I'll be getting a new computer soon; which means I'll get Windows back; which means I'll be able to do more AutoHotkey stuff.
Wooo! :)

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: XX0 and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group