Microsoft Small Basic

Program Listing:
Embed this in your website
' MASTERMIND for SmallBasic by DaveyWavey, March 2010. v1
' modified by Nonki Takahashi, October 2019. v3
' Program ID JBH373-2

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(6), 1)
computer[2]=text.GetSubText("ABCDEF", Math.GetRandomNumber(6), 1)
computer[3]=text.GetSubText("ABCDEF", Math.GetRandomNumber(6), 1)
computer[4]=text.GetSubText("ABCDEF", Math.GetRandomNumber(6), 1)

' now let the player try to guess what the computer has chosen
try = "True"
While try

  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

  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 line[column]=player[lwp][column] Then
        line[column]="" ' matched
    For column=1 To 4
      If Array.ContainsValue(line, color) Then
        RemoveColorFromLine() 'matched


  If player[tries][1]=computer[1] And player[tries][2]=computer[2] And player[tries][3]=computer[3] And player[tries][4]=computer[4] Then
    try = "False"


Sub RemoveColorFromLine
  ' param line - colors given by player
  ' param color - to remove
  For _column=1 To 4
    If line[_column]=color Then
      line[_column]=""  ' mached
      _column=4         ' exit For
Copyright (c) Microsoft Corporation. All rights reserved.