Iterating towards a goal
Executive summary:


please_use_very_readable_names insteadOfUnreadableOneslikeInJava.
Use higher-order predicates.
Always consider using DCGs when describing lists. pass1 and pass2 can be simplified a lot with DCGS.
Use format/2 instead of multiple write/1 calls.




Examples:

Higher order predicate maplist/2, replacing 4 almost identical member/2 calls:

make_guess(Guess) :-
    length(Guess, 4),
    Colours = [red, blue, green, yellow, orange, purple, pink],
    maplist(list_member(Colours), Guess).

list_member(Ls, M) :- member(M, Ls).


Sample query and its result:

?- make_guess(Gs).
Gs = [red, red, red, red] ; 
Gs = [red, red, red, blue] ;
Gs = [red, red, red, green].


Further example, for counting the number if white elements with the higher-order predicate include/3:

list_num_white(Ls, N) :-
    include(=(white), Ls, Ws),
    length(Ws, N).


Sample query and its result:

?- list_num_white([white,black,white], N).
N = 2


Exercise: Generalize this by parametrizing the element, so that you can use list_element_count(Ls, black, N) and list_element_count(Ls, white, N).

Example for format/2: Instead of:

write(Guess), write(' '), write(ThisScore),nl


you can write:

format("~w ~w\n", [Guess,ThisScore])