Prisons can restrict the rights of inmates to nerd out, a federal appeals court has found.

In an opinion issued on Monday , a three-judge panel of the United States Court of Appeals for the Seventh Circuit rejected the claims in a lawsuit challenging a ban on the game Dungeons & Dragons by the Waupun Correctional Institution in Wisconsin.

The suit was brought by a prisoner, Kevin T. Singer, who argued that his First Amendment and 14th Amendment rights were violated by the prison’s decision to ban the game and confiscate his books and other materials, including a 96-page handwritten manuscript he had created for the game.

Mr. Singer, “a D&D enthusiast since childhood,” according to the court’s opinion, was sentenced to life in prison in 2002 for bludgeoning and stabbing his sister’s boyfriend to death.

Prison officials said they had banned the game at the recommendation of the prison’s specialist on gangs, who said it could lead to gang behavior and fantasies about escape.