So we start with a simple Bunco game written in BASIC.

10 PRINT "BUNCO"

20 S=0:W=INT(RND(1)*200)+300

30 FOR R=1 TO 6

40 PRINT "ROLLING..."

50 FOR Q=1 TO W: X=RND(1): NEXT Q

60 D1=INT(RND(1)*6)+1:D2=INT(RND(1)*6)+1:D3=INT(RND(1)*6)+1

70 PRINT "ROUND:";R;"Rolls:";D1;D2;D3

80 IF (D1=D2) AND (D2=D3) THEN 150

90 IF D1=R THEN S=S+1

100 IF D2=R THEN S=S+1

110 IF D3=R THEN S=S+1

120 PRINT "SCORE ";S

125 INPUT "PRESS ENTER";A$

130 NEXT R

140 PRINT "FINAL SCORE=";S: END

150 IF D1=R THEN PRINT "BUNCO!": S=S+21: GOTO 120

160 PRINT "MINI BUNCO": S=S+5: GOTO 120

The original for this was probably written for my Pocket Computer 2.

The S-BASIC version looks like this:

var s,w,r,q,x,d1,d2,d3=integer

var a=char

PRINT "BUNCO"

S=0

W=INT(RND(1)*200)+300

FOR R=1 TO 6

PRINT "ROLLING..."

FOR Q=1 TO W

X=RND(1)

NEXT Q

D1=INT(RND(1)*6)+1

D2=INT(RND(1)*6)+1

D3=INT(RND(1)*6)+1

PRINT "ROUND:";R;" Rolls:";D1;D2;D3

IF (D1=D2) AND (D2=D3) THEN BEGIN

IF D1=R THEN begin

PRINT "BUNCO!"

S=S+21

end

else begin

PRINT "MINI BUNCO"

S=S+5

end

end

else begin

IF D1=R THEN S=S+1

IF D2=R THEN S=S+1

IF D3=R THEN S=S+1

end

PRINT "SCORE ";S

INPUT "PRESS ENTER";A

NEXT R

PRINT "FINAL SCORE=";S

Now, it certainly is much easier to read and much of the original code is there, but there was a significant amount of change to make this work under S-BASIC.

One gotcha was the

60 D1=INT(RND(1)*6)+1:D2=INT(RND(1)*6)+1:D3=INT(RND(1)*6)+1

The S-BASIC compiler did **not** flag that as an error, but the assignments to D2 and D3 were simply ignored.

But lines 150 and 160

150 IF D1=R THEN PRINT "BUNCO!": S=S+21: GOTO 120

160 PRINT "MINI BUNCO": S=S+5: GOTO 120

Did get a compiler error because they came after the PRINT.

Lines 150 and 160 also have a second gotcha: The way to those lines is a GOTO within the FOR loop. Again, the S-BASIC compiler flagged no problem, but the FOR loop simply exited after the first iteration.

## No comments:

Post a Comment