Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 0010 PROC compare(guess$,secret$)
- 0020 correct:=0
- 0021 misplaced:=0
- 0030 FOR i:=1 TO 4 DO
- 0040 IF guess$(i:i)=secret$(i:i) THEN
- 0050 correct:=correct+1
- 0051 guess$(i:i):=" "
- 0052 secret$(i:i):=" "
- 0060 ENDIF
- 0070 ENDFOR i
- 0071 FOR i:=1 TO 4 DO
- 0072 FOR c:=1 TO 4 DO
- 0073 IF guess$(i:i)<>" " AND guess$(i:i)=secret$(c:c) THEN
- 0074 misplaced:=misplaced+1
- 0075 guess$(i:i):=" "
- 0076 secret$(c:c):=" "
- 0077 ENDIF
- 0078 ENDFOR c
- 0079 ENDFOR i
- 0080 PRINT AT CURROW-1,24: "Correct: ",correct," Misplaced: ",misplaced
- 0090 ENDPROC compare
- 0100 FUNC isin(v,s$)
- 0110 FOR i:=1 TO LEN(s$) DO
- 0120 IF VAL(s$(i:i))=v THEN RETURN TRUE
- 0130 ENDFOR i
- 0140 RETURN FALSE
- 0150 ENDFUNC isin
- 0160 FUNC validate(guess$)
- 0170 IF LEN(guess$)<>4 THEN
- 0180 RETURN FALSE
- 0190 ENDIF
- 0200 FOR i:=1 TO 4 DO
- 0210 IF NOT guess$(i:i) IN "0123456789" THEN RETURN FALSE
- 0220 ENDFOR i
- 0230 RETURN TRUE
- 0240 ENDFUNC validate
- 0250 secret$:=""
- 0260 FOR i:=1 TO 4 DO
- 0270 REPEAT
- 0280 candidate:=INT(RND*8)+1
- 0290 UNTIL NOT isin(candidate,secret$)
- 0300 secret$:=secret$+STR$(candidate)
- 0310 PRINT "Generated value numer ",i," which was ",candidate
- 0320 ENDFOR i
- 0330 PAGE
- 0340 PRINT "Welcome to Mastermind by RetroComputing with Mike"
- 0350 guesses:=0
- 0360 REPEAT
- 0370 INPUT "Guess the code:": guess$
- 0380 IF NOT validate(guess$) THEN
- 0390 PRINT "Your guess should consists of 4 numbers"
- 0400 ELSE
- 0410 guesses:=guesses+1
- 0420 compare(guess$,secret$)
- 0430 ENDIF
- 0440 UNTIL guess$=secret$
- 0450 PRINT "Congratulations, you guessed the secret in ",guesses," attempts"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement