Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define-struct card (suit rank))
- ;; bestsuit: card card - > string
- ;;Helping function that distinguishes the better suit of two cards
- (define (bestsuit a b)
- (if (equal? (card-suit a) 'spades)
- 'spades
- (if (or (equal? (card-suit a) 'hearts) (equal? (card-suit b) 'hearts))
- 'hearts
- (if (or (equal? (card-suit a) 'diamonds)(equal? (card-suit b) 'diamonds))
- 'diamonds
- 'clubs))))
- ;;bestrank nat nat - > nat
- ;;Helping function that distinguises the highest rank of two cards.
- (define (bestrank a b)
- (cond
- [(< (card-rank a) (card-rank b)) (card-rank b)]
- [(> (card-rank a) (card-rank b)) (card-rank a)]
- [(equal? (card-rank a) (card-rank b)) (card-rank a)]))
- ;;better-card card card - > card
- ;;This function will intake two cards and then produce
- ;;the card with the highest suit. If both suits are equal,
- ;;the function will produce the card with highest rank.
- (define (better-card a b)
- (if (equal? (card-suit a)(card-suit b))
- (make-card (card-suit a) (bestrank a b))
- (if (equal? (bestsuit a b) a)
- (make-card (card-suit a)(card-rank a))
- (make-card (card-suit b)(card-rank b)))))
- ;;straight: card card card - > bool
- ;;Helping function which will consume three card and, if they are of the same suit,
- ;;will produce either true if each card has a distance of one from another, or
- ;;false if this is not the case.
- (define (straight a b c)
- (if (equal? (card-suit a)(card-suit b)(card-suit c))
- (if (and (or
- (equal? (- (bestrank (bestrank a b) c) 1)(card-rank a))
- (equal? (- (bestrank (bestrank a b) c) 1)(card-rank b))
- (equal? (- (bestrank (bestrank a b) c) 1)(card-rank c)))
- (equal? (- (bestrank (bestrank a b) c) 2)(card-rank a))
- (equal? (- (bestrank (bestrank a b) c) 2)(card-rank b))
- (equal? (- (bestrank (bestrank a b) c) 2)(card-rank c)))
- true
- false)
- false))
- ;;hand-value: card card card - > string
- ;;This function will consume three cards and produce
- ;;a string corresponding to the rules at the beginning
- ;;of this assigment.
- (define (hand-value a b c)
- (if (equal? (card-suit a)(card-suit b)(card-suit c))
- (if (straight a b c)
- 'straightflush
- 'flush)
- (if (straight a b c)
- 'straight
- (if (and (equal? (card-rank a)(card-rank b))
- (equal? (card-rank b)(card-rank c)))
- 'three-of-a-kind
- (if (or (equal? (card-rank a)(card-rank b))
- (equal? (card-rank b)(card-rank c))
- (equal? (card-rank c)(card-rank a)))
- 'pair
- 'high-card)))))
Add Comment
Please, Sign In to add comment