Last login: Wed Sep 18 16:12:23 on ttys000 mba:CCM Programming Challenge - Wild Card johnz$ swipl Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.3) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. For online help and background, visit http://www.swi-prolog.org For built-in help, use ?- help(Topic). or ?- apropos(Word). *load the programm ?- consult('attack_and_break.pro'). true. *list all the relation and rules in the KB ?- listing. world :- break, attack. breakable(Name) :- break(Name, level(L), size(S)), L=<5, S\=extra_large. :- multifile prolog_predicate_name/2. play :- breakable(Name), write(Name), nl, fail. play :- attackable(Name), write(Name), nl, fail. play. tiny(Name) :- break(Name, _, size(small)). tiny(Name) :- attack(Name, _, size(small)). attack :- attack(Name, _, _), write(Name), nl, fail. attack. :- multifile prolog_clause_name/2. tiny. :- dynamic prolog_exception_hook/4. :- multifile prolog_exception_hook/4. prolog_exception_hook(error(E, context(Ctx0, Msg)), error(E, context(prolog_stack(Stack), Msg)), Fr, GuardSpec) :- prolog_stack: ( current_prolog_flag(backtrace, true), \+ is_stack(Ctx0, _Frames), ( atom(GuardSpec) -> debug(backtrace, 'Got uncaught (guard = ~q) exception ~p (Ctx0=~p)', [GuardSpec, E, Ctx0]), stack_guard(GuardSpec), Guard=GuardSpec ; prolog_frame_attribute(GuardSpec, predicate_indicator, Guard), debug(backtrace, 'Got exception ~p (Ctx0=~p, Catcher=~p)', [E, Ctx0, Guard]), stack_guard(Guard) ), ( current_prolog_flag(backtrace_depth, Depth) -> Depth>0 ; Depth=20 ), get_prolog_backtrace(Depth, Stack0, [frame(Fr), guard(Guard)]), debug(backtrace, 'Stack = ~p', [Stack0]), clean_stack(Stack0, Stack1), join_stacks(Ctx0, Stack1, Stack) ). humongous(Name) :- break(Name, _, size(extra_large)). humongous(Name) :- attack(Name, _, size(extra_large)). attackable(Name) :- attack(Name, catch(C), size(S)), C=<5, S\=extra_large, S\=large. humongous. attack(bird, catch(8), size(small)). attack(bug, catch(2), size(small)). attack(hellhound, catch(6), size(large)). attack(maillman, catch(3), size(extra_large)). attack(lasagna, catch(1), size(medium)). :- thread_local thread_message_hook/3. :- dynamic thread_message_hook/3. :- volatile thread_message_hook/3. % NOTE: system definition has been overruled for break/0 break :- break(Name, _, _), write(Name), nl, fail. break. break(vase, level(1), size(small)). break(tv, level(3), size(extra_large)). break(lamp, level(8), size(large)). break(cushion, level(5), size(medium)). break(toilet_paper, level(1), size(small)). true. *list all the objects that can be broke ?- break. vase tv lamp cushion toilet_paper true. *list all the objects that can be attacked ?- attack. bird bug hellhound maillman lasagna true. *list the part of the KB pertatning to the world relation ?- listing(world). world :- break, attack. true. *list all the objects in this world ?- world. vase tv lamp cushion toilet_paper bird bug hellhound maillman lasagna true. *list all the objects that is a size of extra large ?- humongous(Name). Name = tv ; Name = maillman. *list all the objects that is a size of small ?- tiny(Name). Name = vase ; Name = toilet_paper ; Name = bird ; Name = bug. *list all the objects in the world that can be broke by cat, programmably ?- breakable(Name),write(Name),nl,fail. vase cushion toilet_paper false. *list all the objects in the world that can be attacked by cat, interactively ?- attackable(Name). Name = bug ; Name = lasagna. *list all the objects in the world that cat can interact with. ?- play. vase cushion toilet_paper bug lasagna true. *exit the programm ?- halt. mba:CCM Programming Challenge - Wild Card johnz$