Jump to content

Recommended Posts

Posted

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.

Posted (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 by tannerli
Posted

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 )
;
Posted

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
Posted

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.

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...