""" Pairs in the Middle, Suits on the Ends solitaire
Shuffle the entire deck and deal out four cards face up.
Remove cards as follows: If you have a pair in the middle of the four cards, you may remove them.
If the first card and the fourth card are the same suit, you remove the two middle cards.
If all four cards are the same suit, remove all four cards.
Add another card to the right end of your row.
If it is the same suit as the fourth card to the left, remove the two middle cards.
If you paired up in the middle, you can remove the two middle cards.
And if all four cards are in the same suit, remove all four cards.
Continue adding cards as in Step 3, looking for both of the following:
cards with matching suits with two cards between them and pairs in the middle of four cards.
Remember to also look for four cards in a row of the same suit.
Win the game if you are left with no cards.
from __future__ import print_function
from collections import namedtuple
input = raw_input
def can_take_out(pos, cards):
if pos < 3:
return 4 if (cards[pos-2].suit == cards[pos-1].suit == cards[pos].suit) else 2
def print_cards(pos, cards):
""" Concise printing format for cards """
print("Card %i. Current cards:" % (pos+1),
','.join(card.suit+('%02i' % card.value ) for card in reversed(cards)))
if __name__ == '__main__':
Card = namedtuple('Card', 'value suit')
game = 0
cards = [Card(value,suit)
for value in range(2,15)
for suit in 'DHSC']
pos, took = -1, True
game += 1
# winning test with two of same value left in end
##cards = [
if pos < 3:
if not took:
print("\nNot possible to take out anything")
pos = len(cards) - 1
took = False
out = can_take_out(pos, cards)
print(("Can take out %s" % out).center(20,'*'))
if out == 4:
took = True
pos -= out
pos -= 1
#if out: input()
if (len(cards) == 2 and ((cards.suit == cards.suit) or
(cards.value == cards.value))):
print('Can take out last cards because they are same suit or value.')
cards = 
q = input('\nYou lost game %i, with %i cards left!' % (game,len(cards)))
if q.lower() =='q':
print('\nYou won on game %i.' % game)