Dec-23-2021, 10:22 PM
Hello, I've introduced classes in one of my project for the first time and now i can't seem to understand what goes where anymore... I'm trying to build a poker game and I've created a player class
This clearly shows that i don't know what I'm doing. I've been on the net to see what needs to be where, but I only find basic stuff with general explanation about basic stuff, like car class with drive functions so I think i need someone who can help me make sense of of functions inside functions.
Keep in mind this is my first program ever
class Player: hand = [] playershand = [] playersgrade = [] dealer = False smallblind = False bigblind = False def __init__(self, number, chips): self.number = number self.chips = chips def bet(self): print("Bet") def besthands(self, pair, triple, quadruple, checksetinplayershand, checkstraightinplayershand, checkflushinplayershand): sets = checksetinplayershand(hand, flop, turn, river, a, pair, doublepair, triplepair, triple, doubletriple, quadruple) straights = checkstraightinplayershand( hand, flop, turn, river) flush = checkflushinplayershand(hand, flop, turn, river) print(sets) print(straights) print(flush) print() if straightinplayershandandriver == True and flushinplayershandandriver == True: grade = 'Royal straight flush' grade.append(max(tgrade)) return grade elif quadruple == True: max(sets) return listofquadruple #not finished... def raisestakes(self): pass def call(self): pass def check(self): pass def fold(self): pass def quit(self): pass def showstats(self): pass class me(Player): passand here's my main program
import random import time import sys from classes import * from straightfunction import * from pairfunction import * from flushfunction import * deck = [['1','H'], ['2','H'], ['3','H'], ['4','H'], ['5','H'], ['6','H'], ['7','H'], ['8','H'], ['9','H'], ['10','H'], ['11','H'], ['12','H'], ['13','H'], ['1','D'], ['2','D'], ['3','D'], ['4','D'], ['5','D'], ['6','D'], ['7','D'], ['8','D'], ['9','D'], ['10','D'], ['11','D'], ['12','D'], ['13','D'], ['1','C'], ['2','C'], ['3','C'], ['4','C'], ['5','C'], ['6','C'], ['7','C'], ['8','C'], ['9','C'], ['10','C'], ['11','C'], ['12','C'], ['13','C'], ['1','S'], ['2','S'], ['3','S'], ['4','S'], ['5','S'], ['6','S'], ['7','S'], ['8','S'], ['9','S'], ['10','S'], ['11','S'], ['12','S'], ['13','S']] card = [] hand = [] flop = [] turn = [] river = [] cardsdrawn = [] playersgrade = [] def pickacard(deck): card = deck[0] deck.remove(deck[0]) return card def pickplayershand(deck): card = pickacard(deck) deck.remove(deck[0]) hand.append(card) card = pickacard(deck) deck.remove(deck[0]) hand.append(card) return hand def pickflop(deck, flop): for i in range(3): flop.append(deck[0]) cardsdrawn.append(deck[0]) deck.remove(deck[0]) return flop def pickturn(deck, turn): turn.append(deck[0]) cardsdrawn.append(deck[0]) deck.remove(deck[0]) return turn def pickriver(deck,river): river.append(deck[0]) cardsdrawn.append(deck[0]) deck.remove(deck[0]) return river random.shuffle(deck) print(pickplayershand(deck)) print(pickflop(deck,flop)) print(pickturn(deck,turn)) print(pickriver(deck, river)) playershand= hand+flop+turn+river print(playershand) player1 = Player(1, 250) player1.besthands(pair, triple, quadruple, checksetinplayershand, checkstraightinplayershand, checkflushinplayershand)And here's my error
Error:Traceback (most recent call last):
File "/usr/lib/python3.8/idlelib/run.py", line 559, in runcode
exec(code, self.locals)
File "/home/fook/Documents/pygame/Poker Practice/Poker.py", line 77, in <module>
player1.besthands(pair, triple, quadruple, checksetinplayershand, checkstraightinplayershand, checkflushinplayershand)
File "/home/fook/Documents/pygame/Poker Practice/classes.py", line 33, in besthands
sets = checksetinplayershandandriver(hand, flop, turn, river, a, pair, doublepair, triplepair, triple, doubletriple, quadruple)
NameError: name 'hand' is not defined
Now... I know the hand =[ ] in the player class is empty and i tried putting the pickacard function in the class, but then it created another set of problems that i think have the same root as this one: " I'm calling a function in my class that has a function inside, which i give in the arguments, that has variables outside my class...This clearly shows that i don't know what I'm doing. I've been on the net to see what needs to be where, but I only find basic stuff with general explanation about basic stuff, like car class with drive functions so I think i need someone who can help me make sense of of functions inside functions.
Keep in mind this is my first program ever