Jump to content

master mind


Recommended Posts

Did a few things, over here. Studied the script, the most of it is understood.

A few lines I have questions about.

line 32, where 4 digits were supposted to be generated, separated by spaces, I understand this line perfectly, BUT you made that line a remark line....

later on (line 57, you use a quite different way to achief that goal. And I don't quite understand what happens there.

If I may ask, can you discribe what happens on line 57?

Last tiny question:

Line 43, where it says: $sDisp &= $i etcetera.

I noticed the ampersand and equalsign, without space in between. Purpose of that notation? Is it to make the value of $i hidden /invisible?

I made a few tiny changes, mosty to get a nicer layout, but may be, this is only a matter of taste.

I attach the addapted script, so when you discuss the lines, I had questions about, we are synchronized in linenumbers.

Thanx again. solommUK.au3

With reference to your attached file " solommUK.au3".

Line 32 is replaced by the 6 command lines that are directly above, lines 25 to 31, which are the " Generate unique 4 digit number separated with spaces" routine.

Line 32 was susceptible to creating duplicate digits in the hidden number.

Line 57 uses StringRegExpReplace to put a space between the digits of the number in $rg, which was entered in the InputBox (line 51).

The pattern of the regular expression is "(.)". The brackets, "()", captures a group suitable for back-referencing. The "." within the brackets represents any one single character. Instead of a dot, ".", I could have used "\d", which would capture one single digit. (See StringRegExp function in help file)

The replace parameter of StringRegExpReplace is "\1 ". "\1" is the first and only back-reference. Anything that is captured from within the test string that matches the pattern within the first set of brackets, can be expressed as "\1", or back-referenced. "\1", "$1", and "${1} are equivalent.

In this case, each single character is capture in a first group from $rg, and is replaced with each single character via its back-reference notation, followed by a space.

This results in StringRegExpReplace returning 4 characters with 4 spaces. So, StringTrimRight function is used to trim the unwanted trailing space.

Another method to put a space in between the digits is to use the array $aRG with a For-Next loop to return the required string.

Line 43: "$sDisp &= $i & etc." is a short hand notation for "$sDisp = $sDisp & $i & etc.". (strings)

Similarly, "$x += 1" stands for "$x = $x + 1" (numeric)

Line 60: The "Local $aRes[uBound($aRG)]" is a mistakened left-over from the copy of the routine from post #9 example.

In the evaluation routine of post #9, each individual digit is specifically assigned an evaluation symbol,"X 0 =". These symbols would then need to be sorted.

In later examples, all that is needed is "Local $aRes[3]". But what is being mistakenly used is the equivalent of "Local $aRes[5]". In these later evaluation routines, all the "X" are going into $aRes[1], all the "0" are going into $aRes[2], all the "=" are going into $aRes[3], and $aRes[0] and $aRes[4] are not being used.

Lines 63, 65, and 67: "$aRes[n] &= "symbol" & " "

The concatenation of the two strings is not necessary. All that is needed is the symbol and a space.

Example line 63, $aRes[1] &= "X" & " " becomes $aRes[1] &= "X " which is equivlant to $aRes[1] = $aRes[1] & "X "

Line 53: "If @error = 1 Then Exit"

I see you prefer the "Cancel" option to exit the script at the InputBox.

Instead of "If @error = 1 Then ExitLoop 2 " which exits two loops and allows the choice for another game to start or to exit script. Plus you get to see what the hidden number was.

I hope this help you push your way up through the murky depths - happy scripting.

Link to comment
Share on other sites

Malkey:

Lots of outside action, this summerwether here, offers. So did not read your answer till now.

You did your best to explain line 57, the one with StringRegExpReplace and the spaces, that had to be inserted.

I read it a few times over but it remains hazy. I feel what it does, but i have to make some tests for myself.

Until I realy understand, I have to copy the magic formula to get results.

That is not your fault, that is because this programming stuff is new to me and (luckely for you) not Dutch.....

You noticed my change in line 53 to exit the script, instead of your ExitLoop 2, which remains inside the script.

May be only a matter of taste, but when I want to exit, then i realy want OUT and when I want to see the hidden number,

then I have to walk my way through all the turns. Forcing the player to finish his/her turns.

tnx a lot for being patient with me.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...