Skip to content

Instantly share code, notes, and snippets.

@jsomers
Created April 25, 2010 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsomers/378255 to your computer and use it in GitHub Desktop.
Save jsomers/378255 to your computer and use it in GitHub Desktop.
Functions for dealing and scoring games of Mindy Coat
# The Rules of Mindy Coat
# =======================
# => Four players, opposite sides are in teams.
# => Deal 5 cards each, one-by-one starting left of the dealer.
# => Left of the dealer calls trump looking at those 5.
# => Dealer deals the last 8 cards out (starts on the left).
# => Highest card of the trick wins, unless a trump is thrown, in which case the highest trump wins.
# => Team that takes the most tens wins, unless each takes two, in which case the total number of tricks is counted.
# => (Must follow suit unless you don't have it.)
# Live multiplayer version TODOs:
# ===============================
# => Drawing arbitrary cards (in Javascript).
# => Juggernaut.
# => Showing the score, your hand, the current trick, etc. Making cards clickable. (Re-arrangeable?). Seat map. Room.
# => Events: deal. choose trump. player chooses cards. assign trick to team. choose player turn. who wins game? next deal.
class String
def suit
self.split("")[-1]
end
end
def shuffle
suits = ["h", "d", "s", "c"]
ranks = (2..10).collect {|n| n.to_s} + ["J", "Q", "K", "A"]
deck = ranks.collect {|r| ([r] * 4).zip(suits).collect {|pr| pr.join}}.flatten
return deck.sort { rand }
end
def to_n(card)
vals = {"J" => 11, "Q" => 12, "K" => 13, "A" => 14}
if (c = card.split("")[0]).to_i == 0
vals[c]
else
c.to_i == 1 ? 10 : c.to_i
end
end
def rank(cards)
cards.sort {|a, b| to_n(a) <=> to_n(b)}
end
def winner(trick, trump)
lead_suit = trick.first.suit
trumps = trick.select {|c| c.include? trump}
live = trick.select {|c| c.include? lead_suit}
if !trumps.empty?
trick.index(rank(trumps).last)
else
trick.index(rank(live).last)
end
end
def valid?(card, trick_stub, hand)
lead_suit = trick_stub.first.suit
has_lead_suit = hand.collect {|c| c.suit}.uniq.include? lead_suit
!has_lead_suit or card.suit == lead_suit
end
def deal_first_five
deck = shuffle
[deck[0..4], deck[5..9], deck[10..14], deck[15..19], deck[20..-1]]
end
def deal_the_rest(hands, deck)
(0..3).collect {|n| hands[n] + deck[n + 8 * n..8 * n + n + 7]}
end
def deal
deck = deal_first_five
p deck[0]
puts "Player, choose trump."
trump = gets
deal_the_rest(deck[0..3], deck[4]) + [trump.strip]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment