– The soldiers were about to storm the fortress when they went still. James Smith, 17, and teacher Shirley Coulter squinted at the monitor.

Smith was programming his own military game, the final project in his Advanced Placement computer science principles class at Sheridan High School in the foothills of the Bighorn Mountains. But the game had crashed, and neither Smith nor Coulter — a 19-year veteran whose background is in teaching business classes — could figure out how to debug it.

“I’m learning with the kids,” she said. “They grasp it faster than I do.”

Coulter is one of hundreds of teachers in this sparsely populated state tasked with carrying out one of the most ambitious curriculum reform laws in the nation. Dozens of states have taken steps to expand students’ access to computer science, but last year, Wyoming became one of the few to require that all K-12 public schools offer it.

The mandate is part of a wide-ranging package of new laws intended to wean Wyoming off its reliance on the oil, gas and coal industries, and stem the flow of young people leaving for better jobs.

Full of coal mines, vast cattle ranches and snow-capped peaks, Wyoming is perhaps an unlikely leader in a drive to bring coding into the classroom. Computer programming and software development account for fewer than two jobs per 1,000 here, compared with 19 per 1,000 in Washington state, according to the Bureau of Labor Statistics. But with half of Wyoming’s revenue coming from the boom-and-bust cycles of the energy sector state leaders are looking to branch out.

Now Wyoming’s 48 school districts have until the 2022-23 school year to begin teaching computer science at every grade level. The mandate will not be easy to pull off. U.S. schools have long struggled to define computer science. And low taxes are an orthodoxy in Wyoming, and the Legislature did not dedicate any new dollars to the plan. That has left schools reliant on limited state, federal and philanthropic funds — and on individual educators, like Coulter — to bear the burden of introducing an entirely new subject.

Coulter had three weeks of training in basic programming from a group called Project Lead the Way, which is backed by companies like Chevron, Toyota and Lockheed Martin. She also partnered with Anne Gunn, a computer science instructor at a local community college who visited her AP computer science course three days a week.

The school district in Sheridan, a city of 18,000 residents, was lucky enough to land a $1.8 million grant from a local foundation, Whitney Benefits, to help introduce computer science.

In districts with less philanthropic support, school leaders are still debating what to do about the mandate. Some plan to use video conferencing to get students help from experts far away.

George Mirich, superintendent in Niobrara County, said some students had built and programmed drones to monitor cattle. But work like this has generally been limited to club activities and electives, he said. Mirich said that he had reassigned a staff member to elementary school computer science, and that he expected much of the new programming curriculum to be folded into traditional subjects like math.

The major corporate backer of the Wyoming plan is Microsoft. Kate Behncken, vice president of Microsoft Philanthropies, had sweeping visions for the company’s nationwide push on computer science education, from closing skills gaps to soothing national political tensions.

The 2016 presidential election showed “it was clear there were people across the U.S. who feel like they don’t have the same opportunities as people in the major metros,” Behncken said. “We have a responsibility to help address these issues.”