begin process at 2012 02 08 13:24:10
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Math & Algorithmes

 > PRONOSTIQUES DE POKER PRÉ-FLOP

PRONOSTIQUES DE POKER PRÉ-FLOP


 Information sur la source

Note :
Aucune note
Catégorie :Math & Algorithmes Classé sous :poker, probabilités, listes Niveau :Débutant Date de création :07/08/2010 Date de mise à jour :07/08/2010 20:41:26 Vu :2 970

Auteur : kawamythe

Ecrire un message privé
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 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

Source avec Zip BASE64 ENCRYPT/DECRYPT PYTHON BY MAXOU56800 par Maxou56800
Source avec Zip Source avec une capture TRIANGULATION par mecrosoft
Source avec Zip Source avec une capture COURBE DE BEZIER par mecrosoft
Source avec Zip Source avec une capture CALCUL D'AIRE D'UN TRIANGLE [INTERFACE GRAPHIQUE] par SeventhSon
Source avec Zip Source avec une capture SUITE DE FIBONACCI [INTERFACE GRAPHIQUE] par SeventhSon

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture LE MOT LE PLUS LONG PAR DICO par Clempython
Source avec une capture POKER : ANALYSE DES MAINS ET DES RÉSULTATS DE TOURNOIS POUR ... par guillaume_pays_cevenol
Source avec Zip NOMBRES PREMIERS, LISTES, NOMBRES PREMIERS JUMEAUX, CONJECTU... par Julien39
Source avec Zip MASTERMIND (PAR JULIE ET HCD) par HCD

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


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


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 2,574 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales