% % astro2.pl -- prolog program to determine what you're looking at in % the night sky % % Brian "Beej" Hall % % to run, start prolog and do the following: % % ?- consult(astro2). % ?- itsa(X). % % or, you could query a specific object to see if you have it right: % % ?- itsa('inner planet'). % % % itsa/1: this is the predicate you look for matches in % itsa('galaxy') :- galaxy. itsa('star') :- star. itsa('planetoid') :- planetoid. itsa('cluster') :- cluster. itsa('nebula') :- nebula. itsa('sun') :- sun. itsa('moon') :- moon. itsa('barred spiral galaxy') :- barred_spiral_galaxy. itsa('spiral galaxy') :- spiral_galaxy. itsa('elliptical galaxy') :- elliptical_galaxy. itsa('irregular galaxy') :- irregular_galaxy. itsa('sunlike') :- sunlike. itsa('white dwarf') :- white_dwarf. itsa('red giant') :- red_giant. itsa('black hole') :- black_hole. itsa('comet') :- comet. itsa('asteroid') :- asteroid. itsa('planet') :- planet. itsa('inner planet') :- inner. itsa('outer planet') :- outer. itsa('open cluster') :- open. itsa('globular cluster') :- globular. itsa('emission nebula') :- emission. itsa('planetary nebula') :- planetary. itsa('dark') :- dark. % % definition of individual objects % galaxy :- fuzzy, not(moves), not(individual_stars). star :- point, not(moves). planetoid :- moves. cluster :- fuzzy, not(moves), individual_stars. nebula :- fuzzy, not(individual_stars), not(moves). sun :- large, bright, moves. moon :- large, bright, crescent, moves. spiral_galaxy :- galaxy, spiral. barred_spiral_galaxy :- galaxy, bar. elliptical_galaxy :- galaxy, elliptical. irregular_galaxy :- galaxy, not(barred_spiral_galaxy), not(spiral_galaxy), not(elliptical_galaxy). sunlike :- star, yellow. white_dwarf :- star, white. red_giant :- star, red. black_hole :- star, black. comet :- planetoid, fuzzy. asteroid :- planetoid, point. planet :- planetoid, disk. inner :- planet, crescent. outer :- planet, not(crescent). open :- cluster, not(many_stars). globular :- cluster, many_stars. emission :- nebula, glowing, not(ring). planetary :- nebula, glowing, ring. dark :- nebula, not(glowing). % % These are the individual elements that the above objects are made of. % The user is queried for each via the ask/1 predicate. % fuzzy :- ask('Does the object have a fuzzy appearance'). moves :- ask('Does the object appear to move against the stars'). point :- ask('Is the object a single point of light'). individual_stars :- ask('Can you resolve individual stars in the object'). large :- ask('Is the object larger than 2 degrees across'). bright :- ask('Is the object brighter than magnitude -8'). crescent :- ask('Does the object ever appear as a crescent'). spiral :- ask('Does the object have a spiral appearance'). bar :- ask('Does the object have a bar across its center'). elliptical :- ask('Does the object have an elliptical shape'). yellow :- ask('Is the object yellow'). white :- ask('Is the object white'). red :- ask('Is the object red'). black :- ask('Is the object black'). disk :- ask('Does the object appear as a disk'). many_stars :- ask('Does the object consist of more than 40 stars'). glowing :- ask('Is the object glowing'). ring :- ask('Is the object ring-shaped'). % % asked/1: true for a question if is has already been asked. (Don't % want to query the user twice for the same thing.) % asked('Does the object have a fuzzy appearance') :- fail. asked('Does the object appear to move against the stars') :- fail. asked('Is the object a single point of light') :- fail. asked('Can you resolve individual stars in the object') :- fail. asked('Is the object larger than 2 degrees across') :- fail. asked('Is the object brighter than magnitude -8') :- fail. asked('Does the object ever appear as a crescent') :- fail. asked('Does the object have a spiral appearance') :- fail. asked('Does the object have a bar across its center') :- fail. asked('Does the object have an elliptical shape') :- fail. asked('Is the object yellow') :- fail. asked('Is the object white') :- fail. asked('Is the object red') :- fail. asked('Is the object black') :- fail. asked('Does the object appear as a disk') :- fail. asked('Does the object consist of more than 40 stars') :- fail. asked('Is the object glowing') :- fail. % % ask/1: asks the user (if haven't asked already) one of the questions. % ask(Q) :- not(asked(Q)), assert(asked(Q)), write(Q), write('? '), read(yes), asserta(ask(Q)). % % yes and no--easier for the user to write than "true" and "fail". % yes :- true. no :- fail.