home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / prolog / pdprolog / robot.pro < prev    next >
Text File  |  1986-05-05  |  3KB  |  76 lines

  1. /*    John M. Linebarger
  2.       25 October 1985
  3.  
  4.       Thi≤ prograφ act≤ a≤ ß robo⌠ tha⌠ will¼ wheε giveε ß to≡ 
  5. ááááááleve∞ predicatσ oµ 'place(X,Y).'¼ placσ blocδ ß oε to≡ oµ 
  6. ááááááblocδ Γ iε thσ block≤ world« Thσ strateg∙ i≤ a≤ follows:
  7.  
  8.       1« Takσ everythinτ ofµ oµ thσ receivinτ blocδ anΣ 
  9. áááááá  áplacσ i⌠ oε thσ table.
  10. áááááá      
  11. áááá  2« Takσ everythinτ ofµ oµ thσ sendinτ blocδ anΣ placσ 
  12. áááááá áái⌠ oε thσ table.
  13.  
  14.       3« Place sendinτ blocδ ont∩ receivinτ block.
  15.  
  16.       ┴ majo≥ assumptioε here¼ oµ course¼ i≤ tha⌠ therσ i≤ 
  17. ááááááunlimiteΣ room oε thσ table.
  18.  
  19.       ┴ featurσ oµ thi≤ prograφ i≤ thσ front-enΣ editinτ oµ 
  20. ááááááthσ top-level placσ predicate.
  21.  
  22. */
  23.   
  24. on( [], a ). 
  25. on( a, b ).
  26. on( b, c ).
  27. on( c, d ).
  28. on( d, table ).
  29. on( [], e ).
  30. on( e, f ).
  31. on( f, g ).
  32. on( g, table ).
  33.    
  34. place( table, _ ) :- print( 'Table cannot be moved.' ), nl.
  35. place( A, A ) :- print( 'Cannot place block on top of itself.' ), nl.
  36. place(A,_) :- (not(on(A,_)); not(on(_,A))), print( 'Block ' ),
  37.  ááááá        print(A), print( ' does not exist.' ), nl.
  38. place(A,B) :- on(A,B), print(A), print( ' is already on ' ), 
  39.               print(B), print( '.' ), nl.
  40. place(A,table) :- on(A,B), clear_top(B).
  41. place(_,B) :- (not(on(B,_)); not(on(_,B))), print( 'Block ' ),
  42.  ááááá        print(B), print( ' does not exist.' ), nl.
  43. place( A, B ) :- clear_top( B ), clear_top( A ), on( A, C ),
  44.  ááááá           below( A, C ),
  45.                  retract( on( [], B ) ), asserta( on( A, B ) ),
  46.                  print( 'Put ' ), print( A ), print( ' on ' ), 
  47. áááááá           print( B ), print( '.' ), nl.
  48.   
  49. clear_top( X ) :- on( Y, X ), (on( [], X ); (remove( Y, X ), 
  50. áááááá            clear_top( X ) ) ).
  51.  
  52. remove( [], X ) :- on( X, Y ), move( X, Y ).
  53. remove( Y, X )  :- on( Z, Y ), remove( Z, Y ).
  54. èbelow( A, table ) :- retract( on( A, table ) ).
  55. below( A, C )     :- retract( on( A, C ) ), asserta( on ( [], C ) ).
  56.  
  57. move( X, table ).
  58. move( X, Y ) :- retract( on( X, Y ) ), asserta( on( X, table ) ), 
  59.                     asserta( on( [], Y ) ), print( 'Put ' ), 
  60. áááááá              print( X ), print( ' on table.' ), nl.
  61.  
  62. show :- on (X, Y ), print ( X ), print ( ' is currently on ' ), 
  63.         print ( Y ), print ( '.' ), nl, fail.  
  64. show.
  65.  
  66. help :- print( 'This program acts like a robot in the blocks world' ),nl, 
  67.         print( 'that will place one block on top of another with a' ),nl,
  68.         write( 'place(X,Y)' ), print( ' predicate. To see the current '),
  69.         nl, print( 'block configuration, type '), print( '\'show\'' ),
  70.         print( '.' ),nl, nl, 
  71.         print('Written by John M. Linebarger as part of a course in'),nl,
  72.         print( 'Artificial Intelligence in the MBA program of New York'), 
  73.         nl, print( 'University. The author\'s address is:'),
  74.         nl, print( '360 Davidson Street, Apt. 6, Bridgeport, CT 06605.'),
  75.         nl, print( 'Home phone is 203/333-5779.' ).
  76.