Error message- expects a number as 1st argument, given 'hearts
I have to make a code without using equal? in solution my code looks like this
(define-struct card (suit value))
(define (card=? str-1 str-2)
(cond
[(and (= (card-suit str-1) (card-suit str-2))
(= (card-value str-1) (card-value str-2))) true]
[else false]))
(check-expect (card=? (make-card 'hearts 3) (make-card 'hearts 3)) true)
Edit - the question goes like this for further info
In the card game “crazy eights” players take turns playing a card in the center, with the goal of being the first player without any cards in their hand. Players must play a card that matches the suit of the center card, with two exceptions. First, a player may instead play a card that matches the value of the center card. Second, eights are “wild”, so a player may always play an eight. When a player plays an eight, they say the name of a suit. The eight is treated as having this suit, even if it does not. For example, if a player plays the eight of spades, and says “hearts”, then the next card played must be a “hearts” card (or another eight). Instead of playing a card, the player may draw a card. If they can play the new card they may do so, otherwise this is the end of their turn. When a player runs out of cards, they have won the hand. The winning player receives points based on what cards the other players are holding.
For this question we will represent cards using the Card type:
(define-struct card (suit value))
;; A Card is a (make-card Sym Nat)
;; requires: suit is one of ’hearts, ’diamonds, ’clubs, or ’spades
;; value between 1 and 13, using 11 for Jack, 12 for Queen, and 13 for King.
Note: We are representing these cards with a computer, so it is easy enough to actually change the eight of spades into an eight of hearts when it is played! For that reason, in the following functions you may assume that the current suit is equal to the suit of the current card in the center, even if the center card is an eight.
A)
Write a function card=?
which consumes two Card structures and produces true if
they represent the same playing card, and false otherwise. You must not use equal?
in your solution. For example, (card=? (make-card ’hearts 3) (make-card ’hearts 3))
produces true
b)
Write a function crazy-count
which consumes a list of Card structures and the current
center Card, and produces the number of Card structures in the list that can legally be
played in the center.