Esempio n. 1
0
def insideStraightDrawsFromHandType(handType):
	"""generates all inside straight draw types a handType can flop
	@param handType: (str)
	@return: (list) containing all inside straight draw types
	"""
	# determine card ranks. special case Ace low
	if PokerTools.handTypeIsPair(handType):
		return []
	rank1, rank2 = PokerTools.handTypeRanks(handType)
	rank3 = None
	if rank1 == 12:
		rank3 = -1
	# iterate over all inside straight draw candidates
	# 9 x 8 7 6 x 4
	result = []
	for high in range(12, 4, -1):
		rng = range(high, high-7, -1)
		rng[1] = 'x'
		rng[-2] = 'x'
		if rank2 in rng:
			if rank1 in rng:
				rng.pop(1)
				rng.pop(-2)
				result.append([PokerTools.Card.RankNames[i] for i in rng])
			elif rank3 in rng:
				rng[-1] = 12
				rng.pop(1)
				rng.pop(-2)
				result.append([PokerTools.Card.RankNames[i] for i in rng])
	return result
Esempio n. 2
0
    def onEditHandRangeReturnPressed(self):
        handRange = self.handRange()
        if handRange is None:
            return
        handTypes = {}
        for hand in handRange:
            handType = PokerTools.handTypeFromHand(hand)
            if handType not in handTypes:
                handTypes[handType] = []
            handTypes[handType].append(hand)

        self.lock = True
        try:
            for handType, btn in self.handTypeButtons.items():
                hands = handTypes.get(handType, None)
                if hands and PokerTools.handTypeIsPair(handType) and len(
                        hands) == 6:
                    btn.setChecked(True)
                elif hands and PokerTools.handTypeIsSuited(handType) and len(
                        hands) == 4:
                    btn.setChecked(True)
                elif hands and len(hands) == 12:
                    btn.setChecked(True)
                else:
                    btn.setChecked(False)
        finally:
            self.lock = False
Esempio n. 3
0
def insideStraightDrawsFromHandType(handType):
    """generates all inside straight draw types a handType can flop
	@param handType: (str)
	@return: (list) containing all inside straight draw types
	"""
    # determine card ranks. special case Ace low
    if PokerTools.handTypeIsPair(handType):
        return []
    rank1, rank2 = PokerTools.handTypeRanks(handType)
    rank3 = None
    if rank1 == 12:
        rank3 = -1
    # iterate over all inside straight draw candidates
    # 9 x 8 7 6 x 4
    result = []
    for high in range(12, 4, -1):
        rng = range(high, high - 7, -1)
        rng[1] = 'x'
        rng[-2] = 'x'
        if rank2 in rng:
            if rank1 in rng:
                rng.pop(1)
                rng.pop(-2)
                result.append([PokerTools.Card.RankNames[i] for i in rng])
            elif rank3 in rng:
                rng[-1] = 12
                rng.pop(1)
                rng.pop(-2)
                result.append([PokerTools.Card.RankNames[i] for i in rng])
    return result
Esempio n. 4
0
	def onEditHandRangeReturnPressed(self):
		handRange = self.handRange()
		if handRange is None:
			return
		handTypes = {}
		for hand in handRange:
			handType = PokerTools.handTypeFromHand(hand)
			if handType not in handTypes:
				handTypes[handType] = []
			handTypes[handType].append(hand)
		
		self.lock = True
		try:
			for handType, btn in self.handTypeButtons.items():
				hands = handTypes.get(handType, None)
				if hands and PokerTools.handTypeIsPair(handType) and len(hands) == 6:
					btn.setChecked(True)
				elif hands and PokerTools.handTypeIsSuited(handType) and len(hands) == 4:
					btn.setChecked(True)
				elif hands and len(hands) == 12:
					btn.setChecked(True)
				else:
					btn.setChecked(False)
		finally:
			self.lock = False
Esempio n. 5
0
	def __init__(self, handType, iRow, iCol, parent=None):
		QtGui.QPushButton.__init__(self, handType, parent)
		self.fixedSize = None
		self.handType = handType
		self.iRow = iRow
		self.iCol = iCol
		type = None
		if PokerTools.handTypeIsPair(handType):
			self.setObjectName('pair')
		elif PokerTools.handTypeIsSuited(handType):
			self.setObjectName('suited')
		else:
			self.setObjectName('offsuit')
		self.setCheckable(True)
		self.setFocusPolicy(QtCore.Qt.NoFocus)
		sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
		sizePolicy.setHeightForWidth(True)
		self.setSizePolicy(sizePolicy)
Esempio n. 6
0
def genHandTypeData():
	"""
	brute forces flop props of all hand types and prints result as dict to stdout
	WARNING: takes a couple of minutes to complete (~12mins on a reasonably fast machine)
	"""
	deck = PokerTools.CardDeck().cards
	handTypes = PokerTools.genHandTypes()
	print 'HandTypeData = {'
	for handType in handTypes:
		data = dict([(i, 0) for i in HandNames.values()])
		for board in itertools.combinations(deck, 3):
			holeCards = PokerTools.handTypeToHands(handType)[0].cards
			if holeCards[0] in board or holeCards[1] in board:
				continue
			for handNameId, n in evalHandN(holeCards, board).items():
				data[handNameId] += n
		print "\t'%s': {%s}," % (handType, ','.join(['%s:%s' % i for i in sorted(data.items())]))
	print '\t}'		
Esempio n. 7
0
def genHandTypeData():
    """
	brute forces flop props of all hand types and prints result as dict to stdout
	WARNING: takes a couple of minutes to complete (~12mins on a reasonably fast machine)
	"""
    deck = PokerTools.CardDeck().cards
    handTypes = PokerTools.genHandTypes()
    print 'HandTypeData = {'
    for handType in handTypes:
        data = dict([(i, 0) for i in HandNames.values()])
        for board in itertools.combinations(deck, 3):
            holeCards = PokerTools.handTypeToHands(handType)[0].cards
            if holeCards[0] in board or holeCards[1] in board:
                continue
            for handNameId, n in evalHandN(holeCards, board).items():
                data[handNameId] += n
        print "\t'%s': {%s}," % (handType, ','.join(
            ['%s:%s' % i for i in sorted(data.items())]))
    print '\t}'
Esempio n. 8
0
 def __init__(self, handType, iRow, iCol, parent=None):
     QtGui.QPushButton.__init__(self, handType, parent)
     self.fixedSize = None
     self.handType = handType
     self.iRow = iRow
     self.iCol = iCol
     type = None
     if PokerTools.handTypeIsPair(handType):
         self.setObjectName('pair')
     elif PokerTools.handTypeIsSuited(handType):
         self.setObjectName('suited')
     else:
         self.setObjectName('offsuit')
     self.setCheckable(True)
     self.setFocusPolicy(QtCore.Qt.NoFocus)
     sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed,
                                    QtGui.QSizePolicy.Fixed)
     sizePolicy.setHeightForWidth(True)
     self.setSizePolicy(sizePolicy)
Esempio n. 9
0
	def __init__(self, parent=None, styleSheet=None, maxCards=None, cards=None):
		"""
		@param parent: (L{QWidget}) parent or None
		@param styleSheet: (str) stylesheet to apply to the widget
		@param maxCards: (int) maximum number of cards that can be selected or None for unlimited
		@param cards: (list) of L{PokerTools.Card}s to initialize the widget with
		QtGui.QFrame.__init__(self, parent)
		"""
		QtGui.QFrame.__init__(self, parent)
				
		self._maxCards = maxCards
		self._buttonsSelected = []
				
		# add card buttons
		self._cardButtons ={}	# card --> button
		for iCol, suitName in enumerate(PokerTools.Card.SuitNames):
			for iRow, rankName in enumerate(PokerTools.Card.RankNames[::-1]):
				card = PokerTools.Card(rankName+suitName)
				btn = CardButton(card, iRow, iCol, parent=self)
				btn.setStyleSheet(self.StyleSheet if styleSheet is None else styleSheet)
				self._cardButtons[card] = btn
				btn.toggled.connect(self.onCardButtonToggled)
		
		self.handleFontChanged()
		
		# layout
		
		box0 = QtGui.QHBoxLayout(self)
		box0.setSpacing(0)
		box0.setContentsMargins(0, 0, 0, 0)
		box1 = QtGui.QVBoxLayout()
		box0.addLayout(box1)
		
		s = QtGui.QHBoxLayout()
		s.addStretch(999)
		box0.addItem(s)
		
		grid1 = QtGui.QGridLayout()
		#grid1.setSpacing(0)
		#grid1.setContentsMargins(0, 0, 0, 0)
		for btn in self._cardButtons.values():
			grid1.addWidget(btn, btn.iRow, btn.iCol)
					
		box1.addLayout(grid1)
				
		s = QtGui.QVBoxLayout()
		s.addStretch(999)
		box1.addItem(s)
		
		# init widget with cards passed
		if cards is not None:
			for card in cards:
				self._cardButtons[card].setChecked(True)	
Esempio n. 10
0
def evalHandRange(handRange):
	"""evaluates a hand range against all possible flops"""
	noFlops = 0.0
	result = dict([(handName, 0) for handName in HandNames])
	for hand in handRange:
		handType = PokerTools.handTypeFromHand(hand)
		data = HandTypeData[handType]
		for handNameId, n in data.items():
			result[HandNameIds[handNameId]] += n
		noFlops += NoFlops
	for handName, n in result.items():
		result[handName] = n / noFlops
	return result
Esempio n. 11
0
def evalHandRange(handRange):
    """evaluates a hand range against all possible flops"""
    noFlops = 0.0
    result = dict([(handName, 0) for handName in HandNames])
    for hand in handRange:
        handType = PokerTools.handTypeFromHand(hand)
        data = HandTypeData[handType]
        for handNameId, n in data.items():
            result[HandNameIds[handNameId]] += n
        noFlops += NoFlops
    for handName, n in result.items():
        result[handName] = n / noFlops
    return result
Esempio n. 12
0
def straightsFromHandType(handType):
	"""generates all straight types a handType can flop
	@param handType: (str)
	@return: (list) containing all straight types
	"""
	# determine card ranks. special case Ace low
	if PokerTools.handTypeIsPair(handType):
		return []
	rank1, rank2 = PokerTools.handTypeRanks(handType)
	rank3 = None
	if rank1 == 12:
		rank3 = -1
	# iterate over all straight cadidates
	result = []
	for high in range(12, 2, -1):
		rng = range(high, high-5, -1)
		if rank2 in rng:
			if rank1 in rng:
				result.append([PokerTools.Card.RankNames[i] for i in rng])
			elif rank3 in rng:
				rng[-1] = 12
				result.append([PokerTools.Card.RankNames[i] for i in rng])
	return result
Esempio n. 13
0
def straightsFromHandType(handType):
    """generates all straight types a handType can flop
	@param handType: (str)
	@return: (list) containing all straight types
	"""
    # determine card ranks. special case Ace low
    if PokerTools.handTypeIsPair(handType):
        return []
    rank1, rank2 = PokerTools.handTypeRanks(handType)
    rank3 = None
    if rank1 == 12:
        rank3 = -1
    # iterate over all straight cadidates
    result = []
    for high in range(12, 2, -1):
        rng = range(high, high - 5, -1)
        if rank2 in rng:
            if rank1 in rng:
                result.append([PokerTools.Card.RankNames[i] for i in rng])
            elif rank3 in rng:
                rng[-1] = 12
                result.append([PokerTools.Card.RankNames[i] for i in rng])
    return result
Esempio n. 14
0
def outsideStraightDrawsFromHandType(handType):
	"""generates all outside straight draw types a handType can flop
	@param handType: (str)
	@return: (list) containing all outside straight draw types
	"""
	# determine card ranks. special case Ace
	rank1, rank2 = PokerTools.handTypeRanks(handType)
	if rank1 == 12:
		return []
	ranks = (rank1, rank2)
		
	# iterate over all straight draw cadidates
	result = []
	for high in range(12, 3, -1):
		rng = range(high, high-6, -1)
		# if one of the cards is an edge card we do not have a straight draw 
		if rng[0] in ranks or rng[-1] in ranks:
			continue
			
		if rank1 in rng and rank2 in rng:
			rng = rng[1:-1]
			result.append([PokerTools.Card.RankNames[i] for i in rng])
	return result
