Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ORACLE: Simple magic 8-ball program
- ; Requires Aubrey Jaffer's SLIB
- (require 'random)
- ; Basic decision roller for the Oracle
- (define (oracle-roll)
- (exact->inexact (/ (random 100) 10)))
- ; Advanced contemplator for the Oracle
- (define (oracle-think i j w)
- (begin
- (cond
- ((< j 1) (oracle-process w))
- (else (let ((op (random 4)))
- (cond
- ((= op 0) (oracle-think i (- j 1) (/ w (oracle-roll))))
- ((= op 1) (oracle-think i (- j 1) (* w (oracle-roll))))
- ((= op 2) (oracle-think i (- j 1) (- w (oracle-roll))))
- ((= op 3) (oracle-think i (- j 1) (+ w (oracle-roll))))))))))
- ; Decimal shifter for processing the end result of a contemplation cycle
- (define (oracle-process n)
- (begin
- (cond
- ((< n 0) (oracle-process (abs n)))
- ((< n 10) n)
- (else (oracle-process (exact->inexact (/ n 10)))))))
- ; Decision processor for the Oracle
- (define (oracle-decide r)
- (begin
- (cond
- ((< r 1) (display "NOT A CHANCE"))
- ((< r 2) (display "NOT AT ALL LIKELY"))
- ((< r 3) (display "NO"))
- ((< r 4.5) (display "OUTLOOK NOT GOOD"))
- ((< r 5.5) (display "CANNOT REACH A DECISION"))
- ((< r 7) (display "OUTLOOK GOOD"))
- ((< r 8) (display "YES"))
- ((< r 9) (display "ABSOLUTELY"))
- ((< r 10) (display "YOU MAY RELY ON IT")))
- (newline)
- r))
- ; Receive a random answer from the Oracle
- (define (oracle)
- (oracle-decide (oracle-roll)))
- ; Ask the Oracle a single question
- (define (ask-oracle question)
- (begin
- (display "Q: ") (display question) (newline)
- (display "A: ") (oracle)))
- ; Ask the Oracle to contemplate a question
- (define (oracle-contemplate question)
- (let ((i (random 15)))
- (begin
- (display "Q: ") (display question) (newline)
- (display "PROCESSING...") (newline)
- (display "A: ") (oracle-decide (oracle-think i i (oracle-roll))))))
- ; Initiate a dialog with the Oracle
- (define (oracle-dialog)
- (begin
- (display "Pose a question to the Oracle... ")
- (let ((q (read-line)))
- (cond
- ; ::::: Dialog exit checks :::::
- ((or
- (string-ci=? q "bye")
- (string-ci=? q "goodbye")
- (string-ci=? q "exit")
- (string-ci=? q "quit")) (display "A: GOODBYE"))
- ; ::::: Question processing :::::
- (else (begin
- (cond
- ; ::::: For getting quick answers :::::
- ((or
- (string-ci=? q "q")
- (string-ci=? q "quick")
- (string-ci=? q "quickly")
- (string-ci=? q "fast")) (begin
- (display "A: ")
- (let ((answer (oracle)))
- (display "<")
- (display answer)
- (display ">")
- (newline))))
- ; ::::: Standard dialog processing, contemplates more deeply :::::
- (else (begin
- (let ((answer (oracle-contemplate q)))
- (display "<")
- (display answer)
- (display ">")
- (newline)))))
- (oracle-dialog)))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement