Poker pro Phil Ivey in 2009. (AP)

Imagine you go to a casino to play blackjack. You find a table, sit down and buy some chips. Gambling has few barriers to entry.

After awhile, you notice: For some reason, all of the cards higher than 9 are marked. Because of some slight imperfection in the deck, you can tell whether a card is an ace, king, queen, jack or ten before it’s turned over. Because of a manufacturer’s mistake, you have a huge advantage over the house. And the dealer doesn’t notice.

You decide to stay at the table. You win $12.4 million dollars. But later, the casino figures out how you won, says you cheated and refuses to pay. So you sue.

So: What’s a judge to do? Were your gains ill-gotten — or is it the casino’s responsibility to watch its own back?

A different version of this question was put before a British court after American poker pro Phil Ivey sued a London casino. In 2012, Ivey was accused of cheating at Punto Banco, a form of baccarat, by Crockfords, which withheld Ivey’s $12.4 million winnings.

And on Wednesday, Her Majesty’s High Court of Justice decided Ivey had done wrong — and won’t get paid.

“He gave himself an advantage which the game precludes,” Judge John Mitting said, as Bloomberg reported. “This is in my view cheating.” 

Ivey was disappointed.

“I was upset as I had played an honest game and won fairly,” Ivey said in a statement, as the Guardian reported. “I believe that what we did was a legitimate strategy and we did nothing more than exploit Crockfords’ failures to take proper steps to protect themselves against a player of my ability.”

Ivey’s admitted strategy — what’s called “edge-sorting” — was quite involved. Here’s poker scribe Jim McManus’s excellent description of the angle, which he wrote for Bloomberg. Headline: “Judge Says Poker Champ Robbed the Casino.”

Working with a partner, Cheung Yin Sun, Ivey was able, by observing tiny asymmetrical flaws along the edge of the backs of some decks, to read the value of the bottom card of the shoe just before it was dealt.

Pretending to be superstitious, Ivey and Sun persuaded Crockfords to grant them a series of unusual requests. They wanted a specific Chinese woman to be their croupier/dealer. Speaking to her in Mandarin, a language the pit bosses did not understand, Sun asked for all the nines, eights, sevens and sixes — the most favorable cards for the player — to be rotated 180 degrees inside the deck. Sun, who goes by Kelly and is known among high-stakes advantage players as “the Queen of Sorts,” also asked the dealer not to manually mix up the cards before replacing them into the automatic shuffling machine. The sixes through nines would thus remain easy for Ivey and Sun to identify as they re-appeared at the end of the shoe. Ivey then would increase his bet from a few thousand pounds to as much as 150,000 pounds.

Ivey even specified what brand of cards Crockfords should use — but he and his partner never touched them.

“Mr. Ivey had gained himself an advantage and did so by using a croupier as his innocent agent or tool,” Mitting said. “It was not simply taking advantage of error on her part or an anomaly practiced by the casino, for which he was not responsible.”

After letting Ivey play the game his way and losing millions, the casino got a do-over.

“Crockfords is pleased with the judgment of the high court today,” a spokesman said. “We very much regret that proceedings were brought against us. We attach the greatest importance to our exemplary reputation for fair, honest and professional conduct and today’s ruling vindicates the steps we have taken in this matter.”

In interviews ahead of the decision, Ivey made clear he considered the casino’s accusations an assault on his character.

“Once you get ‘cheater’ next to your name — especially in my business, which is the business of gambling — it’s really bad,” he told “60 Minutes Sports.” “Some people believe it was cheating. I know it wasn’t.”

An expert witness who testified on Ivey’s behalf told The Washington Post the gambler was allowed to control the way the game was played because he is a high roller.

“High rollers are a precious commodity in the casino industry, and so they are ceded any number of special requests to get their business,” said Eliot Jacobson, a self-described “advantage-play expert” and a former professor at the University of California at Santa Barbara who taught computer science. “It’s competition for scarce resources.”

Jacobson, whose clients include casinos, strongly disagreed with the outcome.

The judge “said going forward in the future a casino in the U.K. can be ignorant and should a player come in and win money off them using a new method, the casino doesn’t have to be accountable for their ignorance at all,” Jacobson said. “That to me seems an absurdity.”

The poker world took umbrage. Few object when this 38-year-old man with 10 World Series of Poker Bracelets — a New Jersey native whose grandfather taught him how to play cards — calls himself the “Tiger Woods of poker.” In the poker boom of the 2000s, Ivey was one of the game’s young, fresh-faced missionaries, a regular on cable television and unavoidable on poker Web sites. Even the judge was impressed, calling Ivey “an honest witness,” according to Bloomberg.

But in London, he went all-in, and the house won the pot.

“Professional poker players know that any bet contains risks they need to guard against, and they know there’s no recourse if they lose,” poker pro Matt Matros, who’s written about gambling for The Washington Post, wrote in an e-mail. “It should be no different for the house. A casino’s own incompetence doesn’t absolve them from having to pay out winnings.”

This isn’t Ivey’s last hand. He ran a similar angle against the Borgata in Atlantic City in 2012. The casino paid him — but now wants its $9 million back and filed suit earlier this year.

“Because of his notoriety as a high-stakes gambler, and the amount of money he intended to gamble, Ivey was able to negotiate special arrangements to play baccarat at Borgata,” the complaint states, as reported by Poker News.Ivey’s true motive, intention, and purpose in negotiating these playing arrangements was to create a situation in which he could surreptitiously manipulate what he knew to be a defect in the playing cards in order to gain an unfair advantage over Borgata.”

Jacobson thought the Borgata lawsuit misguided.

“I’m absolutely convinced that the method used by Ivey is fair play,” he said. “I consider that lawsuit is just not reasonable based on the facts as I know them.”

Here’s Ivey’s recent “60 Minutes Sports” interview: