Anonymous user
Go Fish/Locomotive Basic: Difference between revisions
improved dealing and AI
(Created page with "<lang locobasic>10 cls:randomize time:defint a-z 20 dim play(13),compu(13),deck(13),guess(13),poss(13) 30 card$="A234567890JQK" 40 remca=4*13-2*9 50 for i=1 to 13:deck(i)=4:next ...") |
(improved dealing and AI) |
||
Line 1:
<lang locobasic>10 cls:randomize time:defint a-z
20 dim play(13),compu(13),deck(13),guess(13),poss(13),asked(13)
30 card$="A234567890JQK"
40 remca=4*13
50 for i=1 to 13:deck(i)=4:next
60 for i=1 to 9
70
80 deck(k)=
90
100 deck(k)=deck(k)-1▼
110
130
140
150
▲160 play(k)=play(k)+1
170 input "What is your name";name$
180
190 print "======="▼
200 print ,remca"cards remaining"
210
220
▲230 print "Score: "name$;score(0);" Computer: ";score(1)
240 for j=1 to play(i)
250 print mid$(card$,i,1);"
260
270 ' NEXT_CARD
▲270 if play(i)=0 then 320
280
290 print
300
310
320
▲330 print
340
▲350 gosub 1100
370 if play(cn)=0 then print "You do not have that card!":goto 310
▲370 input "Which card do you ask for";c$
380 guess(cn)=1
▲380 cn=instr(card$,upper$(c$))
390 if compu(cn)=0 then print s$"
▲400 if play(cn)=0 then print "You do not have that card!":goto 350
410
420 if compu(cn)=0 then print s$", go fish!":print s$" draws a ";:gosub 760:gosub 920:goto 500▼
▲430 v=compu(cn)
440
▲450 play(cn)=play(cn)+v
460 ' COMPUTER_TURN_1
▲460 print s$" gets"v"more cards."
470
480
490
500
510 ' COMPUTER_TURN_2
510 po=0▼
520
540
550 if
560
570
580 ' DRAW_GUESS
580 if poss(k)=0 then 570▼
590
▲600 goto 650
610
620 asked(k)=
630 if compu(k)=0 then 620▼
640 '
650 k=rnd*12+1
650 print "Computer wants a "mid$(card$,k,1)▼
670
680 play(k)=0▼
690
▲
700 print s$" gets"v"more cards."▼
710
720
730 compu(k)=compu(k)+v
▲730 goto 230
740 end▼
750
760
770 goto 190
770 if deck(k)=0 then 760▼
780 print mid$(card$,k,1)▼
790 ' DRAW_CARD_P
800 gosub 1250
810 remca=remca-1▼
830 ' DRAW_CARD_C▼
840
860
880
890
900 return
910 ' CHECK_BOOK_P
920 for i=1 to 13
930 if play(i)<>4 then 980
940 print s$" completes book of "mid$(card$,i,1)"'s."
950 play(i)=0
960 score(0)=score(0)+1
Line 101:
1010 for i=1 to 13
1020 if compu(i)<>4 then 1070
1030 print s$" completes book of "mid$(card$,i,1)"'s."
1040 compu(i)=0
1050 score(1)=score(1)+1
Line 119:
1190 print "*** Game over! ***"
1200 print
1210 if score(0)>score(1) then print name$" has won.":end
1220 if score(0)<score(1) then print "The computer has won.":end
1230 print "It's a tie!":end
1240 ' DEAL_CARD
1260 sc=remca*rnd+1
1270 for k=1 to 13
1280 sc=sc-deck(k)
1300 next</lang>
Note: 10's are called 0's here to get single-letter rank names.
|