A 1,500-mile defensive wall has brought stalemate to the 12-year-old Polisario guerrilla war to wrest control of the Western Sahara from Morocco.

The guerrillas say they hold out little hope for an outright military victory.They now talk of compromise in their campaign for an independent nation in the former Spanish colony in northwest Africa. Nevertheless, refugees remain keyed up for war in teeming Polisario camps near the Algerian border where military training begins in primary school, and their slogan, "The Entire Nation or Martyrdom," is everywhere.

They have been fighting for independence since 1976 when Spain relinquished what then was the Spanish Sahara to joint Moroccan and Mauritanian control.

Mauritania withdrew from the conflict in 1979, but Morocco maintained the fight to hold its sovereignty over the territory, which is about the size of Colorado and is rich in phosphates and possibly potash and iron ore.

Morocco began building its defensive wall of rock and sand in 1980. Now completed, it is studded with concrete bunkers and U.S.-made sensors to detect infiltrators.

Almost all of Morocco's 100,000-man army is deployed along the wall, and guerrilla attacks behind it have virtually stopped.

Talking to visiting Western reporters in their camp at Akuadim, the guerrillas acknowledged that their "liberation struggle" has degenerated into a series of brief hit-and-run assaults on Moroccan defenses.

Bachir Sayed, a member of Polisario's seven-member Executive Committee, told the visitors: "We don't want to defeat Morocco. We want to create a different situation . . . that will bring (Morocco's) King Hassan II to the bargaining table."

The guerrillas suffered a serious blow in May when Algeria, which has supported the Polisario Front, restored the diplomatic relations it broke with Morocco over the issue.

Algerian officials now are hinting that Polisario might accept some kind of autonomy under Moroccan sovereignty, but the guerrillas have not acknowledged this is their intent.

Their main sanctuary now is in the stark, hilly desert around the oasis of Tindouf inside Algeria.

The last Algerian checkpoint is three miles outside Tindouf. After that are camps for more than 100,000 refugees, followed along the road by miles of sand and shrub. The comes the "battle zone" that stretches across Algeria's border into a no man's land leading to the Moroccan wall.

Polisario has built hospitals and military schools in the zone, but the guerrillas say they intend to abandon the area whenever they "return" to the Moroccan-held phosphate mines and fishing ports on the Atlantic coast.

When Spanish colonial rule ended, the territory's population comprised 80,000 tribal nomads roaming the desert with camels and goats.

Polisario claims to have 16,000 heavily armed guerrillas operating in the desert. Moroccan officers estimate guerrilla strength at fewer than 4,000.

Abba Deddi, a 23-year-old Polisario guerrilla, said he could not imagine being anything but a soldier.

"I want to remain a soldier even after the liberation, to fight against any new colonialist attempts," he said.

Out in the battle zone, a five-hour drive from Tindouf across a featureless desert, a group of uniformed guerrillas played cards on a blanket, surrounded by empty artillery shells scattered on the sand. They were desert men, ranging from 18-year-old recruits to veterans of the Spanish Foreign Legion.

Artillery fire thudded in the distance as the Moroccans responded to an attack on the wall by another Polisario unit.

The firing stopped abruptly.

"That's all," said Omar Mohammed, the unit commander. "We give them 10 minutes every two or three hours. It keeps them on their toes."

Mohammed said his forces frequently cross the Moroccan wall after disabling its radar system. The Moroccans claim not a single attack has even reached the wall's outer defenses since last summer.

"We have the advantage of knowing the desert and of speed," Mohammed said. "We dismantle the mines, cut the barbed wire, cross in, capture weapons, take prisoners and retreat."