63 lines
2.1 KiB
Plaintext
63 lines
2.1 KiB
Plaintext
DIM pPLchoice(1 TO 3) AS INTEGER, pCMchoice(1 TO 3) AS INTEGER
|
|
DIM choices(1 TO 3) AS STRING
|
|
DIM playerwins(1 TO 3) AS INTEGER
|
|
DIM playerchoice AS INTEGER, compchoice AS INTEGER
|
|
DIM playerwon AS INTEGER, compwon AS INTEGER, tie AS INTEGER
|
|
DIM tmp AS INTEGER
|
|
|
|
' Do it this way for QBasic; FreeBASIC supports direct array assignment.
|
|
DATA "rock", "paper", "scissors"
|
|
FOR tmp = 1 to 3
|
|
READ choices(tmp)
|
|
NEXT
|
|
DATA 3, 1, 2
|
|
FOR tmp = 1 to 3
|
|
READ playerwins(tmp)
|
|
NEXT
|
|
|
|
RANDOMIZE TIMER
|
|
|
|
DO
|
|
' Computer chooses first to ensure there's no "cheating".
|
|
compchoice = INT(RND * (pPLchoice(1) + pPLchoice(2) + pPLchoice(3) + 3))
|
|
SELECT CASE compchoice
|
|
CASE 0 to (pPLchoice(1))
|
|
' Player past choice: rock; choose paper.
|
|
compchoice = 2
|
|
CASE (pPLchoice(1) + 1) TO (pPLchoice(1) + pPLchoice(2) + 1)
|
|
' Player past choice: paper; choose scissors.
|
|
compchoice = 3
|
|
CASE (pPLchoice(1) + pPLchoice(2) + 2) TO (pPLchoice(1) + pPLchoice(2) + pPLchoice(3) + 2)
|
|
' Player past choice: scissors; choose rock.
|
|
compchoice = 1
|
|
END SELECT
|
|
|
|
PRINT "Rock, paper, or scissors ";
|
|
DO
|
|
PRINT "[1 = rock, 2 = paper, 3 = scissors, 0 to quit]";
|
|
INPUT playerchoice
|
|
LOOP WHILE (playerchoice < 0) OR (playerchoice > 3)
|
|
|
|
IF 0 = playerchoice THEN EXIT DO
|
|
|
|
pCMchoice(compchoice) = pCMchoice(compchoice) + 1
|
|
pPLchoice(playerchoice) = pPLchoice(playerchoice) + 1
|
|
PRINT "You chose "; choices(playerchoice); " and I chose "; choices(compchoice); ". ";
|
|
IF (playerchoice) = compchoice THEN
|
|
PRINT "Tie!"
|
|
tie = tie + 1
|
|
ELSEIF (compchoice) = playerwins(playerchoice) THEN
|
|
PRINT "You won!"
|
|
playerwon = playerwon + 1
|
|
ELSE
|
|
PRINT "I won!"
|
|
compwon = compwon + 1
|
|
END IF
|
|
LOOP
|
|
|
|
PRINT "Some useless statistics:"
|
|
PRINT "You won "; STR$(playerwon); " times, and I won "; STR$(compwon); " times; "; STR$(tie); " ties."
|
|
PRINT , choices(1), choices(2), choices(3)
|
|
PRINT "You chose:", pPLchoice(1), pPLchoice(2), pPLchoice(3)
|
|
PRINT " I chose:", pCMchoice(1), pCMchoice(2), pCMchoice(3)
|