% % logic.pl -- the Knight/Knave identifier... % % Author: % % Comments: % % some "nice" prolog settings... see assignment 8's % description for the details on what these do % -- but it's not crucial to know the details of these Prolog internals :- set_prolog_flag( prompt_alternatives_on, groundness ). :- set_prolog_flag(toplevel_print_options, [quoted(true), portray(true), attributes(portray), max_depth(999), priority(699)]). % % noVars( X ) is true if X is an expression that does not % contain any logical variables, that is, no % integers. (The expressions will not hold any % Prolog variables in any case... .) % % Remember that you'll need one more rule here % for expressions with only ONE subexpression! % noVars( t ). noVars( f ). noVars( [_, L, R] ) :- noVars( L ), noVars( R ). % % getVar( Expr, N ) is true if Expr is an expression with a % logical variable, that is, an integer % Then, N should be bound to one of those % available variables (again, an integer) % % Remember that you'll need one more rule here % for expressions with only ONE subexpression! % getVar( N, N ) :- number( N ). getVar( [_, L, R], N ) :- getVar( L, N ); (noVars(L), getVar( R, N)).