0:02

And here's the flop.

Â Those two spade's impossible inside straight draw

Â really helped Genevieve with no help for Drew.

Â Her odd wnet 32 percent to 55 percent.

Â Drew has bet, Genevieve called.

Â Here's the turn. The king of spades.

Â Drew now has three kings,

Â and Genevieve has a straight.

Â Drew needs a king, jack, nine,

Â or a red 10, giving him only a 21 percent chance here.

Â Hit me. What was that for?

Â The peanut butter and jelly video.

Â And besides, this is poker, not blackjack.

Â Are you betting or checking?

Â I really wish I could see those probabilities

Â that they put over there in the corner of the screen.

Â Well, that would take all the fun out of the game, wouldn't it?

Â Yeah, probably. But, hey,

Â you know what would make a great project for our Coursera learners?

Â It better not be teaching you to play poker.

Â No, no, no. They could write a program that reads in a description of the poker hands,

Â and does a Monte Carlo Simulation to determine the odds of each hand winning.

Â Genevieve and I are playing poker.

Â And you all can see the odds of each of us winning the hand,

Â based on what cards we each have.

Â How does this get calculated?

Â When there is only one unknown card,

Â you could pretty reasonably work it out by hand.

Â But if there were many unknown cards,

Â it could get complicated quickly.

Â Wouldn't it be great to write a program that could figure this out for us?

Â That's what you are going to do,

Â with part of the project at the end of each course.

Â To do this, we'll need to describe

Â the hands in a way that is easy for the computer to work with.

Â Here is the poker table from my perspective.

Â In this variant of poker,

Â which is called Texas Hold'Em,

Â these seven cards are my hand.

Â If you don't know how to play poker, that's okay.

Â We'll explain the rules you need to implement this program.

Â When all the cards are played,

Â I'll pick the best five of my seven cards,

Â and say what poker hand they make.

Â At the moment, I have three kings.

Â We can represent this in a way that is easy to

Â work with by describing each card with two letters.

Â One for the rank, and one for the suit.

Â Here, I've described my two pocket cards,

Â the ones that are just mine with Kh for the King of Hearts,

Â and Kc for the king of clubs.

Â I've described the known common cards similarly.

Â The first three are called the flop,

Â and the fourth one is called the turn.

Â The fifth card which is called the river is unknown.

Â So I've represented it with a question mark and a number. In this case, two.

Â Everywhere that question mark two appears in this hand description,

Â will be the same card which will be

Â different from question mark zero and question mark one.

Â Genevieve's hand is made up of these seven cards.

Â Her two pocket cards,

Â and the five common cards in the middle.

Â Since I don't know what her pocket cards are,

Â I represented them with question mark zero and one.

Â She also has the same description of the flop and turn,

Â since we share those,

Â and also has question marks two for

Â the river since we will share that card once it is dealt.

Â You'll learn how to read input from files as well as how to dynamically allocate

Â the memory to hold any number of hands that your program is working with in course four.

Â Until then, we'll provide some compiled object files that will read the input for you.

Â We can use this idea to describe other situations.

Â Here are our hands before the flop is dealt.

Â I know my two pocket cards, but no others.

Â Question mark two through six represent the common cards which are as yet unknown,

Â but will be the same in both hands.

Â However, for the spectators and announcers,

Â all the pocket cards are known.

Â Having more information gives you

Â a different calculation of the probabilities of the hands.

Â Genevieve's hand is actually really good,

Â so her odds of winning are better given what her hand actually is,

Â than if we assume it is a random hand.

Â Our input representation is flexible enough

Â that we can represent many other common poker variations.

Â For example, seven card stud has no shared cards,

Â and some that are dealt face down,

Â and some dealt face up.

Â So that's how we'll describe the situation in a poker hand.

Â But how will you actually go about calculating the odds?

Â You could make your program consider every possible combination of cards.

Â If you have four known cards and five unknown cards,

Â as would be the case if we can see two players' hands,

Â and have five cards yet to deal,

Â you end up with about 205 million combinations.

Â That's not so bad as computers go.

Â We could do it in a matter of minutes,

Â but we'd like to be faster than that.

Â Could we work out the formulas for every case based on

Â the principles of probability and combinatorics?

Â Maybe, but that would be a lot of work especially given how many cases there are,

Â and how much these depend on what other cards each other player has.

Â Instead, what we are going to do is a Monte Carlo Simulation.

Â So what is a Monte Carlo Simulation?

Â You will draw a large number of random hands for the unknown cards,

Â and see who wins,

Â and count up how many times each of players wins the hand,

Â and use those numbers as estimates for the probability of each player winning.

Â If you do this for a large enough number of random draws,

Â your answer will be very accurate.

Â 100,000 random draws is pretty fast,

Â and give estimates that are quite good.

Â The idea of Monte Carlo Simulation is not just limited to poker or card games,

Â but is a broadly applicable technique whenever determining

Â the exact answer is incredibly complicated or computationally difficult.

Â Let's head back to our poker game and see how it finishes.

Â And here's the river, 10 of spades.

Â Wow. Genevieve drew the straight flush.

Â But Drew probably thinks his hand is good with a full house.

Â All in.

Â Call.

Â Full house.

Â Straight flush.

Â And Genevieve wins the $25 million pot.

Â What a game?

Â Did I say a million? I meant 25.

Â