From 8599c2de33c0caeebc0a32ee48694324bf610719 Mon Sep 17 00:00:00 2001 From: Iden Watanabe Date: Sun, 4 Dec 2016 12:44:27 -0500 Subject: [PATCH 1/5] Modified 2-color, usually-fewer, ab-color --- lib/SCSAmatcher.lisp | 30 ++++++++++++++++++------------ lib/genetic.lisp | 6 +++--- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/SCSAmatcher.lisp b/lib/SCSAmatcher.lisp index 5f7342c..09d677f 100644 --- a/lib/SCSAmatcher.lisp +++ b/lib/SCSAmatcher.lisp @@ -132,16 +132,18 @@ ;;2-color list ;; remove duplicates from guess, if is length 2 then this is true -(defun 2-color-checker-p (guess) - (if (equal (length (remove-duplicates guess)) 2) T)) +(defun 2-color-checker-p (guess colors) + (let ((result (my-color-counter colors guess))) + (sort result #'> ) + (if (= (+ (aref result 0) (aref result 1)) (length guess)) T))) ;;list of only AB ;; remove duplicates from guess if the list is length 2 and only has A and B this is true -(defparameter result nil) +; (defparameter result nil) -(defun AB-checker-p (guess) - (progn(setq result (remove-duplicates guess)) - (if (and (equal (length result) 2) (member 'A result) (member 'B result)) T))) +(defun AB-checker-p (guess colors) + (let ((result (my-color-counter colors guess))) + (if (= (+ (aref result 0) (aref result 1)) (length guess)) T))) ;;list of alternate 2 colors ;;Use mystery-4 code @@ -166,8 +168,12 @@ ;;Fewer colors (2 or 3) ;;remove duplicates from guess and check length if lenght is <= 3 then true -(defun less-than-three-checker-p (guess) - (if (<= (length (remove-duplicates guess)) 3) T)) +(defun less-than-three-checker-p (guess colors) + (let ((result (my-color-counter colors guess))) + (sort result #'>) + (if (= (+ (aref result 0) (aref result 1) (aref result 2)) + (length guess)) + T))) ;;makes a list with preference for fewer colors ;; 50% chance to have 1 color @@ -177,17 +183,17 @@ ;; 3% chance to have 5 colors ;; 1% chance to have 6 colors -(defun matches-scsa (scsa-name code) +(defun matches-scsa (scsa-name code colors) (cond ( (equal scsa-name 'two-color) - (if (2-color-checker-p code) 1 0)) + (if (2-color-checker-p code colors) 1 0)) ( (equal scsa-name 'prefer-fewer) (score-prefer-fewer code)) ( (equal scsa-name 'ab-color) - (if (AB-checker-p code) 1 0)) + (if (AB-checker-p code colors) 1 0)) ( (equal scsa-name 'two-color-alternating) (if (2-color-alt-checker-p code) 1 0)) @@ -199,7 +205,7 @@ (if (first-last-checker-p code) 1 0)) ( (equal scsa-name 'usually-fewer) - (if (less-than-three-checker-p code) 1 0)) + (if (less-than-three-checker-p code colors) 1 0)) ( (equal scsa-name 'mystery-1) (if (mystery-1-checker-p code) 1 0)) diff --git a/lib/genetic.lisp b/lib/genetic.lisp index 0bfcadf..3b288e8 100644 --- a/lib/genetic.lisp +++ b/lib/genetic.lisp @@ -39,9 +39,9 @@ for score = (- slick diff-cows diff-bulls) sum score)) -(defun scsa-consistency-score (scsa-name individual number-of-guesses) +(defun scsa-consistency-score (scsa-name individual number-of-guesses colors) (* - (matches-scsa scsa-name individual) + (matches-scsa scsa-name individual colors) (length individual) number-of-guesses *scsa-consistency-multiplier*)) @@ -50,7 +50,7 @@ "Determines fitness of individual based on how consistent it is with past guesses and responses" (+ (response-similarity-score individual colors guesses responses) - (scsa-consistency-score scsa-name individual (length guesses)))) + (scsa-consistency-score scsa-name individual (length guesses) colors))) (defun population-by-fitness (population colors guesses responses scsa-name) (mapcar From 6d4768245c18dce6645fce6f9bda845e9f48a1d1 Mon Sep 17 00:00:00 2001 From: Iden Watanabe Date: Sun, 4 Dec 2016 15:07:54 -0500 Subject: [PATCH 2/5] Tiny but important fix on sort --- lib/SCSAmatcher.lisp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/SCSAmatcher.lisp b/lib/SCSAmatcher.lisp index 09d677f..4c48707 100644 --- a/lib/SCSAmatcher.lisp +++ b/lib/SCSAmatcher.lisp @@ -134,7 +134,7 @@ ;; remove duplicates from guess, if is length 2 then this is true (defun 2-color-checker-p (guess colors) (let ((result (my-color-counter colors guess))) - (sort result #'> ) + (setf result (sort result #'> )) (if (= (+ (aref result 0) (aref result 1)) (length guess)) T))) ;;list of only AB @@ -170,7 +170,7 @@ ;;remove duplicates from guess and check length if lenght is <= 3 then true (defun less-than-three-checker-p (guess colors) (let ((result (my-color-counter colors guess))) - (sort result #'>) + (setf result (sort result #'>)) (if (= (+ (aref result 0) (aref result 1) (aref result 2)) (length guess)) T))) From d2883a8268f0ca73d81a1140f5874ee9ebce03bc Mon Sep 17 00:00:00 2001 From: Iden Watanabe Date: Sun, 4 Dec 2016 17:37:27 -0500 Subject: [PATCH 3/5] less-than-3 returns .9 or .1 --- lib/SCSAmatcher.lisp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/SCSAmatcher.lisp b/lib/SCSAmatcher.lisp index 4c48707..1db2c74 100644 --- a/lib/SCSAmatcher.lisp +++ b/lib/SCSAmatcher.lisp @@ -135,7 +135,9 @@ (defun 2-color-checker-p (guess colors) (let ((result (my-color-counter colors guess))) (setf result (sort result #'> )) - (if (= (+ (aref result 0) (aref result 1)) (length guess)) T))) + (if (= (+ (aref result 0) (aref result 1)) + (length guess)) + T))) ;;list of only AB ;; remove duplicates from guess if the list is length 2 and only has A and B this is true @@ -156,7 +158,7 @@ ;;a list in which colors appear at most once ;;remove duplicates in a guess and see if length changes, if not then true -(defun at-most-once-checker-p (guess) +(defun at-most-once-checker-p (guess colors) (if (equal (length guess) (length (remove-duplicates guess))) T)) @@ -167,13 +169,16 @@ ;;Fewer colors (2 or 3) -;;remove duplicates from guess and check length if lenght is <= 3 then true +;;remove duplicates from guess and check length if length is <= 3 then true (defun less-than-three-checker-p (guess colors) - (let ((result (my-color-counter colors guess))) + (let ((result (my-color-counter colors guess)) + (total 0)) (setf result (sort result #'>)) - (if (= (+ (aref result 0) (aref result 1) (aref result 2)) - (length guess)) - T))) + (setf total (+ (aref result 0) (aref result 1) (aref result 2))) + (if (or (= total 3) + (= total 2)) + 0.9 + 0.1))) ;;makes a list with preference for fewer colors ;; 50% chance to have 1 color @@ -199,7 +204,7 @@ (if (2-color-alt-checker-p code) 1 0)) ( (equal scsa-name 'only-once) - (if (at-most-once-checker-p code) 1 0)) + (if (at-most-once-checker-p code colors) 1 0)) ( (equal scsa-name 'first-and-last) (if (first-last-checker-p code) 1 0)) From fbf1def52f424f2d3af98b59b1c9f267f0e5e0f2 Mon Sep 17 00:00:00 2001 From: Iden Watanabe Date: Sun, 4 Dec 2016 18:25:00 -0500 Subject: [PATCH 4/5] Update SCSAmatcher.lisp --- lib/SCSAmatcher.lisp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/SCSAmatcher.lisp b/lib/SCSAmatcher.lisp index 1db2c74..09f6a88 100644 --- a/lib/SCSAmatcher.lisp +++ b/lib/SCSAmatcher.lisp @@ -141,7 +141,6 @@ ;;list of only AB ;; remove duplicates from guess if the list is length 2 and only has A and B this is true -; (defparameter result nil) (defun AB-checker-p (guess colors) (let ((result (my-color-counter colors guess))) @@ -170,7 +169,7 @@ ;;Fewer colors (2 or 3) ;;remove duplicates from guess and check length if length is <= 3 then true -(defun less-than-three-checker-p (guess colors) +(defun usually-fewer-p (guess colors) (let ((result (my-color-counter colors guess)) (total 0)) (setf result (sort result #'>)) @@ -210,7 +209,7 @@ (if (first-last-checker-p code) 1 0)) ( (equal scsa-name 'usually-fewer) - (if (less-than-three-checker-p code colors) 1 0)) + (if (usually-fewer-p code colors) 1 0)) ( (equal scsa-name 'mystery-1) (if (mystery-1-checker-p code) 1 0)) @@ -226,4 +225,4 @@ ( (equal scsa-name 'mystery-5) (score-mystery-5 code)) - (t 0))) \ No newline at end of file + (t 0))) From 7941716b836e6cf482d52e10c7956a0c528625d8 Mon Sep 17 00:00:00 2001 From: Iden Watanabe Date: Sun, 4 Dec 2016 18:27:19 -0500 Subject: [PATCH 5/5] Update SCSAmatcher.lisp --- lib/SCSAmatcher.lisp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/SCSAmatcher.lisp b/lib/SCSAmatcher.lisp index 09f6a88..6896cfd 100644 --- a/lib/SCSAmatcher.lisp +++ b/lib/SCSAmatcher.lisp @@ -144,7 +144,9 @@ (defun AB-checker-p (guess colors) (let ((result (my-color-counter colors guess))) - (if (= (+ (aref result 0) (aref result 1)) (length guess)) T))) + (if (= (+ (aref result 0) (aref result 1)) + (length guess)) + T))) ;;list of alternate 2 colors ;;Use mystery-4 code