Rock-paper-scissors: Difference between revisions
Content added Content deleted
No edit summary |
(Added tiny Minimal BASIC program) |
||
Line 254: | Line 254: | ||
rock paper scissors |
rock paper scissors |
||
You chose: 60 0 1 |
You chose: 60 0 1 |
||
I chose: 2 55 4 |
I chose: 2 55 4 |
||
{{works with|uBasic}} |
|||
This works with a tiny, integer BASIC interpreter. The expression: |
|||
CHOOSE X=3 |
|||
Is equivalent to: |
|||
LET X=INT(RND(1)*3) |
|||
This implementation uses a 6-bits binary scheme, where the lower three bits represent the choice of the user and the higher three bits the choice of the computer: |
|||
<lang ubasic> 20 LET P=0: LET Q=0: LET Z=0 |
|||
30 INPUT "Rock, paper, or scissors (1 = rock, 2 = paper, 3 = scissors)? ", A |
|||
40 IF A>3 THEN GOTO 400 |
|||
50 IF A=3 THEN LET A=4 |
|||
60 IF A<1 THEN GOTO 400 |
|||
70 CHOOSE C=3 : LET D=4: FOR B=1 TO C+1 : LET D = D+D : NEXT : GOTO (A+D)*10 |
|||
90 Z=Z+1 : PRINT "We both chose 'rock'. It's a draw." : GOTO 30 |
|||
100 P=P+1 : PRINT "You chose 'paper', I chose 'rock'. You win.." : GOTO 30 |
|||
120 Q=Q+1 : PRINT "You chose 'scissors', I chose 'rock'. I win!" : GOTO 30 |
|||
170 Q=Q+1 : PRINT "You chose 'rock', I chose 'paper'. I win!" : GOTO 30 |
|||
180 Z=Z+1 : PRINT "We both chose 'paper'. It's a draw." : GOTO 30 |
|||
200 P=P+1 : PRINT "You chose 'scissors', I chose 'paper'. You win.." : GOTO 30 |
|||
330 P=P+1 : PRINT "You chose 'rock', I chose 'scissors'. You win.." : GOTO 30 |
|||
340 Q=Q+1 : PRINT "You chose 'paper', I chose 'scissors'. I win!" : GOTO 30 |
|||
360 Z=Z+1 : PRINT "We both chose 'scissors'. It's a draw." : GOTO 30 |
|||
400 PRINT "There were ";Z;" draws. I lost ";P;" times, you lost ";Q;" times." : END</lang> |
|||
A sample game: |
|||
Rock, paper, or scissors (1 = rock, 2 = paper, 3 = scissors)? 1 |
|||
You chose 'rock', I chose 'paper'. I win! |
|||
Rock, paper, or scissors (1 = rock, 2 = paper, 3 = scissors)? 2 |
|||
You chose 'paper', I chose 'scissors'. I win! |
|||
Rock, paper, or scissors (1 = rock, 2 = paper, 3 = scissors)? 3 |
|||
You chose 'scissors', I chose 'paper'. You win.. |
|||
Rock, paper, or scissors (1 = rock, 2 = paper, 3 = scissors)? 1 |
|||
You chose 'rock', I chose 'paper'. I win! |
|||
Rock, paper, or scissors (1 = rock, 2 = paper, 3 = scissors)? 2 |
|||
We both chose 'paper'. It's a draw. |
|||
Rock, paper, or scissors (1 = rock, 2 = paper, 3 = scissors)? 3 |
|||
You chose 'scissors', I chose 'rock'. I win! |
|||
Rock, paper, or scissors (1 = rock, 2 = paper, 3 = scissors)? 4 |
|||
There were 1 draws. I lost 1 times, you lost 4 times. |
|||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |