-- Like many other high-stakes gamblers, Phil Ivey had his quirks and was accommodated because of the large sums of money he would plunk down at casinos.
On the surface, it appeared that his superstitions paid off, lady luck paid him a visit often.
But a civil complaint from Borgata alleges his good fortune was nothing more than an elaborate card trick -- a complex scheme involving secret commands in Chinese and "edge sorting" cards to gain the upper hand on the house.
The complaint lays out in breathtaking detail the way Ivey and his alleged accomplice, Cheng Yin Sun allegedly hoodwinked the casino over the course of several trips there using a card-marking technique that leaves no trace.
The technique allegedly exploited the asymmetry of the pattern on the back of the cards so that the players would know if the first card dealt in each game was important, increasing their chances from a 1 percent house advantage to an almost 7 percent advantage in their favor.
In the wake of the alleged scheme, New Jersey federal Judge Noah Hillman ruled in favor of Borgata, saying the casino is entitled to more than $10 million after Ivey purportedly won that amount playing baccarat and craps there.
According to the complaint, filed in 2014, on several occasions, Ivey and Sun "played Baccarat with cards that had been manipulated and 'marked' so that their value was identifiable to Ivey and Sun before bets had to be placed and before the cards were dealt."
"Because of Ivey and Sun’s misconduct, unfair play and the use of their influence as 'high rollers' to deceive Borgata, Ivey and Sun succeeded in manipulating the Baccarat game to deprive the game of its essential element of chance," the complaint alleges.
To do this, "Sun would identify minute asymmetries on the repeating diamond pattern on the backs of the playing cards to identify certain cards' values, and would have the dealer turn those strategically important cards so that they could be distinguished from all other cards in the deck," Hillman wrote in his opinion.
"Ivey and Sun would then be able to see the leading edge of the first card in the shoe before it was dealt, giving them 'first card knowledge,' and Ivey would bet accordingly."
Ivey and Sun allegedly requested several accommodations from the casino "to make the edge sorting scheme work" including a private area in which to play, a dealer who spoke Mandarin Chinese, as well as "(3) a guest (defendant Sun) to sit with him at the table while he played; (4) one 8-deck shoe of purple Gemaco Borgata playing cards to be used for the entirety of each session of play; and (5) an automatic card shuffling device to be used to shuffle the cards after each shoe was dealt, which retained the orientation of each card that Sun requested to be turned," Hillman wrote.
According to the complaint, Ivey first contacted Borgata in April 2012 about visiting to play baccarat, and "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."
At Ivey's request -- under the pretext he was superstitious -- he was granted the accommodations he requested, the complaint said.
Ivey first played in April 2012, accompanied by Sun. The complaint said Sun spoke to the dealer in Mandarin Chinese and alleged "Sun gave instructions to the dealer on how to flip over and lay the cards out on the table."
"It is not uncommon for Baccarat players to make special requests for how the cards are dealt based on individual superstitions," the complaint said, adding, "Borgata accommodated Sun’s request for how cards were to be dealt."
"At no time did Sun or Ivey disclose the true purpose behind Sun’s request for how the cards were to be dealt."
Ivey purportedly won $2,416,000 on the April trip, the complaint said.
In May 2012, Ivey made a second trip to the casino and "requested the same arrangements as his first trip," the complaint said, and, "Sun again spoke to the dealer in Mandarin Chinese, giving him instructions on how to turn the cards as they were dealt."
During the May 2012 trip Ivey purportedly won $1,597,400, the complaint said.
In July 2012, Ivey made a third trip to the casino with the same arrangements and again played with Sun at the table, the complaint said. During the July 2012 trip, Ivey purportedly won $4,787,700.
In October 2012, Ivey made a fourth trip to Borgata to play Baccarat with "the same arrangements," the complaint said. He arrived at Borgata around Oct. 5, 2012, but didn't play baccarat until after Sun arrived the next day.
This trip, he purportedly won $824,900, according to the complaint, which alleged "Ivey intentionally lost a portion of his winnings."
According to the complaint, edge sorting exploits "manufacturing defects" in the cards where the pattern on one of the long edges is slightly different than on the other. The dealer could then flip the card so that it was clear, the next time the card was used, if it was important or not.
"It is not uncommon for Baccarat players to make special requests for how the cards are dealt based on individual superstitions," the complaint says.
"The dealer would first lift the card so that Sun could see its value before it was flipped over all the way and placed on the table," the complaint said.
Sun would then either tell the dealer the Mandarin word for "good card," or "bad card," the complaint said. "By telling the dealer 'good card' or 'bad card' in Mandarin, the dealer would place the cards on the table so that when the cards were cleared and put in the used card holder, the leading edges of the strategically important cards could be distinguished from the leading edges of the other cards in the deck," according to the complaint.
The complaint said Ivey and Sun also requested an automatic card shuffler to keep the edges of the cards facing the same direction.
"Once the 'edge sorting' was completed, Ivey and Sun were able to see the leading edge of the first card in the shoe before it was dealt, giving them 'first card knowledge,'" the complaint said.
In October 2016, the court ruled that Ivey and Sun breached their contract "when they knowingly engaged in a scheme to create a set of marked cards and then used those marked cards to place bets based on the markings," Hillman wrote in his opinion. On Dec. 15, Hillman ordered that Ivey and Sun return the $9,626,000 Ivey won from Baccarat and the $504,000 he won from Craps after Baccarat.
Ivey's attorney, Ed Jacobs, told ABC News that the judge found that Ivey "committed absolutely no fraud and followed every single rule of the game of Baccarat. Nonetheless, the judge disapproved of his gambling technique."
"This was simply a skilled patron of the casino combining his intellect, his visual acuity and his skills to beat the casino at his own game," Jacobs said.
"He did absolutely nothing wrong, he never touched the cards," Jacobs said, adding that it's "therefore impossible that he could have marked the cards. ... He was simply able to out-think and out-strategize the casino."
Jacobs said they are appealing.
"This case is not over," he said. "That's round one, we will be back."
The Borgata did not immediately provide a response to ABC News' request for comment.
Editor’s note: This story was amended after publication to clarify that the court documents cited were part of a civil complaint filed by Borgata Hotel Casino & Spa.