Esempio n. 15
0
def outsideStraightDrawsFromHandType(handType):
    """generates all outside straight draw types a handType can flop
	@param handType: (str)
	@return: (list) containing all outside straight draw types
	"""
    # determine card ranks. special case Ace
    rank1, rank2 = PokerTools.handTypeRanks(handType)
    if rank1 == 12:
        return []
    ranks = (rank1, rank2)

    # iterate over all straight draw cadidates
    result = []
    for high in range(12, 3, -1):
        rng = range(high, high - 6, -1)
        # if one of the cards is an edge card we do not have a straight draw
        if rng[0] in ranks or rng[-1] in ranks:
            continue

        if rank1 in rng and rank2 in rng:
            rng = rng[1:-1]
            result.append([PokerTools.Card.RankNames[i] for i in rng])
    return result
Esempio n. 16
0
 def HAND(klass, *cards):
     return [PokerTools.Card(card) for card in cards]
Esempio n. 17
0
    def __init__(self, parent=None, styleSheet=None, handRange=None, pct=None):
        """
		@param parent: (L{QWidget}) parent or None
		@param styleSheet: (str) stylesheet to apply to the widget
		@param handRange: (L{PokerTools.HandRangeHoldem}) to initialize the widget with
		@param pct: (float) if no HandRange is specified, percentage of hands to select initially
		"""

        QtGui.QFrame.__init__(self, parent)

        # pseudo lock
        self.lock = False
        self.sliderPressed = False

        # add range table buttons
        self.handTypeButtons = {}  # handType --> button
        for iRow, row in enumerate(PokerTools.genHandTypeTable()):
            for iCol, handType in enumerate(row):
                btn = HandTypeButton(handType, iRow, iCol, parent=self)
                btn.setStyleSheet(
                    self.StyleSheet if styleSheet is None else styleSheet)
                self.handTypeButtons[handType] = btn
                btn.toggled.connect(self.onRangeButtonToggled)

        # add range slider
        self.spin = QtGui.QDoubleSpinBox(self)
        self.spin.setSuffix('%')
        self.spin.setMaximum(100.0)
        self.spin.setDecimals(1)
        self.spin.setSingleStep(0.1)
        self.spin.valueChanged.connect(self.onSpinValueChanged)

        self.slider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.slider.setMaximum(1000)
        self.slider.setPageStep(100)
        self.slider.setTickInterval(100)
        self.slider.setTickPosition(self.slider.TicksAbove)
        self.slider.valueChanged.connect(self.onSliderValueChanged)
        self.slider.sliderPressed.connect(self.onSliderPressed)
        self.slider.sliderReleased.connect(self.onSliderReleased)

        self.editHandRange = QtGui.QLineEdit(self)
        self.editHandRange.returnPressed.connect(
            self.onEditHandRangeReturnPressed)
        #self.editHandRange.setReadOnly(True)

        self.handleFontChanged()

        # layout

        box0 = QtGui.QHBoxLayout(self)
        box0.setSpacing(0)
        box0.setContentsMargins(0, 0, 0, 0)
        box1 = QtGui.QVBoxLayout()
        box0.addLayout(box1)

        s = QtGui.QHBoxLayout()
        s.addStretch(999)
        box0.addItem(s)

        grid1 = QtGui.QGridLayout()
        #grid1.setSpacing(0)
        #grid1.setContentsMargins(0, 0, 0, 0)
        for btn in self.handTypeButtons.values():
            grid1.addWidget(btn, btn.iRow, btn.iCol)

        box1.addLayout(grid1)

        box2 = QtGui.QHBoxLayout()
        box1.addLayout(box2)
        box2.addWidget(self.spin)
        box2.addWidget(self.slider)
        box2.setStretch(1, 99)

        box1.addWidget(self.editHandRange)

        s = QtGui.QVBoxLayout()
        s.addStretch(999)
        box1.addItem(s)

        # init widget
        if handRange is not None:
            self.setHandRange(handRange)
        elif pct is not None:
            self.setHandRangeToPct(pct)
