8-Bit Software Online Conversion

Prisoner's Dilemma - Listing

0MODE7 10REM >Comp1 20REM by Steven Flintham 30REM 40REM Sunday 3rd January 1993 50REM Tuesday 16th February 1993 60: 70PROCinitialise 80PROCcontrol`competition 90PROCshow`results 100END 110: 120DEF PROCinitialise 130DIM move%(200,2) 140RESTORE 150cooperate%=1 160defect%=2 170strategies%=-1 180REPEAT 190READ name$,function$ 200strategies%=strategies%+1 210UNTIL name$="End" 220RESTORE 230DIM name$(strategies%),function$(st rategies%),score%(strategies%) 240FOR read%=1 TO strategies% 250READ name$(read%),function$(read%) 260score%(read%)=0 270NEXT 280ENDPROC 290: 300DEF PROCcontrol`competition 310LOCAL outer%,inner% 320FOR outer%=1 TO strategies% 330FOR inner%=outer% TO strategies% 340PRINT name$(outer%);" v ";name$(inn er%) 350PROCcompete(outer%,inner%) 360NEXT 370NEXT 380ENDPROC 390: 400DEF PROCcompete(outer%,inner%) 410LOCAL outer`action%,inner`action% 420FOR round%=1 TO 200 430outer`action%=EVAL("FN"+function$(o uter%)+"(1)") 440inner`action%=EVAL("FN"+function$(i nner%)+"(2)") 450move%(round%,2)=outer`action% 460move%(round%,1)=inner`action% 470IF move%(round%,1)=cooperate% AND m ove%(round%,2)=cooperate% THEN score%(in ner%)=score%(inner%)+3:score%(outer%)=sc ore%(outer%)+3 480IF move%(round%,1)=cooperate% AND m ove%(round%,2)=defect% THEN score%(outer %)=score%(outer%)+5 490IF move%(round%,2)=cooperate% AND m ove%(round%,1)=defect% THEN score%(inner %)=score%(inner%)+5 500IF move%(round%,1)=defect% AND move %(round%,2)=defect% THEN score%(inner%)= score%(inner%)+1:score%(outer%)=score%(o uter%)+1 510NEXT 520ENDPROC 530: 540DEF PROCshow`results 550LOCAL show%,outer%,inner%,temp$,tem p% 560FOR outer%=1 TO strategies% 570FOR inner%=outer% TO strategies% 580IF score%(inner%)>score%(outer%) TH EN temp$=name$(inner%):name$(inner%)=nam e$(outer%):name$(outer%)=temp$:temp%=sco re%(inner%):score%(inner%)=score%(outer% ):score%(outer%)=temp% 590NEXT 600NEXT 610PRINT'"Name";TAB(30);"Score" 620FOR show%=1 TO strategies% 630PRINT name$(show%);TAB(30)score%(sh ow%) 640NEXT 650ENDPROC 660: 670REM These are the functions which i mplement the strategies 680: 690REM They are each passed one parame ter which is the second subscript 700REM to use when reading the moves a rray in order to obtain their 710REM opponents previous moves 720: 730REM They should return (1) cooperat e% if they wish to cooperate or (2) defe ct% to defect 740: 750DATA Random,random 760DEF FNrandom(discard%) 770=RND(2) 780: 790DATA Tit for Tat,tit`for`tat 800DEF FNtit`for`tat(subscript%) 810IF round%=1 THEN =cooperate% 820=move%(round%-1,subscript%) 830: 840DATA Always Cooperate,always`cooper ate 850DEF FNalways`cooperate(discard%) 860=cooperate% 870: 880DATA Always Defect,always`defect 890DEF FNalways`defect(discard%) 900=defect% 910: 920DATA Tit for Two Tats,tit`for`two`t ats 930DEF FNtit`for`two`tats(subscript%) 940IF round%<=2 THEN =cooperate% 950IF move%(round%-1,subscript%)=defec t% AND move%(round%-2,subscript%)=defect % THEN =defect% 960=cooperate% 970: 980DATA Grudger,grudger 990DEF FNgrudger(subscript%) 1000LOCAL opp`defect%,check% 1010IF round%=1 THEN =cooperate% 1020opp`defect%=FALSE 1030FOR check%=1 TO round%-1 1040IF move%(check%,subscript%)=defect% THEN opp`defect%=TRUE 1050NEXT 1060IF opp`defect% THEN =defect% 1070=cooperate% 1080: 1090DATA Naive Prober,naive`prober 1100DEF FNnaive`prober(subscript%) 1110IF RND(10)=5 THEN =defect% 1120IF round%=1 THEN =cooperate% 1130=move%(round%-1,subscript%) 1140: 1150DATA Suspicious Tit for Tat,susp`ti t`for`tat 1160DEF FNsusp`tit`for`tat(subscript%) 1170IF round%=1 THEN =defect% 1180=move%(round%-1,subscript%) 1190: 1200DATA End,end