10

Greed


It's interesting to observe the tactics adopted by different people when playing this game. The computer rolls a dice (or die, if you insist) and asks if you want to roll again. The point is that the dice scores keep adding up for as long as you like, until a one is rolled, when the score is reduced to zero and play passes to the next player. However, if you drop out at any time, the score is retained and added to your total score. The player first reaching a total score of 200 is the winner. There is the cautious type of player who agonises over every decision; the dashing type who recklessly goes on rolling and rolling; and the super-cautious type who rarely rolls more than once, and never - but never - rolls three times. Perhaps we should call the game 'Caution'.
   What should our tactics be? Taken over a long period of time, the dice will show an almost equal frequency of ones, twos, threes, etc., so strictly speaking, if we roll five times without showing a one, we ought to be satisfied. On the other hand . . .
   Any number of players may take part. During the game the current player is addressed by name, so that no confusion may arise. On his turn, the player sees a labelled box with his overall score, another with his score in turn, one for the dice roll and, finally, a question asking if he wishes to roll again. Press Y (RETURN) or RETURN alone for another throw. Press N (RETURN) to retain the score.
   Lines 50 to 70 accept the players' names and we go straight into the game. The listing should be quite self-explanatory and easy to follow, except perhaps for the reminder about the parameters that are passed to PROCbox. In order these are (1) position of box from left of screen, (2) position down from top of screen, (3) its length internally; i.e. number of characters it can hold, (4) its height internally, (5) its colour, and (6) whether or not an input is required.

Variables

PL%Number of players
P%(X)Total score for each player
P$(X)Name of each player (maximum 12 characters).
X%General counter
PLAYER%Number of current player
SCORE%Current score not yet secured
X$Player input Y or N (or just RETURN)
DICEDice throw
W$Dummy

   10 MODE7:PROCTITLE("GREED")
   20 INPUT'''"How many players",PL%:IF PL%>8 GOTO10
   30 DIM P%(PL%),P$(PL%)
   40 CLS:PRINT''"Please type your names"
   50 FOR X%=1 TO PL%:PRINT''"Player #";X%
   60 PROCbox(12,X%*2+3,12,1,148,0)
   70 P$(X%)=X$:NEXT
   80  
   90 REM - Game loop
  100  
  110 REPEAT
  120 FOR PLAYER%=1 TO PL%
  130 CLS:PROCTITLE(P$(PLAYER%)+"'S TURN")
  140 PRINT''''"Score so far":PROCbox(15,11,3,1,148,1)
  150 PRINTTAB(17,11);CHR$135;P%(PLAYER%);CHR$148
  160 SCORE%=0
  170  
  180 REM - Player's loop
  190  
  200 PRINTTAB(0,14);"Score this turn"
  210 PROCbox(15,14,3,1,148,1)
  220 PRINTTAB(17,14);CHR$135;SCORE%;CHR$148
  230 PRINTTAB(0,17);"Roll die (Y-N)?"
  240 PROCbox(17,17,1,1,148,0)
  250 IF X$<>"N" GOTO 290
  260 P%(PLAYER%)=P%(PLAYER%)+SCORE%
  270 IF P%(PLAYER%)>=200 GOTO 410
  280 GOTO 370
  290 DICE=RND(6)
  300 PRINTTAB(0,19);"Roll"
  310 PROCbox(17,19,1,1,148,1)
  320 PRINTTAB(19,19);CHR$135;DICE;CHR$148
  330 IF DICE=1 GOTO360
  340 W$=INKEY$(300):SCORE%=SCORE%+DICE
  350 PRINTTAB(20,19);" ":GOTO200
  360 PRINT'"You lose.  Score this turn=0"
  370 PROCRET:NEXT PLAYER%
  380 UNTIL 0
  390  
  400 REM - A winner
  410  
  420 CLS:PROCDBL(0,5,129,P$(PLAYER%)+" WINS!")
  430 END
  440  
  450 DEFPROCTITLE(X$)
  460 PRINTCHR$132;STRING$(19,"Oo")
  470 PROCDBL((36-LEN(X$))/2,4,131,X$)
  480 PRINTCHR$132;STRING$(19,"Oo")
  490 ENDPROC
  500  
  510 DEFPROCDBL(X%,Y%,C%,X$)
  520 PRINTTAB(X%,Y%);CHR$141;CHR$C%;X$
  530 PRINTTAB(X%,Y%+1);CHR$141;CHR$C%;X$
  540 ENDPROC
  560 DEFPROCbox(X%,Y%,L%,H%,C%,F%)
  570 LOCALV%,W%,I%,J%
  580 PRINTTAB(X%,Y%);
  590 V%=VPOS:W%=POS
  600 PRINTTAB(W%,V%-H%);CHR$C%;"7";
  610 FORI%=0TOL%+1:PRINT"£";:NEXT
  620 PRINT"k":PRINTTAB(W%,V%+1);CHR$C%;"u";
  630 FORI%=0TOL%+1:PRINT"p";:NEXT:PRINT"z"
  640 FORJ%=V%-H%+1TOV%:PRINTTAB(W%,J%);CHR$C%;"5":NEXT
  650 FORJ%=V%-H%+1TOV%
  660 PRINTTAB(W%+L%+3,J%);CHR$C%;"j":NEXT
  670 IF F%GOTO750
  680 PRINTTAB(W%+2,V%);"";
  690 FORI%=1TOL%:PRINT".";:NEXT
  700 PRINTTAB(W%+3,V%);:X$=""
  710 G$=GET$:IF ASCG$=13 GOTO750
  720 IF ASCG$<>127 PRINT;G$;:X$=X$+G$:GOTO710
  730 IF X$="" GOTO 710
  740 X$=LEFT$(X$,1):PRINTCHR$8;".";CHR$8:GOTO710
  750 ENDPROC
  760  
  770 DEFPROCRET
  780 PRINTTAB(5,23);CHR$131;"Press";
  790 PRINTCHR$132;CHR$157;CHR$129;"RETURN  ";CHR$156;
  800 ENDPROC