class - sequential list for python poker program -


i want build straight function texas hold'em program. i've created test values , want function return list of cards satisfy straight.

this have far:

import cards  c1=cards.card(1,1) c2=cards.card(2,1) c3=cards.card(3,2) c4=cards.card(4,2) c5=cards.card(5,2) c6=cards.card(6,4) c7=cards.card(3,4) c8=cards.card(7,3) h1=[c7,c3,c2,c6,c5,c4,c1] h2=[c1,c2,c3,c2,c3,c3,c8]   def build_rank_d(h):     dict1={}     item in h:         a=item.get_rank()         if not in dict1:             dict1[a]=[item]           else:             dict1[a].append(item)       return dict1  def straight(h):     sequence=set()     item in h:         a=item.get_rank()         sequence.add(a)      list_seq=list(sequence)     n=list_seq[0]     new_list=[]     if list_seq[1]==n+1 , list_seq[2]==n+2 , list_seq[3]==n+3 , list_seq[4]==n+4         print("you have straight")         return h      else:         print("no straight found")     return []   print(straight(h1))  straight(h2) 

right function prints entire set of cards, not cards satisfy straight, want.

this sample of cards class program i've imported:

import random    # required shuffle method of deck  class card(object):     ''' suit , rank ints, , index suit_list , rank_list.         value different rank: example face cards equal in value (all 10)     '''     # use these lists map ints of suit , rank nice words.     # 'x' place holder index-2 maps '2', etc.     suit_list = ['x','c','d','h','s']     rank_list = ['x', 'a', '2', '3', '4', '5', '6', '7', '8', '9', '10','j', 'q', 'k']      def __init__(self, rank=0, suit=0):         ''' rank , suit must ints. checks in correct range.             blank card has rank , suit set 0.         '''         if type(suit) == int , type(rank) == int:             # indicies work             if suit in range(1,5) , rank in range(1,15):                 self.__suit = suit                 self.__rank = rank              else:                 self.__suit = 0                 self.__rank = 0         else:             self.__suit = 0             self.__rank = 0     def get_rank(self):         return self.__rank      def get_suit(self):         return self.__suit 

what does:

sequence = set() ... list_seq=list(sequence) 

is produce list of integers in random order (set unordered), want sort list first before making comparisons.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -