Bulls and Cows


Choosing a four digit number, the computer will respond to your guesses (or deductions, we hope) by displaying a bull when you get a correct digit in the right place, and a cow when a digit you input also occurs in the computer's number, but not in the same place. You should note that the computers number can have the same digit repeated.

You can choose the number of guesses you're allowed, making it more difficult for yourself as you get more practiced.

    1  REM**BULLS AND COWS** **BBC VERSION** 
by I.THOMAS from Spectrum program by R.Erskin
e
   10 VDU23,255,0,96,254,62,62,34,34,34
   20 GOSUB580
   30 DIMA(4),H(4)
   40 CLS
   50 R=RND(1):INPUTTAB(0,19)"How many guesse
s do you want (1-20) ?"T
   60 IFT<1 OR T>20 GOTO50
   70 GOSUB320
   80 CLS:PRINTTAB(0,19)CHR$&86"I have chosen
 my number":TIME=0:REPEAT:UNTILTIME>100
   90 GOSUB370
  100 FORQ=1TOT
  110   PRINTTAB(0,25)"Enter guess ";Q;:INPUT
G
  120   PRINTTAB(13,25)"       "
  130   IFG<1000 OR G>9999 GOTO110
  140   GOSUB190:GOSUB450
  150 IFBL<4 NEXTQ
  160 TIME=0:REPEAT:UNTILTIME>100:GOSUB530
  170 COLOUR10:PRINT'"  Press Space for     a
nother go"
  180 GOSUB650:MODE7:CLEAR:GOTO30
  190 BL=0:WH=0
  200 G$=STR$(G)
  210 FORX=1TO4
  220   A(X)=VAL(MID$(G$,X,1)):H(X)=0
  230   NEXT:FORX=1TO4
  240   IFA(X)=N(X) BL=BL+1:H(X)=1
  250   NEXT:FORX=1TO4
  260   FORY=1TO4
  270     IFH(Y)GOTO290
  280     IFA(X)=N(Y) WH=WH+1:H(Y)=1:Y=4
  290   NEXTY
  300 NEXTX
  310 RETURN
  320 DIMN(4)
  330 FORX=1TO4
  340   N(X)=RND(9)
  350 NEXTX
  360 RETURN
  370 MODE2
  380 GCOL107,0:MOVE0,255:MOVE1279,255
  390 PLOT85,0,957:DRAW1279,255
  400 PLOT85,1279,957
  410 COLOUR2:PRINTTAB(4,30)"ANSWER: ";:COLOU
R129:COLOUR9:VDU19,9,1;0;0:FORX=1TO4:PRINT;N(
X);:NEXT
  420 COLOUR128:COLOUR7
  430 VDU5:GCOL0,0:FORX=1TOT:MOVE31,957-X*32:
PRINT;X:NEXT:VDU4
  440 RETURN
  450 VDU5:GCOL0,4:MOVE191,957-Q*32:PRINT;G
  460 GCOL0,7:MOVE640,957-Q*32
  470 IFWH=0 GOTO490
  480 FORX=1TOWH:VDU255,32:NEXT
  490 IFBL=0 GOTO520
  500 GCOL0,0
  510 FORX=1TOBL:VDU255,32:NEXT
  520 VDU4:RETURN
  530 VDU19,9,7;0;:IFBL<4 GOTO560
  540 COLOUR3:PRINTTAB(0,25)"You are correct"
  550 RETURN
  560 COLOUR1:PRINTTAB(0,25)"You are wrong"
  570 RETURN
  580 MODE7:PRINT''CHR$141;CHR$&81;CHR$157;CH
R$&83"         BULLS AND COWS           "CHR$
156'CHR$141;CHR$&81;CHR$157;CHR$&83"         
BULLS AND COWS           "CHR$156
  590 PRINT''''CHR$&85"     In Bulls  and Cow
s the  computer"'CHR$&85" chooses a four  dig
it  number  which"
  600 PRINTCHR$&85" you  have to  guess."''CH
R$&85"    Each time you enter a four digit"'C
HR$&85" guess,the  computer  will  give  you"
  610 PRINTCHR$&85" clues: each Bull indicate
s a correct"'CHR$&85" digit  in the correct  
position  and"
  620 PRINTCHR$&85" each Cow indicates  a cor
rect  digit"'CHR$&85" in the wrong position."
  630 PRINTCHR$&85"     Bulls are black, Cows
 are  white"
  640 PRINTTAB(0,21)CHR$136;CHR$&83"        P
ress Space to start"
  650 REPEATUNTILGET=32:RETURN