a guest Dec 14th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;by victor vasilevskiy
  2. (define ranks '(a k q j 10 9 8 7 6 5 4 3 2))
  3. (define suits '(s h d c))
  5. (define (numeric-rank rank)
  6.    (cond ((equal? rank 'a) 14)
  7.          ((equal? rank 'k) 13)
  8.          ((equal? rank 'q) 12)
  9.          ((equal? rank 'j) 11)
  10.          (else rank)))
  12. (define (make-card suit rank)
  13.    (word suit rank))
  14. (define (rank card) (bf card))
  15. (define (suit card) (first card))
  17. (define (sort hand)
  18.    ((repeated sort-once (- (count hand) 1)) hand))
  20. (define (sort-once hand)
  21.    (cond ((empty? hand) hand)
  22.          ((= (count hand) 1) hand)
  23.          ((> (numeric-rank (bf (first hand)))
  24.              (numeric-rank (bf (first (bf hand)))))
  25.                  (se (first hand) (sort-once (bf hand))))
  26.          (else (se (first (bf hand))
  27.                    (sort-once (se (first hand) (bf (bf hand))))))))
  29. (define (poker-value hand)
  30.   (let ((sortedhand (sort hand)))
  31.     (cond ((royal-flush? sortedhand) (se '(ROYAL FLUSH) '- (suitname hand)))
  32.           ((straight-flush? sortedhand) (se '(STRAIGHT FLUSH) '- (rank (first (sort hand))) 'HIGH (suitname hand)))
  33.           ((four-of-a-kind? sortedhand) (se '(FOUR OF A KIND) '- (numword (rank (first (bf (bf (sort hand))))))))
  34.           ((full-house? sortedhand) (se '(FULL HOUSE) '- (numword (rank (last (sort hand)))) 'OVER (numword (rank (first (sort hand))))))
  35.           ((flush? sortedhand) (se 'FLUSH '- (suitname hand)))
  36.           ((straight? sortedhand) (se (word (numword (rank (first (sort hand)))) '-HIGH) 'STRAIGHT))
  37.           ((three-of-a-kind? sortedhand) (se '(THREE OF A KIND) '- (numword (rank (first (bf (bf (sort hand))))))))
  38.           ((two-pair? sortedhand) (se '(TWO PAIRS OF) (numword (rank (first (bf (sort hand))))) 'AND (numword (rank (last (bl (sort hand)))))))
  39.           ((pair? sortedhand) (se '(There is a pair. I am sorry Ms. Hexsel but I have had no idea how to do this part of poker-value for pair. I tried doing a ton of
  40.                                           different things but in the end nothing has worked)))
  41.           (else '(none)))))
  43. ;my code starts here bruh
  45. (define (numword val) ;transforms numbers to words
  46.   (cond ((equal? val 14) 'ACES)
  47.         ((equal? val 13) 'KINGS)
  48.         ((equal? val 12) 'QUEENS)
  49.         ((equal? val 11) 'JACKS)
  50.         ((equal? val 10) 'TENS)
  51.         ((equal? val 9) 'NINES)
  52.         ((equal? val 8) 'EIGHTS)
  53.         ((equal? val 7) 'SEVENS)
  54.         ((equal? val 6) 'SIXES)
  55.         ((equal? val 5) 'FIVES)
  56.         ((equal? val 4) 'FOURS)
  57.         ((equal? val 3) 'THREES)
  58.         ((equal? val 2) 'TWOS)
  59.         ((equal? val 1) 'ONES)
  60.         (else '(I have an intense hatred for joe))))
  62. (define (suitname hand) ;transforms the suit to a word
  63.   (cond ((equal? (suit (first (sort hand))) 'd) 'DIAMONDS)
  64.         ((equal? (suit (first (sort hand))) 'c) 'CLUBS)
  65.         ((equal? (suit (first (sort hand))) 'h) 'HEARTS)
  66.         ((equal? (suit (first (sort hand))) 's) 'SPADES)
  67.         (else '(JOHN F KENNEDY))))
  70. (define (pair? hand) ;this checks for a pair
  71.   (cond ((<= (count (sort hand)) 1) #f)
  72.         ((not (equal? (bf (first (sort hand))) (bf (first (bf (sort hand)))))) (pair? (bf (sort hand))))
  73.         ((equal? (bf (first (sort hand))) (bf (first (bf (sort hand))))) #t)
  74.         (else #f)))
  77. (define (helper1 hand) ;helper for two pair where you need a sentence of 2 sortpairs but not the same so it can run it on both in 1
  78.   (se (first (sort hand)) (first (bf (sort hand)))))
  80. (define (two-pair? hand) ;checks if there are 2 pairs
  81.   (cond ((<= (count (sort hand)) 1) #f)
  82.         ((pair? (helper1 (sort hand))) (pair? (bf (bf (sort hand)))))
  83.         (else (two-pair? (bf (sort hand))))))
  85. (define (three-of-a-kind? hand) ;checks if there are 3 numbers that are the same
  86.   (cond ((<= (count (sort hand)) 1) #f)
  87.         ((and (equal? (numeric-rank (bf (first (sort hand)))) (numeric-rank (bf (first (bf (sort hand))))))
  88.               (equal? (numeric-rank (bf (first (sort hand)))) (numeric-rank (bf (first (bf (bf (sort hand)))))))) #t)
  90.         ((and (equal? (numeric-rank (bf (first (bf (sort hand))))) (numeric-rank (bf (first (bf (bf (sort hand)))))))
  91.               (equal? (numeric-rank (bf (first (bf (sort hand))))) (numeric-rank (bf (first (bf (bf (bf (sort hand))))))))) #t)
  93.         ((and (equal? (numeric-rank (bf (first (bf (bf (sort hand)))))) (numeric-rank (bf (first (bf (bf (bf (sort hand))))))))
  94.               (equal? (numeric-rank (bf (first (bf (bf (sort hand)))))) (numeric-rank (bf (first (bf (bf (bf (bf (sort hand)))))))))) #t)
  95.         (else #f)))
  97. (define (straight? hand) ;adds 1 to the rank of the next rank from the first so if it adds 1 its equal. if all 5 are +1 from each other it returns true
  98.   (cond  ((and (equal? (numeric-rank (bf (first (sort hand)))) (+ 1 (numeric-rank (bf (first (bf (sort hand)))))))
  99.                (equal? (numeric-rank (bf (first (bf (sort hand))))) (+ 1 (numeric-rank (bf (first (bf (bf (sort hand))))))))
  100.                (equal? (numeric-rank (bf (first (bf (bf (sort hand)))))) (+ 1 (numeric-rank (bf (first (bf (bf (bf (sort hand)))))))))
  101.                (equal? (numeric-rank (bf (first (bf (bf (bf (sort hand))))))) (+ 1 (numeric-rank (bf (first (bf (bf (bf (bf (sort hand))))))))))) #t)
  102.         (else #F)))
  104. (define (flush? hand) ;removes the numbers keeps only the suit, only 5 cards in a poker hand, if it continues until 1 then it is true
  105.   (cond ((equal? (count (sort hand)) 1) #t)
  106.         ((equal? (suit (first (sort hand))) (suit (first (bf (sort hand))))) (flush? (bf (sort hand))))
  107.         (else #f)))
  109. (define (fhhelper num hand)
  110.   (cond ((< (count hand) 2) #t)
  111.         ((< num 2) #t)
  112.         ((equal? (numeric-rank (bf (first hand))) (numeric-rank (bf (first (bf hand))))) (fhhelper (- num 1) (bf hand)))
  113.         (else #f)))
  115. (define (full-house? hand)
  116.   (or (and (fhhelper 3 hand) (fhhelper 2 (bf (bf (bf hand)))))
  117.            (and (fhhelper 2 hand) (fhhelper 3 (bf (bf hand))))))
  119. (define (four-of-a-kind? hand) ;checks if there are 3 numbers that are the same
  120.   (cond ((<= (count (sort hand)) 1) #f)
  121.         ((and (equal? (numeric-rank (bf (first (sort hand)))) (numeric-rank (bf (first (bf (sort hand))))))
  122.               (equal? (numeric-rank (bf (first (sort hand)))) (numeric-rank (bf (first (bf (bf (sort hand)))))))
  123.               (equal? (numeric-rank (bf (first (sort hand)))) (numeric-rank (bf (first (bf (bf (bf (sort hand))))))))) #t)
  124.         ((and (equal? (numeric-rank (bf (first (bf (sort hand))))) (numeric-rank (bf (first (bf (bf (sort hand)))))))
  125.               (equal? (numeric-rank (bf (first (bf (sort hand))))) (numeric-rank (bf (first (bf (bf (bf (sort hand))))))))
  126.               (equal? (numeric-rank (bf (first (bf (sort hand))))) (numeric-rank (bf (first (bf (bf (bf (bf (sort hand)))))))))) #t)
  127.         (else #f)))
  129. (define (straight-flush? hand) ;checks for straight flush
  130.   (cond ((empty? hand) #f)
  131.         ((not (flush? hand)) #f)
  132.         ((straight? (sort hand)) #t)
  133.         (else #f)))
  135. (define (royal-flush? hand) ;checks if its a ROYAL FLUSH
  136.   (cond ((empty? hand) #f)
  137.         ((not (flush? hand)) #f)
  138.         ((and (equal? (numeric-rank (bf (first (sort hand)))) 14)
  139.               (equal? (numeric-rank (bf (first (bf (sort hand))))) 13)
  140.               (equal? (numeric-rank (bf (first (bf (bf (sort hand)))))) 12)
  141.               (equal? (numeric-rank (bf (first (bf (bf (bf (sort hand))))))) 11)
  142.               (equal? (bf (first (bf (bf (bf (bf (sort hand))))))) 10)) #t)
  143.         (else #f)))
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!