Hello everyone , i'm glad that i 've found this website as it truly helpfull..
to my problem, i'm a beginner in Python programming but i want to do a simple poker game using this amazing language so far , the problem is that i can't see how can i make it run (e.g. risk calculation) and to connect all different functions together . i want it to be simple so I included my code here , any comment or advice will be greatly appreciated.
thank you in advance,
soltan
CODE
from random import *
from math import *
#GLOBAL VARIABLES
cards = range(0,52)
def randRange(lower,upper):
"""return a value in the range in_lower to in_upper
inclusive
"""
temp_range = upper - lower
return int(round((temp_range+0.5)*random() + (lower - 0.5)))
def dealCard():
"""simulate a deal from a hand of cards
"""
return randRange(0,51)
def randArray(in_list):
return in_list[randRange(0,len(in_list)-1)]
def popRandArray(in_list):
""" return a random value from an array with no replacement
"""
return in_list.pop(randRange(0,len(in_list)-1))
def dealCardTuple():
"""return a tuple with a random card assigned
"""
return int(randRange(0,12)),int(randRange(0,3))
def cardTupleAsString(in_tuple):
"""turn a deal from a hand of cards as a tuple into a string
"""
temp_value,temp_suite = in_tuple
value = ["ace","two","three","four","five","six","seven","eight","nine","ten","jack","queen","king"]
suite = ["hearts","diamonds","spades","clubs"]
return value[temp_value]+ " of " + suite[temp_suite]
def cardAsString(in_card):
"""turn a deal from a hand of cards as a tuple into a string
"""
value = ["ace","two","three","four","five","six","seven","eight","nine","ten","jack","queen","king"]
suit = ["hearts","diamonds","spades","clubs"]
return value[in_card%13]+ " of " + suit[in_card/13]
def realDealCard():
"""performs a non replacement randomised lookup
"""
global cards
#check to see if the array still has a card in it
if len(cards)==0:
print "new deck"
cards = range(0,52)
return popRandArray(cards)
def testCards():
"""tests the distribution of card when dealing a mulitple
number of hands"""
hands=int(raw_input('how many hands do you want to play?:'))
histo = 52 * [0]
for i in range(1,hands*52+1):
n = realDealCard()
histo[n] = histo[n] + 1
for i,v in enumerate(histo):
print cardAsString(i) + " " + str(v)
#print dealCard()
def cardScore(in_card):
"""converts a card into a numerical score"""
score = in_card%13+1
if score > 10:
score = 11
return score