Esempio n. 18
0
		h = w
		fixedSize = QtCore.QSize(w, h)
		for btn in self._cardButtons.values():
			btn.fixedSize = fixedSize
			btn.setMinimumSize(fixedSize)
				
	def onCardButtonToggled(self, flag):
		btn = self.sender()
		if flag:
			if btn not in self._buttonsSelected:
				self._buttonsSelected.append(btn)
			if self._maxCards is not None and len(self._buttonsSelected) > self._maxCards:
				btn = self._buttonsSelected.pop(0)
				btn.setChecked(False)
		else:
			if btn in self._buttonsSelected:
				self._buttonsSelected.remove(btn)
		self.cardsSelectionChanged.emit(self)
		
#************************************************************************************
#
#************************************************************************************
if __name__ == '__main__':
	import sys
	application = QtGui.QApplication(sys.argv)
	gui = CardSelectorWidget(
			maxCards=3, 
			cards=[PokerTools.Card('Ah'), PokerTools.Card('Kd'), PokerTools.Card('Qc')])
	gui.show()
	application.exec_()
Esempio n. 19
0
	def __init__(self, parent=None, styleSheet=None, handRange=None, pct=None):
		"""
		@param parent: (L{QWidget}) parent or None
		@param styleSheet: (str) stylesheet to apply to the widget
		@param handRange: (L{PokerTools.HandRangeHoldem}) to initialize the widget with
		@param pct: (float) if no HandRange is specified, percentage of hands to select initially
		"""
		
		QtGui.QFrame.__init__(self, parent)
				
		# pseudo lock
		self.lock = False
		self.sliderPressed = False
		
		# add range table buttons
		self.handTypeButtons ={}	# handType --> button
		for iRow, row in enumerate(PokerTools.genHandTypeTable()):
			for iCol, handType in enumerate(row):
				btn = HandTypeButton(handType, iRow, iCol, parent=self)
				btn.setStyleSheet(self.StyleSheet if styleSheet is None else styleSheet)
				self.handTypeButtons[handType] = btn
				btn.toggled.connect(self.onRangeButtonToggled)
						
		# add range slider
		self.spin = QtGui.QDoubleSpinBox(self)
		self.spin.setSuffix('%')
		self.spin.setMaximum(100.0)
		self.spin.setDecimals(1)
		self.spin.setSingleStep(0.1)
		self.spin.valueChanged.connect(self.onSpinValueChanged)
		
		self.slider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
		self.slider.setMaximum(1000)
		self.slider.setPageStep(100)
		self.slider.setTickInterval(100)
		self.slider.setTickPosition(self.slider.TicksAbove)
		self.slider.valueChanged.connect(self.onSliderValueChanged)
		self.slider.sliderPressed.connect(self.onSliderPressed)
		self.slider.sliderReleased.connect(self.onSliderReleased)
		
		self.editHandRange = QtGui.QLineEdit(self)
		self.editHandRange.returnPressed.connect(self.onEditHandRangeReturnPressed)
		#self.editHandRange.setReadOnly(True)
		
		self.handleFontChanged()
		
		# layout
		
		box0 = QtGui.QHBoxLayout(self)
		box0.setSpacing(0)
		box0.setContentsMargins(0, 0, 0, 0)
		box1 = QtGui.QVBoxLayout()
		box0.addLayout(box1)
		
		s = QtGui.QHBoxLayout()
		s.addStretch(999)
		box0.addItem(s)
		
		grid1 = QtGui.QGridLayout()
		#grid1.setSpacing(0)
		#grid1.setContentsMargins(0, 0, 0, 0)
		for btn in self.handTypeButtons.values():
			grid1.addWidget(btn, btn.iRow, btn.iCol)
					
		box1.addLayout(grid1)
				
		box2 = QtGui.QHBoxLayout()
		box1.addLayout(box2)
		box2.addWidget(self.spin)
		box2.addWidget(self.slider)
		box2.setStretch(1, 99)
		
		box1.addWidget(self.editHandRange)
		
		s = QtGui.QVBoxLayout()
		s.addStretch(999)
		box1.addItem(s)
				
		# init widget
		if handRange is not None:
			self.setHandRange(handRange)
		elif pct is not None:
			self.setHandRangeToPct(pct)