__metaclass__ = type import texas, random class player: def __init__(self): self.card = [] self.final = [] self.kind = 10 def getcard(self, card, pub): self.card = card self.final = pub self.kind = texas.judgecards(self.final) # pub is the lowest possible solution def getstyle(self, pub): total = self.card + pub # check all the possible solution and find the best one for i in range(7): test_1 = total[:] test_1.pop(i) for j in range(i, 6): test_2 = test_1[:] test_2.pop(j) b = texas.judgecards(test_2) # consider kind first, then for the same kind if b < self.kind : self.final = test_2[:] self.kind = b elif b == self.kind: c = texas.sortcards(self.final, test_2, self.kind) if c == '2': self.final = test_2[:] self.kind = b class card: def __init__(self): value = range(2, 15) suits = 'heart spade club diamond'.split() card.card = [(a, b) for a in value for b in suits] def getcard(self): random.shuffle(card.card) def point(self, Cards): for a in Cards: n = card.card.index(a) card.card.pop(n) N = 0 M = 0 player_1 = player() player_2 = player() card = card() player_1.card = [(13, 'spade'),(14, 'spade')] #player_2.card = [(14, 'club'),(13,'heart card.point(player_1.card) for i in xrange(1000): card.getcard() pub = card.card[:5] player_2.getcard(card.card[5:7],pub) player_1.getcard(player_1.card, pub) player_1.getstyle(pub) player_2.getstyle(pub) a, b = player_1.kind, player_2.kind if a