Daily fantasy-sports fanatic Charles Badalamenti made a play last spring he figured had long odds for success: He wrote to his local reps in Albany.

The 38-year-old real-estate broker from Astoria, Queens, was mad that the state was moving to take away his favorite pastime.

In 2015, Badalamenti turned $5 into $15,000 playing daily fantasy sports when he picked Mets pitcher Noah Syndergaard during a FanDuel game. Then, last November, he pocketed $600 in one weekend on DraftKings, a rival fantasy-sports site, playing football.

But in early June, instead of probing stats and athletes to build winning fantasy teams, Badalamenti found himself on a site called “Fantasy Sports For All,” which urged fantasy sports fanatics to write their New York lawmakers to save FanDuel and DraftKings from going out of business.

“I’ll be completely honest with you — never,” Badalamenti told The Post, when asked whether he’d ever taken an interest in government before. But FanDuel and DraftKings were “very proactive” in directing him to FantasySportsForAll.com, he said, as they started to piece together a battle plan to beat Schneiderman.

Eric SchneidermanPhoto: Gabriella Bass

The two companies had blitzed NFL broadcasts, TV networks, web sites and cable news shows with more than $500 million in TV and radio ads. But on March 21, with less than a month to go in the NBA season, they were stopped dead in their tracks.

With the crucial market of New York off the table, there was doubt whether either company could survive.

Now, as the NFL season moves into week 7, the two companies appear to be stepping lightly, spending about 10 percent of what they did on TV ads last year, according to an estimate by Legal Sports Report.

They appear damaged — but still very much alive and are still able to raise cash. This is the inside story of how the daily fantasy sports industry quickly outworked and outfoxed Schneiderman, allowing the popular game to return.

The man at the center of strategy is Bradley Tusk, a high-power political Mr. Fix-It.

A 42-year-old veteran of many back-room battles, Tusk is perhaps best known for leading Big Apple Mayor Michael Bloomberg’s controversial — and successful — bid for a third term in 2009.

Tusk is currently leading a new campaign — to find a candidate willing to run against the current mayor, Bill de Blasio, in 2017.

It was Tusk’s master plan — a mix of tech-savvy guerrilla campaigning and good old fashioned celebrity hand-shaking that produced more than 100,000 emails and 5,000 phone calls into the state capital and eventually won over crusty lawmakers.

“You go to your average state senator and say, ‘Look, there’s 2,000 people in your district who don’t know you are, but they really love fantasy sports — and if you take it away from them, we’re going to make sure they know who you are,” Tusk told The Post, paraphrasing his hard-knuckle pitch to legislators. “And then they might start to vote.”

Lawmakers should have known they were likely to get steam rolled.

Tusk’s grass roots, scorched-earth methods were on display last summer when he coordinated Uber’s smackdown of de Blasio’s bid to curb the size of its ride-hailing network in New York City.

Bradley TuskPhoto: Getty Images

In that battle, City Hall officials and city council members were barraged with more than 100,000 emails and tweets from concerned Uber customers — many of whom were sparked into political activism through prompts that popped up on their Uber apps.

Tusk, a true believer that tech will play a major role in future political action jobs, has recently started Tusk Ventures, a year-old fund that invests in tech startups whose potentially game-changing business models face political and regulatory hurdles.

In addition to Uber and FanDuel, Tusk’s client-investments include Lemonade, a peer-to-peer insurance provider, Ripple, a blockchain-based settlement system for banks, and Handy, a freelance network for home cleaners and handymen.

On Dec. 2, as Schneiderman began to signal that he would make life difficult for daily fantasy sports players, Tusk sat down with FanDuel brass and outlined a strategy. A seven-page advised the executives that they had untapped powers — that their combined 5 million customers was equal to the membership of the National Rifle Association.

Focused on politically activating fantasy sports players, the memo promised that the two companies could short-circuit any legal roadblocks by letting the players known who was trying to take away their favorites games — a process that could complicate Schneiderman’s rumored aspirations to run for governor in 2018.

The AG — who had first attacked DraftKings and FanDuel in November 2015, sending the companies a cease-and-desist letter before filing his January lawsuit — had also taken “so much campaign money from so many casinos,” according to the memo.

“It’s probably a long-shot bid to begin with,” Tusk wrote of a prospective Schneiderman gubernatorial bid, and “having every fantasy sports customer in New York ready and willing to vote against him does not help his cause.”

In March, Tusk scored his first important win, helping engineer an agreement where FanDuel and DraftKings would stop running games in New York in exchange for a freeze on Schneiderman’s challenge to daily fantasy sports on gambling grounds.

The deal was crucial. A state appeals court was sitting on a decision — after the AG had won in a lower court — and a pro-Schneiderman appellate win could have stopped Tusk’s efforts.

The New York Liberty are sponsored by DraftKings.Photo: Getty Images

“The future was pretty clear,” says Evan Stavisky of Parkside Group, which led the New York lobbying effort for FanDuel. “Unless we dealt with the litigation from the AG’s office, the end of the legislative session was going to potentially be the end of the companies.”

With the agreement temporarily halting the legal challenge, Tusk turned his attention to winning over lawmakers.

Three things crystallized for Tusk, showing he had a good chance of winning.

First, fantasy sports fans were being to hound lawmakers in huge numbers. A bill had been introduced to allow fantasy sports, albeit with regulation.

Second, Tusk greenlighted a fantasy sports-backed poll that showed — surprise! — that 60 percent of New Yorkers favored the activity. The fantasy sports-friendly poll would serve to neutralize a Siena College poll, released a week earlier, that found 45 percent of Empire State residents actually opposed to the practice, versus just 37 percent in favor.

Not everyone was thrilled by the positive spin of the fantasy sports industry poll.

Three things crystallized for Tusk, showing he had a good chance of winning.

“Gambling has real social costs and we’re likely to see greater problems because of this legislation,” said state Sen. Liz Krueger, who voted against the bill. “We’re never asking the right questions about how much of people’s disposable income is going down these rabbit holes of gambling.”

The third event that showed lawmakers may pass the bill is that so many of them love football.

As the Assembly and Senate bills made their way to a floor vote, Tusk served up his coup de grace. He shelled out $100,000 to bring NFL Hall of Famer and former Buffalo Bills star Jim Kelly and ex-Jets quarterback Vinny Testaverde to sleepy Albany.

To say that Kelly and Testaverde wowed the lawmakers would be an understatement. They drew a crowd and could have drained a few pens signing autographs.

As the duo left the legislative building on June 14 — less than three days before the final vote on the fantasy sports bill — some lobbyists groused, not entirely in jest, that the autographs Kelly and Testaverde were signing for lawmakers amounted to campaign contributions.

Tusk’s winning drive to overturn the ban on daily fantasy sports wasn’t without its missteps. One was particularly comical.