Replayer: Refactor player code into its own class

This commit is contained in:
Worros 2010-12-23 15:26:28 +08:00
parent 18ccea9a67
commit 54264bb263

View File

@ -31,6 +31,9 @@ import gtk
import math import math
import gobject import gobject
import pprint
pp = pprint.PrettyPrinter(indent=4)
class GuiReplayer: class GuiReplayer:
def __init__(self, config, querylist, mainwin, options = None, debug=True): def __init__(self, config, querylist, mainwin, options = None, debug=True):
@ -105,8 +108,6 @@ class GuiReplayer:
self.MyHand = self.importhand() self.MyHand = self.importhand()
self.table = Table(self.area, self.MyHand).table self.table = Table(self.area, self.MyHand).table
self.maxseats=self.MyHand.maxseats
if self.MyHand.gametype['currency']=="USD": #TODO: check if there are others .. if self.MyHand.gametype['currency']=="USD": #TODO: check if there are others ..
self.currency="$" self.currency="$"
elif self.MyHand.gametype['currency']=="EUR": elif self.MyHand.gametype['currency']=="EUR":
@ -291,23 +292,18 @@ class Table:
def __init__(self, darea, hand): def __init__(self, darea, hand):
self.darea = darea self.darea = darea
self.hand = hand self.hand = hand
self.players = []
#self.pixmap = gtk.gdk.Pixmap(darea, width, height, depth=-1) #self.pixmap = gtk.gdk.Pixmap(darea, width, height, depth=-1)
# tmp var while refactoring
self.table = {} self.table = {}
for i in range(0, hand.maxseats): # radius: 200, center: 250,250 i = 0
x= int (round(250+200*math.cos(2*i*math.pi/hand.maxseats))) for seat, name, chips in hand.players:
y= int (round(250+200*math.sin(2*i*math.pi/hand.maxseats))) self.players.append(Player(hand, name, chips, seat))
try: self.table[i] = self.players[i].get_hash()
self.table[i]={"name":self.hand.players[i][1],"stack":Decimal(self.hand.players[i][2]),"x":x,"y":y,"chips":0,"status":"live"} #save coordinates of each player i += 1
try:
self.table[i]['holecards']=self.hand.holecards["PREFLOP"][self.hand.players[i][1]][1]+' '+self.hand.holecards["PREFLOP"][self.hand.players[i][1]][2]
print "holecards: ",self.table[i]['holecards']
except:
self.table[i]['holecards']=''
except IndexError: #if seat is empty
print "seat ",i+1," out of ", hand.maxseats," empty"
print "DEBUG: table: %s" % self.table pp.pprint(self.table)
def draw(self): def draw(self):
draw_players() draw_players()
@ -315,13 +311,25 @@ class Table:
draw_community_cards() draw_community_cards()
class Player: class Player:
def __init__(self, name, stack, position): def __init__(self, hand, name, stack, seat):
self.active = True self.status = 'live'
self.stack = stack self.stack = Decimal(stack)
self.position = position self.chips = 0
self.seat = seat
self.name = name self.name = name
x = 0 self.holecards = hand.join_holecards(name)
y = 0 self.x = int (round(250+200*math.cos(2*self.seat*math.pi/hand.maxseats)))
self.y = int (round(250+200*math.sin(2*self.seat*math.pi/hand.maxseats)))
def get_hash(self):
return { 'chips': 0,
'holecards': self.holecards,
'name': self.name,
'stack': self.stack,
'status': self.status,
'x': self.x,
'y': self.y,
}
def draw(self): def draw(self):
draw_name() draw_name()