Created
May 17, 2021 21:20
-
-
Save dmd/c1cd2cef56266bb41572366106350359 to your computer and use it in GitHub Desktop.
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;; Daniel D. ;;; | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(define mertwig | |
(lambda (mine his) | |
(define first-n | |
(lambda (ilist n) | |
(cond [(or (null? ilist) (zero? n)) '()] | |
[else (cons (first ilist) (first-n (rest ilist) (sub1 n)))] ))) | |
(define howmany | |
(lambda (ilist iatom) | |
(cond [(null? ilist) 0] | |
[else (+ (cond | |
[( equal? (first ilist) iatom) 1] | |
[else 0]) | |
(howmany (rest ilist) iatom))] ))) | |
(define agran? | |
(lambda (vec) | |
(let ((x (arhelp vec))) | |
(or (eq? x -2) (eq? x -1) (eq? x 0) (eq? x 1) (eq? x 2))))) | |
(define arhelp | |
(lambda (vec) | |
(cond | |
[(null? vec) 0] | |
[else (cond | |
[(eq? (first vec) 'c) (add1 (arhelp (rest vec)))] | |
[else (sub1 (arhelp (rest vec)))])]))) | |
(define abs | |
(lambda (num) | |
(cond [(>= num 0) num] | |
[else (- 0 num)] ))) | |
(define playing-titfortat? | |
(lambda (mine his) | |
(cond | |
[(and | |
( > (length his) 10) | |
( equal? (first-n his (sub1 (length his))) (rest mine))) #t] | |
[else #f]))) | |
(define 6-check-c? | |
(lambda (his) | |
(cond | |
[(equal? '(c c c c c c) (first-n his 6)) #t] | |
[else #f] ))) | |
(define unresponsive? | |
(lambda (mine his) | |
(cond | |
[(and (equal? '(c c c c) (first-n his 4)) | |
(member? 'd (first-n mine 5))) #t] | |
[else #f] ))) | |
(define collision? | |
(lambda (mine his) | |
(cond | |
[(and | |
(or (equal? '(c d c d) (first-n mine 4)) | |
(equal? '(d c d c) (first-n mine 4))) | |
(or (equal? '(c d c d) (first-n his 4)) | |
(equal? '(d c d c) (first-n his 4)))) | |
#t] | |
[else #f] ))) | |
(define defection-rules? | |
(lambda (his) | |
(cond | |
[( or (null? his) (null? (rest his))) #f] | |
[(zero? (random 25)) #f] | |
[(zero? (random 40)) #t] | |
[(< 2 (howmany (first-n his 5) 'd)) #t] | |
[else #f] ))) | |
(cond | |
[(null? his) 'c] | |
[(defection-rules? his) 'd] | |
[(playing-titfortat? mine his) 'c] | |
[(and (> (length his) 10) | |
(agran? (first-n his 10))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment