[Tutor] New programmer, need some help getting started on my first project

2006-05-16 Thread Chris Delgado
Hello all, I have been studying python tutorials and have a couple beginning python books that I have worked through. I have a very specific project in mind and I want to ask a couple questions. The project in question is this:I am making a Hand History converter for online poker players. This takes the textual record of how a hand played and turns into a more readable format suitable for posting at various websites where people discuss how the hand was played. Id like to start with the converter working for one particular online poker site (every site formats their hand histories somewhat differently) and expand it so that it can recognize the site a hand history came from and format accordingly. So, I am pretty sure that regular expressions will play a big part in the functions in this program. Also, the converter needs to be able to pull dollar amounts out and add them up to keep a running pot size for each round of betting. I guess I am really
 unsure of how to start. Ive sort of drawn out how I think the program should flow. I know this is sort of an open ended question and I hope it is appropriate for the list. What would really be helpful is if someone was willing to correspond privately since Im sure I will have a flood of questions but I realize you all have lives and so this might not be desireable or doable. But if anyone is willing, it would be really helpful. Ive been lurking for a few days now and this seems like a very friendly and helpful group. Thanks for taking the time to read this and I look forward to reading your replies, should anyone decide to do so. ChrisPS I should add that some of these "converters" already exist, I have the perl script for one but the site I currently play on isnt supported and plus I just want to do this. :)
		Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New programmer, need some help getting started on my first project

2006-05-16 Thread Chris Delgado
Alan, First off, thanks for the detailed reply, it is much appreciated. On to your message:>I don't know anything about poker but in general terms this is>a text format conversion tool. since you know the source can>be in different formats I'd adopt an OOP approach with a generic>hand object which can be subclassed for each new format.>The methods of the hand object might be something like load()>and print(). The load method will be specific to each site and>will convert the site format to some standard format defined>in the generic hand. The print method then prints to a standard>output format and only needs overriding for sites where you>need a different output format - which sounds to be rare from>your desciption.>The generic hand class then allows you to write the resty>of the application in a generic way without worrying about>site details apart from the
 point where you instantiate the>hands - and even that can be data driven via an external file>or environment variable etc..Well, I thought this would be the right approach to take given where I ultimately want to go with this. Im glad that I was thinking about this in the correct fashion. >Possibly but I would defer that decision for as long as possible!Hmm can you elaborate on this? (re: regular expressions) >You may need a pot class in the same way as the hand>above - but I'm not sure how that would workj since I don't>know anything about poker!Quickly on the format of the form of poker that I play most: No Limit Texas Hold'emEach player is dealt 2 cards face down. There are 2 forced bets called the Small Blind and Big Blind. Each player, starting to the left of the blinds can fold, call, or raise any amount. Once the action is complete, 3 cards are dealt face up(these are community cards,
 and are used in conjunction with the players' hole cards to make their best hand), and the betting action repeats itself, only now the Small Blind acts first. Another card is dealt face up if there 2 or more players left and the betting action occurs again. Once the action is complete then a final card is dealt and the action repeats. The remaining players then showdown their hands and the best 5 card hand wins. So a pot class would have to be able to extract the dollar amounts from each round of betting and then sum them after each betting round. This is important for talking about how hands play out, but I wont talk about why unless you are just interested. >It would be more helpful - to you and the rest of the>readership - if you keep it public. The kind of questions you>will be asking are likely to be the kind any newbie will come>across in a real project. By sharing the pain you also share>the experience. You also get access to
 many more heads.Thank you. I hoped to discuss it via the list but didnt want to spam the list unnecessarily. >Converting the Perl into Python shouldn't be too hard when>we get to the stage of needing to do that. For now let's start>with one site and get it working, while building in enough>flexibility for the future sites we know we need to deal with later.I just wanted to let you know that I had one in case anyone was interested in working version. Here is an interesting thing. All the converters that I know of are not stand alone apps. They are tied to forms on websites where people input their hands and then take the output to post on various popular internet poker web forums. I can provide links if anyone is interested. I wasnt necesarily wanting to convert the script, that feels a bit like cheating. >In fact maybe we should start at the end and work on the>internal data structure needed to print out the
 final format.>Can we define a program that can read the target format>in and print oit out in the desired format? It may sound trivial>but it gets a lot of the scaffolding in place early.I was very very happy to read this Alan. I was going to ask you in my original email if I should start with the output and work backwards. It actually gives me a lot of confidence that I seem to be thinking along the right lines here. I will start working on that and provide the list with my work on that. Thanks again Alan.Cheers, Chris
		Blab-away for as little as 1¢/min. Make  PC-to-Phone Calls using Yahoo! Messenger with Voice.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New programmer, need some help getting started on my first project

2006-05-17 Thread Chris Delgado
Kent, Thanks for the reply."I would pick one input format and work on a program that reads it and generates some kind of events for everything significant that happens. At first the events could be just print statements, later they can reformat the data to the required output format. From your description it sounds like there is no need to create an internal data format that holds all the data for a hand. A simple loop to read an event, parse the event and output it in the new format might be enough. It would help a lot to see some sample data.For a project of this (small) scale I don't do much design ahead of time, I let the design emerge from the code as I solve the problem. I would start by writing the simplest program that could possibly work to convert a single format. When that is working then look at what is needed to add a format. This will probably involve some refactoring,
 introducing functions or classes that are specific to your problems. When you have two or three formats working you should have a tool set that will make subsequent formats easier.If the data format is complex a parsing library like pyparsing might be helpful. But without seeing some data and trying to parse it there is no way to know."Here is a sample hand history. Failure To Launch 8161071-72989 Holdem No Limit $0.50/$1[May 17 03:26:33] : Hand Start.[May 17 03:26:33] : Seat 1 : bnb3 has $92.50[May 17 03:26:33] : Seat 2 : pineaa has $15.25[May 17 03:26:33] : Seat 3 : prowlerslim has $107.50[May 17 03:26:33] : Seat 4 : Marcelluz has $174.74[May 17 03:26:33] : Seat 5 : texredfsh has $35.25[May 17 03:26:33] : Seat 6 : aloo has $98.37[May 17 03:26:33] : aloo is the dealer.[May 17 03:26:34] : bnb3 posted small blind.[May 17 03:26:34] : pineaa posted big blind.[May 17 03:26:34] : Game
 [72989] started with 6 players.[May 17 03:26:34] : Dealing Hole Cards.[May 17 03:26:34] : Seat 3 : prowlerslim has Ah Kc[May 17 03:26:38] : prowlerslim called $1 and raised $4[May 17 03:26:41] : Marcelluz folded.[May 17 03:26:44] : texredfsh called $5[May 17 03:26:46] : aloo called $5[May 17 03:26:49] : bnb3 folded.[May 17 03:26:52] : pineaa folded.[May 17 03:26:53] : Dealing flop.[May 17 03:26:53] : Board cards [Kd Td 5d][May 17 03:27:01] : prowlerslim bet $10[May 17 03:27:04] : texredfsh called $10[May 17 03:27:06] : aloo folded.[May 17 03:27:07] : Dealing turn.[May 17 03:27:07] : Board cards [Kd Td 5d 3c][May 17 03:27:14] : prowlerslim bet $21[May 17 03:27:19] : texredfsh folded.[May 17 03:27:20] : prowlerslim wins $34.75 as the last player standing[May 17 03:27:22] : Hand is over.Im trying to work this out as we speak but not getting too far at the moment. I'll keep plugging
 along
		Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New programmer, need some help getting started on my first project

2006-05-17 Thread Chris Delgado
Kent,>OK, just looking at this, I'm guessing that you might want some kind of >data to represent the players, maybe something to represent the pot, >maybe something to represent the cards on the table. It really depends >on what kind of output you want to get from this. Can you post an >example of the desired output?Here is an example of the type of output I am looking for. First here is the hand history I used(slightly different then the othe format I showed you)* Hand History for Game 3736569968 *$100 NL Texas Hold'em - Monday, March 13, 22:21:11 ET 2006Table Table  97262 (No DP) (Real Money)Seat 4 is the buttonTotal number of players : 6Seat 2: xxxdoinkxxx ( $133.90 )Seat 3: zinc25 ( $57.08 )Seat 4: UltimateGW ( $143.50 )Seat 6: Dewez ( $101.85 )Seat 1: vulturesrow ( $115.75 )Seat 5: TableATM ( $69 )TableATM posts small blind [$0.50].Dewez is
 sitting out.vulturesrow posts big blind [$1].** Dealing down cards **Dealt to vulturesrow [  Kd Kc ]Dewez has left the table.xxxdoinkxxx calls [$1].zinc25 folds.UltimateGW folds.TableATM folds.vulturesrow raises [$3].xxxdoinkxxx calls [$3].** Dealing Flop ** [ 9d, 5c, 3h ]vulturesrow checks.xxxdoinkxxx checks.** Dealing Turn ** [ 5h ]>You have options at Clementson (No DP) Table!.vulturesrow bets [$6].xxxdoinkxxx calls [$6].** Dealing River ** [ 8s ]>You have options at Clementson (No DP) Table!.NL_DERB has joined the table.vulturesrow bets [$15].xxxdoinkxxx raises [$30].vulturesrow calls [$15].xxxdoinkxxx shows [ Qd, Kh ] a pair of fives.vulturesrow shows [ Kd, Kc ] two pairs, kings and fives.vulturesrow wins $78.50 from  the main pot  with two pairs, kings and fives.>You have options at Clementson (No DP) Table!.Then I ran
 through a converter located here: http://www.neildewhurst.com/hand-converter/Party PokerNo Limit Holdem Ring gameBlinds: $0.50/$16 players[url="">[b]Stack sizes:[/b]UTG: $133.90UTG+1: $57.08CO: $143.50Button: $69SB: $101.85Hero:  $115.75[b]Pre-flop:[/b] ([i]6 players[/i]) Hero is BB with K:diamond: K:club: UTG calls, [i]3 folds[/i], [color:#cc]Hero raises to $3[/color], UTG calls.[b]Flop:[/b] 9:diamond: 5:club: 3:heart: ([i]$6.5, 3 players[/i])Hero checks, UTG checks.[b]Turn:[/b] 5:heart: ([i]$6.5, 3 players[/i])[color:#cc]Hero bets $6[/color], UTG calls.[b]River:[/b] 8:spade: ([i]$18.5, 3 players[/i])[color:#cc]Hero bets $15[/color], [color:#cc]UTG raises to $30[/color], Hero calls.[b]Results:[/b]Final pot: $78.5[color:#ff]UTG shows  Qd Kh
 [/color][color:#ff]Hero shows  Kd Kc [/color]I wont lie, I found your "simple" example a bit mind blowing, maybe I need to work through some more tutorials lol. Still plugging away, thanks so much for helping this novice out. Cheers,Chris
		New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New programmer, need some help getting started on my first project

2006-05-18 Thread Chris Delgado
Kent, Thanks once again."I wonder if maybe you need to write some code? You talk about *reading* but you haven't mentioned *writing*. You can't learn to program without writing programs - that would be like learning to write a foreign language by reading books in the language - it helps but it won't get you there!So if you have just been reading, I suggest you try writing a few small programs as warmups."I think you are right on the money here. I need to write some more simple stuff. I did work through the books but I wrote very little on my own, just sort of followed along and said "Oh that makes sense". So I decided to go through the practice exercises in the book and then post here with any problems. SO here is my first stab and I keep getting a syntax error in my first if statement. The = sign is highlighted and I cant figure out what is wrong. Im almost embarassed to mail this. # A program that
 simulates flipping a coin 100 times and the reports the number of heads and tails that were flipped#import randomheads = 0tails = 0flips = 0if flips <= 100:coin = random.randrange(2)if coin = 0:heads +=elif coin = 1:tails +=flips +=1print "The coin was flipped 100 times and it was heads" + heads + "times and tails" + tails + "times!"raw_input("\n\nPress the Enter key to exit")THanks, Chris 
		New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New programmer, need some help getting started on my first project

2006-05-18 Thread Chris Delgado
Kent, Thanks once again."I wonder if maybe you need to write some code? You talk about *reading* but you haven't mentioned *writing*. You can't learn to program without writing programs - that would be like learning to write a foreign language by reading books in the language - it helps but it won't get you there!So if you have just been reading, I suggest you try writing a few small programs as warmups."I think you are right on the money here. I need to write some more simple stuff. I did work through the books but I wrote very little on my own, just sort of followed along and said "Oh that makes sense". So I decided to go through the practice exercises in the book and then post here with any problems. SO here is my first stab and I keep getting a syntax error in my first if statement. The = sign is highlighted and I cant figure out what is wrong. Im almost embarassed to mail this. # A program that
 simulates flipping a coin 100 times and the reports the number of heads and tails that were flipped#import randomheads = 0tails = 0flips = 0if flips <= 100:coin = random.randrange(2)if coin = 0:heads +=elif coin = 1:tails +=flips +=1print "The coin was flipped 100 times and it was heads" + heads + "times and tails" + tails + "times!"raw_input("\n\nPress the Enter key to exit")THanks, Chris 
		Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New programmer, need some help getting started on my first project

2006-05-18 Thread Chris Delgado
johnf, Yup, I actually thought that might be my mistake but I forgot to actually try it. So I did and revised the code (which I'll post below) and now get a syntax error after my heads += line..yikes .# A program that simulates flipping a coin 100 times and the reports the number of heads and tails that were flipped#import randomheads = 0tails = 0flips = 0if flips <= 100:    coin = random.randrange(2)    if coin == 0:    heads +=    else:    tails +=    flips += 1  print "The coin was flipped 100 times and it was heads" + heads + "times and tails" + tails + "times!"raw_input("\n\nPress the Enter key to exit")johnf <[EMAIL PROTECTED]> wrote: On Thursday 18 May 2006 16:19, Chris Delgado wrote:> import random>> heads = 0> tails = 0> flips = 0>> if flips <= 100:>>     coin = random.randrange(2)>>     if coin = 0:>         heads +=>     elif coin = 1:>         tails +=>>     flips +=1>> print "The coin was flipped 100 times and it was heads" + heads + "times> and tails" + tails + "times!">> raw_input("\n\nPress the Enter key to exit")I think you want '==' and not '='.  Look up assignment and equal!John___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
		Be a chatter box. Enjoy free PC-to-PC calls  with Yahoo! Messenger with Voice.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New programmer, need some help getting started on my first project

2006-05-18 Thread Chris Delgado
Bob et al, Ok guys, program is all fixed up and runs well. HEre is the final code. Thanks for the help and its on to the next prog.  Thanks for the patience and help!Chris# A program that simulates flipping a coin 100 times and the reports the number of heads and tails that were flipped#import randomheads = 0tails = 0flips = 0while flips < 100:    coin = random.randrange(2)    if coin == 0:    heads += 1    else:    tails += 1    flips += 1  print "The coin was flipped 100 times and it was heads " +str(heads)+ " times and tails " + str(tails) + " times!"raw_input("\n\nPress the Enter key to exit")
		Love cheap thrills? Enjoy PC-to-Phone  calls to 30+ countries for just 2¢/min with Yahoo! Messenger with Voice.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New programmer, need some help getting started on my first project

2006-05-18 Thread Chris Delgado
Bob, Thanks for the input. I was trying to stick to the lessons in the chapter whose problems I was working on and so I knew using a for loop might be a bit better, I decided to stick with the stuff from the chapter. I do like the way you simplified using the random function, very clever. I need to start thinking like that. Thanks again, I'll have more questions soon I'm sure!ChrisBob Gailer <[EMAIL PROTECTED]> wrote: Chris Delgado wrote:> Bob et al,>> Ok guys, program is all fixed up and runs well. HEre is the final > code. Thanks for the help and its on to the next prog.  Thanks for the > patience and help!>> Chris>> # A program that simulates flipping a coin 100 times and the reports > the number of heads and tails that were
 flipped#>> import random>> heads = 0> tails = 0> flips = 0>> while flips < 100:>> coin = random.randrange(2)>> if coin == 0:> heads += 1> else:> tails += 1>> flips += 1 >> print "The coin was flipped 100 times and it was heads " +str(heads)+ > " times and tails " + str(tails) + " times!">> raw_input("\n\nPress the Enter key to exit")Congrats! Now consider some "simplifications":import randomheads = 0for flips in range(1,101): heads += random.randrange(2)print "The coin was flipped %s times and it was heads %s times and tails %s times!" % (flips, heads, flips - heads)raw_input("\n\nPress the Enter key to exit")-- Bob Gailer510-978-4454
		Be a chatter box. Enjoy free PC-to-PC calls  with Yahoo! Messenger with Voice.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New programmer, need some help getting started on my first project

2006-05-19 Thread Chris Delgado
   Terry, Thank you for the suggestions. I am going to stick with these little toy programs as you aptly put them to make sure I have a good grasp on the basics. I completely agree with you that I need to do something that I want to solve a problem with and in fact, thats whats motivated me to find and join this list. Unfortunately, it woudl appear I attempted to bit off more than I could chew. Part of the problem with writing to solve things is that there is just about something for everything out there right now!  I did recently convert my old laptop over to Linux so hopefully as I mess around with that I will find some things that I can focus my attentions on. Thanks for taking the time to respond. Cheers, ChrisTerry Carroll <[EMAIL PROTECTED]> wrote: On Thu, 18 May 2006, Chris Delgado
 wrote:> Kent, > > So if you have just been reading, I suggest you try writing a few small > programs as warmups."> > I think you are right on the money here. I need to write some more> simple stuff. Chris, I'd also suggest that, once you have a few toy programs (like your coin-tosser) under your belt, you find some *small* task that you actually want to accomplish, and use Python for that.It's both motivating and satisfying to address some real-life need you have, rather than some arbitrary assignment from a book.I think my very first Python program was to do something like take a comma-separated list of MP3 files, with the directory name in a form that includes artist name and album or collection, and format it as a hierarchical list, because I wanted to see it that way.It was more fun to work on a program that actually did something I wanted, and I had a
 purpose in writing it beyond just learning Python.(Of course, I look back at that code now, and it sure is ugly; but it worked!)___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
		Be a chatter box. Enjoy free PC-to-PC calls  with Yahoo! Messenger with Voice.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor