Created
December 2, 2013 10:14
-
-
Save mavant/7747513 to your computer and use it in GitHub Desktop.
Writing this seemed more appealing than packing for a flight.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (prisoners-dilemma player1 player2) ;;Payoffs correspond to years in prison (lower is better) | |
(let ((p1 (player1 player2 prisoners-dilemma)) ;;Each player is given the other player's source code and the game's source code | |
(p2 (player2 player1 prisoners-dilemma))) | |
(cond | |
((and (equal? p1 'C) (equal? p2 'C)) (cons 1 1)) | |
((and (equal? p1 'C) (equal? p2 'D)) (cons 3 0)) | |
((and (equal? p1 'D) (equal? p2 'C)) (cons 0 3)) | |
((and (equal? p1 'D) (equal? p2 'D)) (cons 2 2))))) | |
(define (nicebot . z) 'C) ;;nicebot ignores the opponent and game; it always cooperates | |
(define (jerkbot . z) 'D) ;;jerkbot always defects. | |
(define (testofcharacterbot opponent game) ;;testofcharacterbot does whatever the opponent would do to something like nicebot | |
(opponent nicebot game)) | |
(define (vizzinibot opponent game) | |
;;vizzinibot tries to predict the opponent's action and make a rational choice based on it. | |
;;vizzinibot does NOT try to do any self-modeling (which is presumably why it doesn't think there's anything odd about shouting 'INCONCEIVABLE!' whenever its plans go awry... | |
(define (singleactionbot x) (lambda (o g) x)) | |
(define (choose l init) ;;Looks at a list of action-payoff pairs, chooses the action with the lowest payoff | |
(cond ((null? l) (car init)) | |
((> (cdr init) (cdr (car l))) (choose (cdr l) (car l))) | |
(else (choose (cdr l) init)))) | |
(define (ponder act) ;;Predicts (to first order) the payoff of certain actions, based on the game structure and the opponent | |
(cons act (car (game (singleactionbot act) opponent)))) | |
(choose (map ponder '(C D)) (cons 'unknown 100))) | |
;;vizzinibot defects against nicebot and jerkbot (as it should) | |
(testofcharacterbot vizzinibot prisoners-dilemma);;testofcharacterbot predicts that vizzinibot would defect against nicebot (and so defects) | |
(vizzinibot testofcharacterbot prisoners-dilemma);;Meanwhile vizzinibot predicts that testofcharacterbot would cooperate against an always-cooperating agent, so it cooperates... | |
(prisoners-dilemma vizzinibot testofcharacterbot);;Thus, testofcharacterbot defects while vizzinibot cooperates. Maybe vizzinibot isn't so clever after all (it could at least have defected too!) | |
(vizzinibot vizzinibot prisoners-dilemma);;And vizzinibot defects against itself, which seals the deal. Nicebot and testofcharacterbot both do better! | |
;;Maybe we can make it smarter. | |
(define (vizzinibot2 opponent game) ;;vizzinibot2 checks whether vizzinibot would cooperate while its opponent defected. | |
(cond ((= 3 (car (game vizzinibot opponent))) 'D) ;If it would, then vizzinibot2 defects instead. | |
(else (vizzinibot opponent game)))) ;Otherwise it does whatever vizzinibot would. | |
(prisoners-dilemma vizzinibot2 testofcharacterbot);;vizzinibot2 defects against testofcharacterbot, so that's good. | |
(prisoners-dilemma vizzinibot2 vizzinibot2);;But it still doesn't cooperate with itself (or vizzinibot). How can we fix that? | |
(define (fairbot opponent game) ;;The obvious thought is a bot that does exactly what it thinks its opponent will do, but there's an obvious problem there... | |
(opponent fairbot game)) | |
(prisoners-dilemma fairbot nicebot);;See, it works against nicebot | |
(prisoners-dilemma fairbot jerkbot);;And against jerkbot | |
(prisoners-dilemma fairbot testofcharacterbot);;And testofcharacterbot | |
(prisoners-dilemma fairbot vizzinibot2);;And it even gets the vizzinibots to cooperate! | |
;(prisoners-dilemma fairbot fairbot) ;;But when it plays against itself, there's an infinite loop. | |
;Solving that in a robust manner is... thorny to say the least. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment