This is a very minor piece of code,
really. But I’m not seeing the "right"
way to do it.
If you’re bored by cards in general
(as in card games), you can stop reading
here.
I spent last night working on a little
program to play Spades (the card game).
It’s amazing how much actually works
after just a couple of hours and 158
lines of code, by the way. That’s Ruby.
I’m trying to write a little "winner"
method to determine which player (which
we can represent by an index 0-3) wins
the trick.
I’ve implemented this for now as a class
method taking a parameter which is an
array of four cards. Each card is an object
with accessors ‘suit’ and ‘rank’.
According to the rules of the game, the
suit that is led first must be followed.
The winner method isn’t/shouldn’t be
responsible for detecting breaches of the
rule; but it affects the “value” of all
the subsequent cards (e.g., if a two of
hearts led, it beats a king of clubs
following). On the other hand, the spade
suit is a trump which will beat anything.
So how would you do this?
Hal