Microsoft Small Basic

Program Listing:
Embed this in your website
' MASTERMIND for SmallBasic by DaveyWavey, March 2010. v1

LF=Text.GetCharacter(10)  ' a linefeed character to help with text layout

TextWindow.WriteLine( "MASTERMIND:" +LF+LF+ "The computer has chosen a 4 character sequence using the letters A,B,C,D,E,F." +LF+ "Each letter may be used more than once." )

' let computer choose a random set of letters
computer[1]=text.GetSubText("ABCDEF", Math.GetRandomNumber(4), 1)
computer[2]=text.GetSubText("ABCDEF", Math.GetRandomNumber(4), 1)
computer[3]=text.GetSubText("ABCDEF", Math.GetRandomNumber(4), 1)
computer[4]=text.GetSubText("ABCDEF", Math.GetRandomNumber(4), 1)

' now let the player try to guess what the computer has chosen
try:
tries=tries+1

TextWindow.Writeline( LF+LF+"Enter your Four Guesses. Press ENTER after each guess: "+LF )
For lwp=1 To 4
  TextWindow.Write("Letter "+lwp+" = ")
  player[tries][lwp]=text.GetSubText( Text.ConvertToUpperCase( TextWindow.Read() ) ,1,1)  ' only accept first character entered
EndFor

TextWindow.Clear()
TextWindow.WriteLine( "MASTERMIND:" +LF+LF+ "The computer has chosen a 4 character sequence using the letters A,B,C,D,E,F." +LF+ "Each letter may be used more than once." +LF+LF )
TextWindow.WriteLine( "Scoring: 1=letter and position correct; 0=correct letter,wrong position" +LF+LF )

For lwp=1 To tries
  TextWindow.Write("Try "+lwp+": " + player[lwp][1] + player[lwp][2] + player[lwp][3] + player[lwp][4] + " = ")

  For column=1 To 4
    If player[lwp][column] = computer[column] Then
      TextWindow.Write( "1" )
    ElseIf array.ContainsValue(computer, player[lwp][column]) Then
      TextWindow.Write( "0" )
    EndIf
  EndFor

  TextWindow.WriteLine("")
EndFor

If player[tries][1]<>computer[1] Or player[tries][2]<>computer[2] Or player[tries][3]<>computer[3] Or player[tries][4]<>computer[4] Then
  Goto try
EndIf

TextWindow.WriteLine( "" )
TextWindow.WriteLine( "CONGRATULATIONS, YOU GOT IT!" +LF+LF )
Copyright (c) Microsoft Corporation. All rights reserved.