0 MODE7 10 REM >Comp1 20 REM by Steven Flintham 30 REM 40 REM Sunday 3rd January 1993 50 REM Tuesday 16th February 1993 60 : 70 PROCinitialise 80 PROCcontrol_competition 90 PROCshow_results 100 END 110 : 120 DEF PROCinitialise 130 DIM move%(200,2) 140 RESTORE 150 cooperate%=1 160 defect%=2 170 strategies%=-1 180 REPEAT 190 READ name$,function$ 200 strategies%=strategies%+1 210 UNTIL name$="End" 220 RESTORE 230 DIM name$(strategies%),function$(strategies%),score%(strategies%) 240 FOR read%=1 TO strategies% 250 READ name$(read%),function$(read%) 260 score%(read%)=0 270 NEXT 280 ENDPROC 290 : 300 DEF PROCcontrol_competition 310 LOCAL outer%,inner% 320 FOR outer%=1 TO strategies% 330 FOR inner%=outer% TO strategies% 340 PRINT name$(outer%);" v ";name$(inner%) 350 PROCcompete(outer%,inner%) 360 NEXT 370 NEXT 380 ENDPROC 390 : 400 DEF PROCcompete(outer%,inner%) 410 LOCAL outer_action%,inner_action% 420 FOR round%=1 TO 200 430 outer_action%=EVAL("FN"+function$(outer%)+"(1)") 440 inner_action%=EVAL("FN"+function$(inner%)+"(2)") 450 move%(round%,2)=outer_action% 460 move%(round%,1)=inner_action% 470 IF move%(round%,1)=cooperate% AND move%(round%,2)=cooperate% THEN score%(inner%)=score%(inner%)+3:score%(outer%)=score%(outer%)+3 480 IF move%(round%,1)=cooperate% AND move%(round%,2)=defect% THEN score%(outer%)=score%(outer%)+5 490 IF move%(round%,2)=cooperate% AND move%(round%,1)=defect% THEN score%(inner%)=score%(inner%)+5 500 IF move%(round%,1)=defect% AND move%(round%,2)=defect% THEN score%(inner%)=score%(inner%)+1:score%(outer%)=score%(outer%)+1 510 NEXT 520 ENDPROC 530 : 540 DEF PROCshow_results 550 LOCAL show%,outer%,inner%,temp$,temp% 560 FOR outer%=1 TO strategies% 570 FOR inner%=outer% TO strategies% 580 IF score%(inner%)>score%(outer%) THEN temp$=name$(inner%):name$(inner%)=name$(outer%):name$(outer%)=temp$:temp%=score%(inner%):score%(inner%)=score%(outer%):score%(outer%)=temp% 590 NEXT 600 NEXT 610 PRINT'"Name";TAB(30);"Score" 620 FOR show%=1 TO strategies% 630 PRINT name$(show%);TAB(30)score%(show%) 640 NEXT 650 ENDPROC 660 : 670 REM These are the functions which implement the strategies 680 : 690 REM They are each passed one parameter which is the second subscript 700 REM to use when reading the moves array in order to obtain their 710 REM opponents previous moves 720 : 730 REM They should return (1) cooperate% if they wish to cooperate or (2) defect% to defect 740 : 750 DATA Random,random 760 DEF FNrandom(discard%) 770 =RND(2) 780 : 790 DATA Tit for Tat,tit_for_tat 800 DEF FNtit_for_tat(subscript%) 810 IF round%=1 THEN =cooperate% 820 =move%(round%-1,subscript%) 830 : 840 DATA Always Cooperate,always_cooperate 850 DEF FNalways_cooperate(discard%) 860 =cooperate% 870 : 880 DATA Always Defect,always_defect 890 DEF FNalways_defect(discard%) 900 =defect% 910 : 920 DATA Tit for Two Tats,tit_for_two_tats 930 DEF FNtit_for_two_tats(subscript%) 940 IF round%<=2 THEN =cooperate% 950 IF move%(round%-1,subscript%)=defect% AND move%(round%-2,subscript%)=defect% THEN =defect% 960 =cooperate% 970 : 980 DATA Grudger,grudger 990 DEF FNgrudger(subscript%) 1000 LOCAL opp_defect%,check% 1010 IF round%=1 THEN =cooperate% 1020 opp_defect%=FALSE 1030 FOR check%=1 TO round%-1 1040 IF move%(check%,subscript%)=defect% THEN opp_defect%=TRUE 1050 NEXT 1060 IF opp_defect% THEN =defect% 1070 =cooperate% 1080 : 1090 DATA Naive Prober,naive_prober 1100 DEF FNnaive_prober(subscript%) 1110 IF RND(10)=5 THEN =defect% 1120 IF round%=1 THEN =cooperate% 1130 =move%(round%-1,subscript%) 1140 : 1150 DATA Suspicious Tit for Tat,susp_tit_for_tat 1160 DEF FNsusp_tit_for_tat(subscript%) 1170 IF round%=1 THEN =defect% 1180 =move%(round%-1,subscript%) 1190 : 1200 DATA End,end