示例#1
0
 def playCardUser(self, sofar, card):
     if (len(sofar) == 0):
         #test if the player has the two of clubs:
         if (self.count(0) == 1):
             if (card == 0):
                 return [True, '']
             else:
                 return [
                     False,
                     'You must play the two of clubs on the first round.'
                 ]
         else:
             self.hand.remove(card)
             return [True, '']
     else:
         leadingCard = sofar[0]
         lb = (leadingCard / 13) * 13
         ub = lb + 12
         valids = []
         for i in range(len(hands)):
             if (hands[i] >= lb and hands[i] <= ub):
                 valids.append(hands[i])
         if (len(valids) == 0):  #if they have no cards of the leading suit
             self.hand.remove(card)
             return [True, '']
         else:
             if (valids.count(card) == 1
                 ):  #if they have a card of the leading suit
                 return [True, '']
             else:
                 return [
                     False, 'You must play a card of suit:' +
                     CardClass.suit(leadingCard)
                 ]
示例#2
0
	def playCardUser(self, sofar, card):
		if(len(sofar) == 0):
			#test if the player has the two of clubs:
			if(self.count(0) == 1): 
				if(card == 0):
					return [True, ''];
				else:
					return [False, 'You must play the two of clubs on the first round.']
			else:
				self.hand.remove(card);
				return [True, ''];
		else:
			leadingCard = sofar[0];
			lb = (leadingCard/13)*13;
			ub = lb + 12;
			valids = [];
			for i in range(len(hands)):
				if(hands[i] >= lb and hands[i] <= ub):
					valids.append(hands[i]);
			if(len(valids) == 0): #if they have no cards of the leading suit
				self.hand.remove(card);
				return [True,''];
			else:
				if(valids.count(card) == 1): #if they have a card of the leading suit
					return [True, ''];
				else:
					return [False, 'You must play a card of suit:' + CardClass.suit(leadingCard)]
示例#3
0
        if (i == 0):
            for k in range(4):
                if Players[k].hasTwoOfClubs:
                    turn = k
                    break

        #check what has been played so far
        sofar = []
        point_total = 0
        #each person plays a card (and loops through turn)
        for m in range(4):
            #print str(turn) +" " + str(Players[turn].hand)
            card = Players[turn].playCardAuto(sofar)
            sofar.append(card)
            turn = (turn + 1) % 4
            point_total += CardClass.pointValue(card)
        turn = CardClass.winner(sofar)  #indicate who wins the trick
        score[turn] += point_total
        '''
		print sofar
		
		print "hand %d" % (i+1)
		for r in range(4):
			print "player %d: %d" % (r+1, score[r])
		'''

    #Someone shot the moon!
    if score.count(26) == 1:
        for k in range(4):
            score[k] = 26 - score[k]
示例#4
0
# -*- coding: utf-8 -*-
import CardClass
import CreateTables
import readFile

# Read in the json file
json = readFile.openJsonFile('AllCards-x.json')

# This line will create the initial tables from the various card properties
CreateTables.createTablesFromProperties(json)

card = CardClass.createCard(json)
card.importProperties()
示例#5
0
		if (i == 0):
			for k in range(4):
				if Players[k].hasTwoOfClubs:
					turn = k
					break
		
		#check what has been played so far
		sofar = []
		point_total = 0
		#each person plays a card (and loops through turn)
		for m in range(4):
			# print str(turn) +" " + str(Players[turn].hand)
			card = Players[turn].playCardAuto(sofar)
			sofar.append(card)
			turn = (turn+1) % 4
			point_total += CardClass.pointValue(card)
		turn = CardClass.winner(sofar) #indicate who wins the trick
		score[turn] += point_total
		
		'''
		print sofar
		
		print "hand %d" % (i+1)
		for r in range(4):
			print "player %d: %d" % (r+1, score[r])
		'''
		
	#Someone shot the moon!
	if score.count(26) == 1:
		for k in range(4):
			score[k] = 26 - score[k]
示例#6
0
	def __init__(self):
		self.the_deck = []
		for i in CardClass.suits:
			for j in  CardClass.ranks:
				self.the_deck.append(CardClass.Card(i,j))
示例#7
0
#--------------------------------------------------------    Class   ---------------------------------------------------------------
class Deck():
	def __init__(self):
		self.the_deck = []
		for i in CardClass.suits:
			for j in  CardClass.ranks:
				self.the_deck.append(CardClass.Card(i,j))
	def shuffle(self):
		random.shuffle(self.the_deck)
		#k = random.sample(self.the_deck,len(self.the_deck))
		#return k

	def __str__(self):
		return self.the_deck

	def pick_one(self):
		return self.the_deck.pop()
#****************************************************************************************************************************************
#------------------------------------------------------- Test - Statements --------------------------------------------------------------
if __name__ == '__main__':
	A = CardClass.Card(CardClass.suits[0],CardClass.ranks[0])
	print(A)
	new_deck = Deck()
	new_deck.shuffle()
	print(new_deck.the_deck[36])
	print(len(new_deck.the_deck))
	z = new_deck.pick_one()
	print(z)
	print(len(new_deck.the_deck))
#****************************************************************************************************************************************