SHARE
TWEET

Untitled

a guest Dec 27th, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ORACLE: Simple magic 8-ball program
  2. ; Requires Aubrey Jaffer's SLIB
  3. (require 'random)
  4.  
  5. ; Basic decision roller for the Oracle
  6. (define (oracle-roll)
  7.   (exact->inexact (/ (random 100) 10)))
  8.  
  9. ; Advanced contemplator for the Oracle
  10. (define (oracle-think i j w)
  11.   (begin
  12.     (cond
  13.       ((< j 1) (oracle-process w))
  14.       (else (let ((op (random 4)))
  15.               (cond
  16.                 ((= op 0) (oracle-think i (- j 1) (/ w (oracle-roll))))
  17.                 ((= op 1) (oracle-think i (- j 1) (* w (oracle-roll))))
  18.                 ((= op 2) (oracle-think i (- j 1) (- w (oracle-roll))))
  19.                 ((= op 3) (oracle-think i (- j 1) (+ w (oracle-roll))))))))))
  20.  
  21. ; Decimal shifter for processing the end result of a contemplation cycle
  22. (define (oracle-process n)
  23.   (begin
  24.     (cond
  25.       ((< n 0) (oracle-process (abs n)))
  26.       ((< n 10) n)
  27.       (else (oracle-process (exact->inexact (/ n 10)))))))
  28.  
  29. ; Decision processor for the Oracle
  30. (define (oracle-decide r)
  31.   (begin
  32.     (cond
  33.       ((< r 1)   (display "NOT A CHANCE"))
  34.       ((< r 2)   (display "NOT AT ALL LIKELY"))
  35.       ((< r 3)   (display "NO"))
  36.       ((< r 4.5) (display "OUTLOOK NOT GOOD"))
  37.       ((< r 5.5) (display "CANNOT REACH A DECISION"))
  38.       ((< r 7)   (display "OUTLOOK GOOD"))
  39.       ((< r 8)   (display "YES"))
  40.       ((< r 9)   (display "ABSOLUTELY"))
  41.       ((< r 10)  (display "YOU MAY RELY ON IT")))
  42.     (newline)
  43.     r))
  44.  
  45. ; Receive a random answer from the Oracle
  46. (define (oracle)
  47.   (oracle-decide (oracle-roll)))
  48.  
  49. ; Ask the Oracle a single question
  50. (define (ask-oracle question)
  51.   (begin
  52.     (display "Q: ") (display question) (newline)
  53.     (display "A: ") (oracle)))
  54.  
  55. ; Ask the Oracle to contemplate a question
  56. (define (oracle-contemplate question)
  57.     (let ((i (random 15)))
  58.       (begin
  59.         (display "Q: ") (display question) (newline)
  60.         (display "PROCESSING...") (newline)
  61.         (display "A: ") (oracle-decide (oracle-think i i (oracle-roll))))))
  62.  
  63. ; Initiate a dialog with the Oracle
  64. (define (oracle-dialog)
  65.   (begin
  66.     (display "Pose a question to the Oracle... ")
  67.     (let ((q (read-line)))
  68.       (cond
  69.         ; ::::: Dialog exit checks :::::
  70.         ((or
  71.            (string-ci=? q "bye")
  72.            (string-ci=? q "goodbye")
  73.            (string-ci=? q "exit")
  74.            (string-ci=? q "quit")) (display "A: GOODBYE"))
  75.         ; ::::: Question processing :::::
  76.         (else (begin
  77.                 (cond
  78.                   ; ::::: For getting quick answers :::::
  79.                   ((or
  80.                      (string-ci=? q "q")
  81.                      (string-ci=? q "quick")
  82.                      (string-ci=? q "quickly")
  83.                      (string-ci=? q "fast")) (begin
  84.                                                (display "A: ")
  85.                                                (let ((answer (oracle)))
  86.                                                  (display "<")
  87.                                                  (display answer)
  88.                                                  (display ">")
  89.                                                  (newline))))
  90.                   ; ::::: Standard dialog processing, contemplates more deeply :::::
  91.                   (else (begin
  92.                           (let ((answer (oracle-contemplate q)))
  93.                             (display "<")
  94.                             (display answer)
  95.                             (display ">")
  96.                             (newline)))))
  97.                 (oracle-dialog)))))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top