10 CLS 20 PRINT "This is Mastermind for Pros (TM)." 30 INPUT "How many colors should we use (try 6)"; U1 40 INPUT "How many pegs shall be placed at a time (try 4)"; V1 50 IF V1 <19 THEN 80 60 PRINT "I can't print that much information on a line. Let's take 8 pegs." 70 V1=18 80 INPUT "How many guesses should a person get (try 10)"; W1 90 RANDOMIZE 100 CLS 110 PRINT "Welcome to Mastermind. I'll write the code, you guess it." 120 PRINT "Colors are the numbers 1 through ";U1;". There are ";V1;" pegs. You have ";W1;" guesses." 130 PRINT "Write your guesses like this:" 140 PRINT "(Remember to hit RETURN after each peg's color is chosen.)" 150 PRINT 160 PRINT "Guess #1" 170 FOR I=1 TO V1 180 PRINT "? ";INT(U1*RND)+1 190 NEXT I 200 FOR I=1 TO V1 210 X(I)=INT(U1*RND)+1 220 IF X(I)<=U1 THEN 240 230 X(I)=U1 240 X1(I)=0 250 Y1(I)=0 260 NEXT I 270 L1=V1+2 280 PRINT 290 PRINT "Good luck." 300 INPUT "Hit RETURN when ready to begin.", R$ 310 CLS 320 PRINT " ";U1;" colors, ";V1;" pegs, ";W1;" guesses." 330 REM Here's where each of the w1 turns begins. 340 FOR I=1 TO W1 350 B=0 360 W=0 370 FOR J=1 TO V1 380 X1(J)=0 390 Y1(J)=0 400 NEXT J 410 LOCATE 1 420 FOR K=1 TO V1+2 430 PRINT " " 440 NEXT K 450 LOCATE 1 460 PRINT "Guess #";I 470 FOR K=1 TO V1 480 INPUT Y(K) 490 IF Y(K) >0 AND Y(K) <=U1 THEN 520 500 PRINT "Invalid entry" 510 GOTO 410 520 NEXT K 530 REM Now figure out the score: first the number of black pegs... 540 FOR J=1 TO V1 550 IF X(J)<>Y(J) THEN 590 560 B=B+1 570 X1(J)=1 580 Y1(J)=1 590 NEXT J 600 REM ... and now figure out the number of whites 610 FOR J=1 TO V1 620 IF X1(J)=1 THEN 720 630 FOR K=1 TO V1 640 IF Y1(K)=1 THEN 670 650 IF Y(K)<>X(J) THEN 670 660 GOTO 690 670 NEXT K 680 GOTO 720 690 W=W+1 700 Y1(K)=1 710 X1(J)=1 720 NEXT J 730 REM Now display the results and take another input 740 LET L1=L1 +1 750 IF L1<26 THEN 770 760 LET L1=V1+3 770 LOCATE L1 780 PRINT "Guess #";I;": "; 790 FOR K=1 TO V1 1730 PRINT Y(K);", "; 1740 NEXT K 1750 PRINT "worth";B;"black,";W;"white" 1760 IF B=V1 THEN 1850 1770 NEXT I 1780 REM That's the loop for each turn. Next line for losers: 1790 PRINT "Sorry, your turns are used up. The pattern was"; 1800 FOR I=1 TO V1 1810 PRINT X(I);", "; 1820 NEXT I 1830 PRINT 1840 GOTO 1870 1850 PRINT 1860 PRINT "You got it! Congratulations! It only took you ";I;" guesses! Good job!" 1870 INPUT "Want to play again? (Type y or n ) ", R$ 1880 IF R$="Y" OR R$="y" THEN 20 1890 SYSTEM 1900 END