RTR42WQ1REUTERS/Issei KatoA visitor plays pachinko at Dynam's pachinko parlour in Fuefuki, west of Tokyo June 19, 2014.

THE gaudy pachinko parlours that disfigure many a Japanese high street are an acquired taste. The country's 12,000 parlours keep players sealed off from the outside world behind a thick wall of noise, smoke and gambler's tension. The pinball-with-prizes machines, with their flashing lights and ceaseless din, induce a trance-like state, prompting Donald Ritchie, an American writer on Japan, to describe pachinko as "cut-price Zen".

Pachinko has been in decline for years, yet its revenues last year were put at 19 trillion yen ($175 billion). To give some idea, that was almost twice the Japanese motor industry's export revenues. About one in seven Japanese adults play it regularly. For decades it has thrived in a legal grey zone, just about dodging an official ban on gambling. Now it faces two challenges: a government plan to allow the building of big, legal casinos; and finding a way to reinvent itself for the video-game generation.

The second problem is the toughest. To young Japanese, pachinko is a bit naff, something your fusty old uncle wastes his time with. The number of regular players has halved since 2002 and the existing customer base is ageing. Its survival is at risk unless it can attract younger men, and more women, admits Toshiharu Kikuchi, a spokesman for Dynam Japan, the largest pachinko-parlour chain.

So, flush with more than $200m from a 2012 flotation on the Hong Kong stockmarket, Dynam plans to open 1,000 new parlours (it currently operates 380). Its new ones are luxurious and air-conditioned, with restaurants and uniformed staff akin to casino attendants. Eventually, says Mr Kikuchi, all Dynam's parlours will be non-smoking–a radical move in an industry so reliant on chain-smoking geezers. Other big operators are also investing in more modern premises. Earlier this year Zent, a rival, opened what it claims is the country's largest parlour, in Nagoya.

pachinkoREUTERS/Issei KatoVisitors play at Dynam's pachinko parlour in Fuefuki, west of Tokyo June 19, 2014.

The casino-legalisation law, which the prime minister, Shinzo Abe, wants to pass in the next few months, will not just bring new competition for the pachinko parlours. The aim is to drag casino gambling away from the seedy company it keeps in illegal backstreet dives and put it in big, family-friendly resorts. So it is inevitable that pachinko will come under similar scrutiny, says Takeshi Iwaya, a lawmaker with the ruling Liberal Democrats.

Pachinko bosses insist the game is played for fun and for trivial prizes. However, the metal balls that players "win" on the machines can also be swapped for tokens and then for cash, at a separate premises nearby. This contrivance used to be dominated by yakuza criminal gangs, which extorted cash from the parlours' owners.

Many parlours are run by Korean-Japanese, some of whom used to send money to the hostile regime in Pyongyang. The authorities have stopped the flow of cash to North Korea, and the police have squeezed out the mobsters–but with unexpected consequences.

The industry is now regulated by the Security Electronics and Communications Technology Association (SECTA), a state agency stuffed with retired policemen. Many parts of the industry, such as the makers of the pachinko machines (which are certified and inspected by SECTA) employ ex-cops as consultants.

pachinkoREUTERS/Issei KatoA woman plays pachinko at Dynam's pachinko parlour in Fuefuki, west of Tokyo June 19, 2014.

The resulting bureaucracy has caused "more trouble and expense for pachinko businesses than the yakuza ever did," concludes a study by Andrew Rankin, a Cambridge University researcher. And as Colin Jones of Doshisha Law School delicately puts it, the police are now deeply involved in the industry in a way that "may not always be conducive to police integrity."

If the government's gambling liberalisation formally legalises pachinko, as looks likely, that would pave the way for taxing it. The finance ministry could look forward to billions of dollars a year. And perhaps a dozen or so big parlour operators could list on the Tokyo stockmarket, raising money to modernise.

Dynam's chairman, Yoji Sato, insists his firm is ready to take on the legalised casinos: he thinks the government is likely to allow no more than ten; and that they will mainly draw rich foreign tourists. His working-class customers will stick with their pachinko.

Click here to subscribe to The Economist