Accueil > > > PRONOSTIQUES DE POKER PRÉ-FLOP
PRONOSTIQUES DE POKER PRÉ-FLOP
Information sur la source
Description
Calcul de chance de gain pour un jeu de poker de type Texas Holdem. Les calculs sont réalisés par choix avant l'arrivée du flop, ce qui peut être facilement modifié pour suivre chaque étape du jeu.
Source
- from pylab import *
- from numpy import *
- from scipy import *
- import time
-
- tps1=time.clock()
-
- def hand(cartes):
- "The aim of this function is to determine the best 5 card hand"
- "out of a set of 7 cards."
- # Pair
- main = cartes[:]
- sortie = 0
- exit = 0
- a = 10000
- for i in range(7):
- if (int(cartes[i]/100)==2):
- a += 10
- elif (int(cartes[i]/100)==3):
- a += 100
- elif (int(cartes[i]/100)==4):
- a += 1000
- else:
- a += 1
- # print a
- a = str(a)
- if (a[1]>='5' or a[2]>='5' or a[3]>='5' or a[4]>='5'):
- # The hand present at least a flush :
- if (a[1]>='5'):
- for i in range(7):
- if (int(cartes[i]/100)!=4):
- main.remove(cartes[i])
- if (len(main)==5):
- break
- elif (a[2]>='5'):
- for i in range(7):
- if (int(cartes[i]/100)!=3):
- main.remove(cartes[i])
- if (len(main)==5):
- break
- elif (a[3]>='5'):
- for i in range(7):
- if (int(cartes[i]/100)!=2):
- main.remove(cartes[i])
- if (len(main)==5):
- break
- elif (a[4]>='5'):
- for i in range(7):
- if (int(cartes[i]/100)!=1):
- main.remove(cartes[i])
- if (len(main)==5):
- break
- for i in range(len(main)):
- main[i]=main[i]%100
- main.sort()
- main.reverse()
- main2 = list(set(main))
- main2.reverse()
- if (len(main2)>=5):
- for i in range(len(main2)-4):
- if (main2[i]==main2[i+4]+4):
- # print 'suited flush'
- sortie = (main2[i])*10**20
- exit = 1
- if (exit==0):
- # print main
- if (main2[0]==13 and main2[-1]==1):
- if (main2[-4]==main2[-1]+3):
- # print 'little suite'
- sortie = (main2[-4])*10**12
- exit=1
- if (exit==0):
- for i in range(5):
- # print 'flush'
- sortie += (main[i])*10**(2*(4-i))
- sortie = sortie*10**6
- else:
- # 2oaK // 3oaK // suite // Full // 4oaK
- for i in range(len(main)):
- main[i]=main[i]%100
- main.sort()
- main.reverse()
- main2 = list(set(main))
- main2.reverse()
- if (len(main2)>=5):
- for i in range(len(main2)-4):
- if (main2[i]==main2[i+4]+4):
- # print 'suited'
- sortie = (main2[i])*10**12
- exit=1
- if (exit==0):
- # print main
- if (main2[0]==13 and main2[-1]==1):
- if (main2[-4]==main2[-1]+3):
- # print 'little suite'
- sortie = (main2[-4])*10**12
- exit=1
- for i in range(len(main)-3):
- if (exit==0):
- if (main[i]==main[i+3]):
- # print '4 of a kind'
- sortie = main[i]
- main.remove(main[i])
- main.remove(main[i])
- main.remove(main[i])
- main.remove(main[i])
- sortie = sortie*10**18 + main[0]
- exit=1
- for i in range(len(main)-2):
- if (exit==0):
- if (main[i]==main[i+2]):
- sortie = main[i]
- main.remove(main[i])
- main.remove(main[i])
- main.remove(main[i])
- for j in range(len(main)-1):
- if (main[j]==main[j+1]):
- # print 'full'
- sortie = sortie*10**16 + main[j]
- exit=1
- if (exit==0):
- # print '3 of a kind'
- sortie = sortie*10**10+main[0]*100+main[1]
- exit=1
- for i in range(len(main)-1):
- if (exit==0):
- if (main[i]==main[i+1]):
- sortie = main[i]
- main.remove(main[i])
- main.remove(main[i])
- for j in range(len(main)-1):
- if (main[j]==main[j+1]):
- # print '2 pairs'
- sortie = sortie*10**8 + main[j]*10**6
- main.remove(main[j])
- main.remove(main[j])
- sortie += main[0]
- exit=1
- break
- if (exit==0):
- # print '2 of a kind'
- sortie = sortie*10**6
- sortie += (main[0])*10**4+(main[1])*100+main[2]
- exit=1
- if (exit==0):
- # print 'nothing'
- for i in range(5):
- sortie += main[i]
- return sortie
-
- Clubs = ['C2','C3','C4','C5','C6','C7','C8','C9','CT','CJ','CQ','CK','CA']
- Diamonds = ['D2','D3','D4','D5','D6','D7','D8','D9','DT','DJ','DQ','DK','DA']
- Hearts = ['H2','H3','H4','H5','H6','H7','H8','H9','HT','HJ','HQ','HK','HA']
- Spades = ['S2','S3','S4','S5','S6','S7','S8','S9','ST','SJ','SQ','SK','SA']
-
- Jeu = Clubs + Diamonds + Hearts + Spades
-
- nplayers = input('Number of players ?')
- # nplayers = 9
-
- card1=raw_input('\n Please enter your first card :')
- card2=raw_input('Please enter your second card :')
- myhand=[[card1,card2]]
- # myhand = [['CA','SA']]
-
- N = 5000
- gain = zeros(nplayers)
-
- for iter in range(N):
- hands=[[0,0]]
- # print iter
- # Jeu_1 : cards that might stay in the game
- # Jeu_2 : index of theses cards
- Jeu_1 = Jeu[:]
- Jeu_2 = range(52)
- for i in range(13):
- for j in range(4):
- Jeu_2[j*13+i] = 100*(j+1)+(i+1)
- #
- # print hands
- # translation into card index :
- for i in range(2):
- if myhand[0][i][0]=='C':
- n = Clubs.index(myhand[0][i])
- carte = 100+(n+1)
- elif myhand[0][i][0]=='D':
- n = Diamonds.index(myhand[0][i])
- carte = 200+(n+1)
- elif myhand[0][i][0]=='H':
- n = Hearts.index(myhand[0][i])
- carte = 300+(n+1)
- elif myhand[0][i][0]=='S':
- n = Spades.index(myhand[0][i])
- carte = 400+(n+1)
- hands[0][i] = carte
- #
- Jeu_1.remove(Jeu_1[Jeu_2.index(hands[0][0])])
- Jeu_2.remove(hands[0][0])
- Jeu_1.remove(Jeu_1[Jeu_2.index(hands[0][1])])
- Jeu_2.remove(hands[0][1])
- #
- #
- # first round :
- #--------------
- for n in range(nplayers-1):
- cards = [0,0]
- for i in range(2):
- rd = rand(1)
- tirage=rd*(len(Jeu_2)-1)
- # print n,i,int(tirage)
- cards[i]=Jeu_2[int(tirage)]
- Jeu_1.remove(Jeu_1[Jeu_2.index(cards[i])])
- Jeu_2.remove(cards[i])
- hands += [cards]
- #
- cards=[]
- for i in range(5):
- rd = rand(1)
- tirage=rd*(len(Jeu_2)-1)
- cards += [Jeu_2[int(tirage)]]
- Jeu_1.remove(Jeu_1[Jeu_2.index(cards[i])])
- Jeu_2.remove(cards[i])
- #
- scores=[]
- for n in range(nplayers):
- cartes = hands[n] + cards
- # print cartes
- scores += [hand(cartes)]
- # print scores
- gain[scores.index(max(scores))] += 1
-
- gain = gain/float(N)
- print''
- print '\tRESULTS with hand :',myhand[0][0],myhand[0][1]
- print '*******************************************'
- for i in range(len(gain)):
- if (i==0):
- print 'you','\t\t-->\t',gain[i]*100,'\t%'
- else:
- print 'player',i+1,'\t-->\t',gain[i]*100,'\t%'
- print '*******************************************'
- print 'error : ',100*(max(gain[1:])-min(gain[1:])),'%'
-
- tps2=time.clock()
- print 'execution time :',tps2-tps1,'s'
-
from pylab import *
from numpy import *
from scipy import *
import time
tps1=time.clock()
def hand(cartes):
"The aim of this function is to determine the best 5 card hand"
"out of a set of 7 cards."
# Pair
main = cartes[:]
sortie = 0
exit = 0
a = 10000
for i in range(7):
if (int(cartes[i]/100)==2):
a += 10
elif (int(cartes[i]/100)==3):
a += 100
elif (int(cartes[i]/100)==4):
a += 1000
else:
a += 1
# print a
a = str(a)
if (a[1]>='5' or a[2]>='5' or a[3]>='5' or a[4]>='5'):
# The hand present at least a flush :
if (a[1]>='5'):
for i in range(7):
if (int(cartes[i]/100)!=4):
main.remove(cartes[i])
if (len(main)==5):
break
elif (a[2]>='5'):
for i in range(7):
if (int(cartes[i]/100)!=3):
main.remove(cartes[i])
if (len(main)==5):
break
elif (a[3]>='5'):
for i in range(7):
if (int(cartes[i]/100)!=2):
main.remove(cartes[i])
if (len(main)==5):
break
elif (a[4]>='5'):
for i in range(7):
if (int(cartes[i]/100)!=1):
main.remove(cartes[i])
if (len(main)==5):
break
for i in range(len(main)):
main[i]=main[i]%100
main.sort()
main.reverse()
main2 = list(set(main))
main2.reverse()
if (len(main2)>=5):
for i in range(len(main2)-4):
if (main2[i]==main2[i+4]+4):
# print 'suited flush'
sortie = (main2[i])*10**20
exit = 1
if (exit==0):
# print main
if (main2[0]==13 and main2[-1]==1):
if (main2[-4]==main2[-1]+3):
# print 'little suite'
sortie = (main2[-4])*10**12
exit=1
if (exit==0):
for i in range(5):
# print 'flush'
sortie += (main[i])*10**(2*(4-i))
sortie = sortie*10**6
else:
# 2oaK // 3oaK // suite // Full // 4oaK
for i in range(len(main)):
main[i]=main[i]%100
main.sort()
main.reverse()
main2 = list(set(main))
main2.reverse()
if (len(main2)>=5):
for i in range(len(main2)-4):
if (main2[i]==main2[i+4]+4):
# print 'suited'
sortie = (main2[i])*10**12
exit=1
if (exit==0):
# print main
if (main2[0]==13 and main2[-1]==1):
if (main2[-4]==main2[-1]+3):
# print 'little suite'
sortie = (main2[-4])*10**12
exit=1
for i in range(len(main)-3):
if (exit==0):
if (main[i]==main[i+3]):
# print '4 of a kind'
sortie = main[i]
main.remove(main[i])
main.remove(main[i])
main.remove(main[i])
main.remove(main[i])
sortie = sortie*10**18 + main[0]
exit=1
for i in range(len(main)-2):
if (exit==0):
if (main[i]==main[i+2]):
sortie = main[i]
main.remove(main[i])
main.remove(main[i])
main.remove(main[i])
for j in range(len(main)-1):
if (main[j]==main[j+1]):
# print 'full'
sortie = sortie*10**16 + main[j]
exit=1
if (exit==0):
# print '3 of a kind'
sortie = sortie*10**10+main[0]*100+main[1]
exit=1
for i in range(len(main)-1):
if (exit==0):
if (main[i]==main[i+1]):
sortie = main[i]
main.remove(main[i])
main.remove(main[i])
for j in range(len(main)-1):
if (main[j]==main[j+1]):
# print '2 pairs'
sortie = sortie*10**8 + main[j]*10**6
main.remove(main[j])
main.remove(main[j])
sortie += main[0]
exit=1
break
if (exit==0):
# print '2 of a kind'
sortie = sortie*10**6
sortie += (main[0])*10**4+(main[1])*100+main[2]
exit=1
if (exit==0):
# print 'nothing'
for i in range(5):
sortie += main[i]
return sortie
Clubs = ['C2','C3','C4','C5','C6','C7','C8','C9','CT','CJ','CQ','CK','CA']
Diamonds = ['D2','D3','D4','D5','D6','D7','D8','D9','DT','DJ','DQ','DK','DA']
Hearts = ['H2','H3','H4','H5','H6','H7','H8','H9','HT','HJ','HQ','HK','HA']
Spades = ['S2','S3','S4','S5','S6','S7','S8','S9','ST','SJ','SQ','SK','SA']
Jeu = Clubs + Diamonds + Hearts + Spades
nplayers = input('Number of players ?')
# nplayers = 9
card1=raw_input('\n Please enter your first card :')
card2=raw_input('Please enter your second card :')
myhand=[[card1,card2]]
# myhand = [['CA','SA']]
N = 5000
gain = zeros(nplayers)
for iter in range(N):
hands=[[0,0]]
# print iter
# Jeu_1 : cards that might stay in the game
# Jeu_2 : index of theses cards
Jeu_1 = Jeu[:]
Jeu_2 = range(52)
for i in range(13):
for j in range(4):
Jeu_2[j*13+i] = 100*(j+1)+(i+1)
#
# print hands
# translation into card index :
for i in range(2):
if myhand[0][i][0]=='C':
n = Clubs.index(myhand[0][i])
carte = 100+(n+1)
elif myhand[0][i][0]=='D':
n = Diamonds.index(myhand[0][i])
carte = 200+(n+1)
elif myhand[0][i][0]=='H':
n = Hearts.index(myhand[0][i])
carte = 300+(n+1)
elif myhand[0][i][0]=='S':
n = Spades.index(myhand[0][i])
carte = 400+(n+1)
hands[0][i] = carte
#
Jeu_1.remove(Jeu_1[Jeu_2.index(hands[0][0])])
Jeu_2.remove(hands[0][0])
Jeu_1.remove(Jeu_1[Jeu_2.index(hands[0][1])])
Jeu_2.remove(hands[0][1])
#
#
# first round :
#--------------
for n in range(nplayers-1):
cards = [0,0]
for i in range(2):
rd = rand(1)
tirage=rd*(len(Jeu_2)-1)
# print n,i,int(tirage)
cards[i]=Jeu_2[int(tirage)]
Jeu_1.remove(Jeu_1[Jeu_2.index(cards[i])])
Jeu_2.remove(cards[i])
hands += [cards]
#
cards=[]
for i in range(5):
rd = rand(1)
tirage=rd*(len(Jeu_2)-1)
cards += [Jeu_2[int(tirage)]]
Jeu_1.remove(Jeu_1[Jeu_2.index(cards[i])])
Jeu_2.remove(cards[i])
#
scores=[]
for n in range(nplayers):
cartes = hands[n] + cards
# print cartes
scores += [hand(cartes)]
# print scores
gain[scores.index(max(scores))] += 1
gain = gain/float(N)
print''
print '\tRESULTS with hand :',myhand[0][0],myhand[0][1]
print '*******************************************'
for i in range(len(gain)):
if (i==0):
print 'you','\t\t-->\t',gain[i]*100,'\t%'
else:
print 'player',i+1,'\t-->\t',gain[i]*100,'\t%'
print '*******************************************'
print 'error : ',100*(max(gain[1:])-min(gain[1:])),'%'
tps2=time.clock()
print 'execution time :',tps2-tps1,'s'
Historique
- 07 août 2010 20:41:26 :
- doublon de code
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
codage des caracteres [ par jerompnt ]
Bonjour a toussur python2.4/windows2000/idleQuand j'affiche des listes(et uniquement pour les listes) dont les chaines possédent un accent,
Zope: Contenu d'une liste en fonction d'une autre [ par keumlebarbare ]
AU SECOURS!!!! Je suis tout ce qu'il y a de plus débutant en Zope, et je crois que si je continue à galérer comme ca, je me (re)met a
Problemes avec les listes [ par BzsReg ]
Bonjours, J'ai la liste suivante liste=[["dupont","remi",1],["durand","pierre",2]]Pour classer par nom je fais liste.sort ,est il possible de classer
|
Derniers Blogs
TECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYSTECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYS par ROMELARD Fabrice
Speakers : Lionel Limozin et Alain Marty La session commence par une découverte de SharePoint à travers la mise en place d'un environnement SharePoint pour la gestion des Sessions animées par BeWise. Le besoin est très ba...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice PERSPECTIVE 3.0 POUR SILVERLIGHT 5.0PERSPECTIVE 3.0 POUR SILVERLIGHT 5.0 par odewit
Je viens de publier la version 3.0 de Perspective pour Silverlight, qui regroupe un portage sous Silverlight 5.0 des fonctionnalités de Perspective 2.0, le framework 3D de haut-niveau introduit récemment et de nouveaux exemples de code. En voici la li...
Cliquez pour lire la suite de l'article par odewit TECHDAYS PARIS 2012 : TOP 10 DES BEST PRACTICES POUR SQL SERVERTECHDAYS PARIS 2012 : TOP 10 DES BEST PRACTICES POUR SQL SERVER par ROMELARD Fabrice
Speaker : Nadia Ben El Kadi Configuration machine La session commence par la toute première question à se poser lors de la mise en place d'environnement SQL Server, la configuration des machines : Type de mac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : KINECT + OFFICE 365 UN BON GESTE POUR VOTRE SITECHDAYS PARIS 2012 : KINECT + OFFICE 365 UN BON GESTE POUR VOTRE SI par ROMELARD Fabrice
Speakers : Fabrice Barbin, Samuel Blanchard, Julien Lo Presti Titre Prometteur et attractif invitant à voir comment lier le composant ludique Kinect dans le cadre d'une structure IT classique, notamment au travers de la plat...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE DU PREMIER JOURTECHDAYS PARIS 2012 : PLEINIèRE DU PREMIER JOUR par ROMELARD Fabrice
KeyNotes du premier jour pour les développeurs. La session est principalement axée sur une des principales directions prise par Microsoft à travers tous ses nouveaux produits : Cloud privé ou public (Solution Azure) ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
PYVISA PROBLèMEPYVISA PROBLèME par sandrine44
Cliquez pour lire la suite par sandrine44
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|