OrangenSaft Posted June 29, 2009 Share Posted June 29, 2009 Hey Guys, I'm trying to do something like a "hangman bot". I've got 2 Input lines and a start button. When pushing start it should look if the words could match. E.g.: Line1: A_to_tv3 Line2: Autoitv3 => Match! Playing around with the StringSplit and the StringInStr functions etc. but not getting anywhere. Could someone give me a hint or has someone an idea? Would apreaciate it. P.S.: Sorry for my bad english, i'm from germany. Link to comment Share on other sites More sharing options...
BrettF Posted June 29, 2009 Share Posted June 29, 2009 Probably look at a dictionary... and try doing the matches from there Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
tannerli Posted June 29, 2009 Share Posted June 29, 2009 (edited) Maybe you can use something like this: Dim $match[10] = ["Hangman", "Bot", "Autoitv3", "Autoitv3Beta", "Scite", "Forum", "Help", "Personalmessage", "OrangenSaft", "Tannerli"] While 1 $input = InputBox("Hangman Matcher", "Please enter your (incomplete) word") If @error Then ExitLoop $inp_pattern = StringReplace($input, "_", ".") For $i = 0 To 9 If StringRegExp($match[$i], "(?i)" & $inp_pattern) Then ; (?i) is used to search case-insensitive MsgBox(0, "Found Match!", $match[$i]) EndIf Next Cheers tannerli Edited December 15, 2009 by tannerli Link to comment Share on other sites More sharing options...
Malkey Posted June 29, 2009 Share Posted June 29, 2009 Hey Guys, I'm trying to do something like a "hangman bot". I've got 2 Input lines and a start button. When pushing start it should look if the words could match. E.g.: Line1: A_to_tv3 Line2: Autoitv3 => Match! Playing around with the StringSplit and the StringInStr functions etc. but not getting anywhere. Could someone give me a hint or has someone an idea? Would apreaciate it. P.S.: Sorry for my bad english, i'm from germany.This StringRegExpReplace() approach works. ; Local $m = " Not a Match" Local $Line1 = "A_to_tv3"; "_u______"; Local $Line2 = "Autoitv3" If StringRegExpReplace($Line1, StringRegExpReplace($Line2, "(.)", "(\1|_)"), "") = "" Then $m = "Match" MsgBox(0,"Result",$m ) ; Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 29, 2009 Share Posted June 29, 2009 That replace won't work. You can't replace something with an option. That doesn't make sense. Link to comment Share on other sites More sharing options...
weaponx Posted June 29, 2009 Share Posted June 29, 2009 Here is the general idea. (NOTE: My regex isn't matching the newlines right, too busy to fix) ;Dictionary $dict = "" $dict = "garage" & @CRLF $dict = "gorilla" & @CRLF $dict = "garbage" & @CRLF $dict = "guilty" & @CRLF $dict = "giraffe" & @CRLF $dict = "gonzo" & @CRLF $dict = "blablabla" & @CRLF ;The correct word $key = "giraffe" ;The given letters $given = "g_ra__e" ;Convert underscores to regex wildcards $given = StringReplace($given, "_",".") & "\r\n" ConsoleWrite($given & @CRLF) ;Display results $aMatches = StringRegExp($dict, $given, 2) If IsArray($aMatches) Then ConsoleWrite("Possible matches:" & @CRLF) For $X = 0 to Ubound($aMatches)-1 ConsoleWrite("[" & $X & "]: " & $aMatches[$X] & @CRLF) Next Else ConsoleWrite("No matches found in dictionary" & @CRLF) EndIf Link to comment Share on other sites More sharing options...
Malkey Posted June 29, 2009 Share Posted June 29, 2009 That replace won't work. You can't replace something with an option. That doesn't make sense.The way I play hangman is the letters of an unknown word is guessed.The OP's example shows two remaining letters to be guessed. The second letter "u" and the fifth letter "i".My example returns "Not a Match" if any wrong letters are entered which does not match the hidden word " Autoitv3". The underscore representing not yet guessed letters.Makes sense to me. Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 30, 2009 Share Posted June 30, 2009 I was commenting on this piece of code. If StringRegExpReplace($Line1, StringRegExpReplace($Line2, "(.)", "(\1|_)"), "") = "" Then $m = "Match" That is showing to replace the character with "either the group or an underscore". That doesn't work. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now