June 13, 2004

Mastermind

I present my very first Excel game (built mostly by me, but with some useful VBA provided by Colo and also Juan Pablo Gonzalez)

Play and enjoy! If you have any feedback, please leave a comment or email me at the link provided below. Thanks.

Download it here!

Write a Comment
Thanks for both the compliments and the tip!

I was afraid of font problems (I have Excel in English but Office in Japanese). Anyway, I wasn't too sure about Sans Serif as my version is possibly different again, so I changed over to Arial. Figured that should be pretty safe.

Thanks very much once again!
Posted by Andrew at June 13, 2004 01:50
Nice one. Pretty hard though!

As for other feedback - the only thing I found was that my PC wouldn't recognise the font you used for the instructions, and the formatting went a bit whacko. I unprotected the sheet and changed the font to MS Sans Serif - seemed to fix up the problem. I suspect this is a regional difference though, which may be difficult to get around.
Posted by Anonymous at June 13, 2004 12:38
Andrew, Arial font is available on English PC. I'd had same question but now I have English version OS, so I'll let you know the font list that can be used on English machine.
Posted by Colo at June 13, 2004 16:12
Much appreciated! Please let me know when you get the chance! Thanks!
Posted by Andrew at June 13, 2004 18:03
Andrew,

If you want to remove the Analysis Toolpak reference, you could use

=INT(RAND()*6)+1

instead of

=RANDBETWEEN(1, 6)

Juan Pablo
Posted by Juan Pablo Gonzalez at June 17, 2004 00:42
Juan Pablo!

This is indeed an honor! Thank you for the alternative formula. The game has been updated already!
Posted by Andrew at June 17, 2004 00:43
Here is an amusing way to pick 4 DIFFERENT random numbers from 1 to 6.

Private Sub CommandButton1_Click()
' find 4 different random numbers between 1 and 6 and display them in A1:An
Dim z As String
Dim i As Byte
Dim r As Byte
Randomize
z = "123456"
For i = 1 To 4
r = Int((7 - i) * Rnd + 1) ' random number between 1 and (7-i), i.e. 1-6, 1-5, 1-4, and 1-3
Worksheets("Sheet1").Cells(1, i).Value = Mid(z, r, 1) ' use the rth character in z as the ith number
z = Mid(z, 1, r - 1) + Mid(z, r + 1) ' remove from z the rth character to avoid repetition
Next
End Sub

As your first number pick the rth digit in 123456 where r = 1 to 6. If r = 4, remove the 4th digit from 123456 to get 12356.

As your second number pick the rth digit in 12356 where r = 1 to 5. If r = 1, remove the 1st digit from 12356 to get 2356.

The third number is the rth digit in 2356 where r = 1 to 4. If r = 4, remove the 4th digit from 2356 to get 235.

The fourth number is the rth digit in 235 where r = 1 to 3. If r = 2, remove the 2nd digit from 235.

Conclusion: we picked 4142, but translated them to 4163, all different.
Posted by Jan Nordgreen at June 19, 2004 11:59
Wow! Thanks for the nice code Jan! And I really appreciate your explanation too.

This is definitely going into my VBA files!
Posted by Andrew at June 20, 2004 02:02