In July 2012, Phil Ivey walked into the Borgata Hotel Casino & Spa in Atlantic City, N. J. Over the next 17 hours, he would become nearly $4.8 million richer. A gambler by profession, Ivey billed himself as the “Tiger Woods” of poker; he had won more than $6 million from several tours on the World Series of Poker and another $19 million through years of online poker. But Ivey was not playing poker on that day in July. His winning spree came from baccarat — a game of chance associated with high rollers and would-be James Bonds.

This was not Ivey’s first impressive baccarat run. He visited the Borgata to play baccarat three other times, too, between April and October 2012. His total winnings from those visits amounted to more than $9.6 million, according to court documents.

Baccarat, as it is played in most U.S. casinos, rewards luck, not skill. Ivey did not have $9.6 million worth of luck.

Borgata sued Ivey, alleging that the gambler had defrauded the casino. But his winning scheme, once revealed, was not exactly cheating, not in the eyes of a district court judge. Ivey did not commit fraud, Judge Noel Hillman for the U.S. District of New Jersey wrote in an opinion on Monday.

To those who have never burned money at a baccarat table, its rules may seem arcane. At its core, though, baccarat is a game of random chance, with roots possibly as far back in history as the ancient Chinese tile game pai gow, or “make nine.” In short: A croupier deals himself or herself a pair of cards, and another pair of cards to a player. The cards in hand are added together — face cards and tens are worth zero, while aces have a value of one — with the twist that only the last digit of the sum matters. A hand of an eight and a six, for example, would be worth four points. Unlike blackjack, a player cannot ask for a third card. An additional card is automatically dealt to a hand of five or fewer points. There are a few ways to bet, though whoever gets closest to a value of nine, the highest possible score, usually wins.

Its simplicity caught on among the tuxedo and cocktail dress crowd — Frank Sinatra was captured on camera dealing a hand at the Sands Hotel in 1959 — and the game flourished across U.S. casinos in the 1950s and 1960s. (Baccarat received the silver screen treatment when Sean Connery debuted as James Bond in 1962’s “Dr. No;” Bond was shown playing a baccarat relative called chemin de fer, in which players bet against each other instead of the house.) It remained popular, especially among wealthy Chinese gamblers. Baccarat was the highest-grossing casino game in the world, as Bloomberg reported in 2012. In 2014, baccarat games generated 91 percent of casino income in gambling mecca Macau.

Huge sums could change hands over a game of baccarat. The Las Vegas Sun reported that, in 1990, Japanese high roller Akio Kashiwagi waged an “epic baccarat battle” with Donald Trump at one Atlantic City table. The gambler risked $12 million in a bid to double it. During the course of the games, Kashiwagi managed to get halfway to his goal before the Trump casino won $9 million from him.

Given the opportunity to make massive amounts of money, casinos can be unusually accommodating to wealthy baccarat players. Ivey was able to use this to his advantage. In each of his visits to the Borgata, the casino accepted the same five requests. Ivey asked: that he play in a private area; that the dealer speak Mandarin Chinese; that he play with eight decks of purple Gemaco Borgata playing cards shuffled together; that the decks be shuffled with an automatic shuffler; and that Ivey would be allowed one guest at the table, a woman named Cheng Yin Sun.

Sun had spent, according to the New York Times magazine, hundreds of hours memorizing tiny flaws in purple Gemaco Borgata playing cards. (Card manufacturer Gemaco, listed in the lawsuit, did not respond to a request for comment from The Washington Post early Tuesday.) As she told the magazine in June, her motivation was not out of overwhelming loss — Sun claimed to have blown $20 million inherited from her father — but from time spent in jail for failing to repay a debt to MGM casino.

“Women attacked me, and the guards wouldn’t let me wear my own underwear,” she said to the Times in June. “I lost 25 pounds in jail and didn’t get out until a relative flew here with $100,000 for the casino. I decided that one day I would get back the money by playing at MGM properties.”

She purchased souvenir playing cards from the Borgata, identical to the ones used on the casino floor save for holes punched in the center. She discovered that patterns on card backs, designed to be symmetrical, were not perfectly so. Sun trained herself to identify aberrations along the left or right margins of the card backs, no wider than 1/32 of an inch, the Times reported. (“Sun’s mental acumen in distinguishing the minute differences in the patterns on the back of the playing cards is remarkable,” Hillman noted.) So prepared, she helped Ivey on his way to millions.

The technique Ivey and Sun used was called edge-sorting. Sun was allowed to peek at the card before the dealer flipped it over. In Mandarin, she would ask the dealer to rotate the most valuable cards in the baccarat deck — the sixes through nines — 180 degrees as they were flipped. The automatic shuffler could randomize the cards, but would not alter their rotation.

“Baccarat is a casino game well known for unique and superstitious rituals,” Hillman noted in an October opinion. “Thus, Sun telling the dealer to turn a card in a certain way did not raise any red flags for Borgata.”

With the deck sorted, it was possible for Sun to identify which cards had been rotated. The pair therefore knew the values of the cards while they were being dealt, before completing bets. Ivey adjusted his bets, and once the pair edge-sorted the entire deck, he increased his bids to the maximum allowed.

“The defendants not only shifted the odds to their favor, it is undisputed they won and won big,” Hillman wrote in his December opinion awarding Borgata the $10 million.

It wasn’t fraud, however, because they did not break the rules of baccarat, he determined. Those rules “do not prohibit a player from manipulating the cards.” Nor were they obligated, as the casino claimed, to explain why they wanted the dealer to behave in a certain way.

Instead, the judge ruled Ivey and a partner did break the rules of New Jersey’s Casino Control Act and thus “breached their contract with Borgata.” In December, the judge ordered the pair to return $10.1 million to Borgata, reflecting the baccarat cash as well as $500,000 won using some of the winnings at craps.

“By using cards they caused to be maneuvered in order to identify their value only to them,” the judge wrote, “Ivey and Sun adjusted the odds of Baccarat in their favor. This is in complete contravention of the fundamental purpose of legalized gambling as set forth by [New Jersey’s Casino Control Commission.] Ivey and Sun’s violation . . . constitutes a breach of their mutual obligation with Borgata to play by the rules” of the state’s law.

As The Washington Post reported in 2014, Ivey and Sun relied on the same method in a London casino. The casino refused to pay the pair, and a British judge declared that edge-sorting was cheating. (It was the London casino’s decision to withhold Ivey’s winnings that tipped off Borgata in October 2o12.)

Ivey’s attorney Ed Jacobs emphasized that Hillman did not describe the poker player’s actions as fraud. “What this ruling says is a player is prohibited from combining his skill and intellect and visual acuity to beat the casino at its own game,” the lawyer said, according to the Associated Press. “The casino agreed to every single accommodation requested by Phil Ivey in his four visits because they were eager to try to win his money.” The gambler was only using observation, the defense went, and rotating the cards was within the rules of the game. Jacobs added Ivey will appeal the ruling.

As for the $250,000 worth of comped goods and services that Borgata gave to Ivey and Sun, Hillman concluded that they did not owe the casino restitution. “Because the ‘comps’ were not tied to an obligation that Ivey win or lose, or do anything in particular except to visit Borgata,” he wrote, “Borgata is not entitled to the return of the value of those ‘comps’ as part of its breach of contract damages.”

Ben GuarinoBen Guarino is a reporter for The Washington Post’s Science section. Before joining The Post in 2016, he worked as a freelance science journalist, an associate editor at the Dodo and a medical reporter at the McMahon Group. He also has a background in bioengineering. Follow

Content from Allstate This content is paid for by an advertiser and published by WP BrandStudio. The Washington Post newsroom was not involved in the creation of this content. Learn more about WP BrandStudio.