Python Forum
I need help understanding a program structure using classes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help understanding a program structure using classes
#1
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

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):
    pass
    
and 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
Reply


Messages In This Thread
I need help understanding a program structure using classes - by CompleteNewb - Dec-23-2021, 10:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Understanding Python classes PythonNewbee 3 1,322 Nov-10-2022, 11:07 PM
Last Post: deanhystad
  Understanding Python super() for classes OmegaRed94 1 1,926 Jun-09-2021, 09:02 AM
Last Post: buran
  Understanding program blocks newbieAuggie2019 2 2,090 Oct-02-2019, 06:22 PM
Last Post: newbieAuggie2019
  help with understanding a program prompt drasil 5 3,094 Feb-14-2019, 05:54 PM
Last Post: ichabod801
  Help, not understanding how classes work... Peter_EU 1 2,429 Jan-20-2018, 06:07 PM
Last Post: wavic
  Using classes? Can I just use classes to structure code? muteboy 5 5,212 Nov-01-2017, 04:20 PM
Last Post: metulburr
  I need help understanding how to use and run this program! Thanks in advance! tc1chosen 6 4,931 Sep-01-2017, 01:56 PM
Last Post: tc1chosen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020