A bizarre and intense diplomatic game is being played out in this capital as the Soviet-installed government of Babrak Karmal maneuvers to cover itself with a veneer of legitimacy despite resistance by much of the world.

Although the United States and other Western European and Islamic nations maintain embassies here, most have recalled their ambassadors and have only limited official contacts with the Babrak government -- a diplomatic way of expressing their disapproval of the way it gained power.

The desire to show that disapproval is so strong among some nations that it overrules the customary niceties of diplomatic behavior. American officials in the small mission remaining here are under instructions to turn their backs if high Afghan officials, such as Foreign Minister Mohammed Dost, move to greet them.

The Americans go to no official Afghan functions and -- along with most Western and Islamic diplomats -- are not supposed to invite members of the Babrak government to their parties.

Working in the other direction, among others, is Evlogui Bonev, a Bulgarian who heads the United Nations development activities here. Although U.N. Advisers are unable to move outside the capital city because of the spreading rebellion against the Babrak government and all current projects are at a standstill, Boney is busily drafting expanded future U.N. programs here, according to Western members of the U.N. team.

The officials said Bonev, who could not be reached for comment, consistently paints for his superiors at U.N. headquarters in New York an optimistic picture of the Afghan government's ability to control the country, while striving to excise unfavorable material from the reports.

At stake in the maneuvering is the development of diplomatic leverage to get the Soviets to withdraw their troops from Afghanistan and the need of the Afghan government to obtain recognition of its legitimacy from non-socialist Bloc countries, especially its Islamic neighbors.

In an effort to widen the contacts, Afghan officials try to inject deeper political meaning into the most mundane administrative matters, such as getting new visas for replacements for diplomats now assigned here.

American diplomats keep even such routine contacts to a minimum, dealing only with the Foreign Ministry and refusing to discuss any substantive political matters. In effect, all contacts are limited to consular duties -- protecting the less than 40 Americans left in the country -- and the housekeeping chores required to run the embassy.

The Moslem nations, in their dealings with the government, are under instructions voted in January by the Islamic Foreign Ministers Conference as part of a package of sanctions and condemnations of the Soviet invasion of Afghanistan that led to the Babrak government coming to power.

In May the Islamic Conference eased its harsh stand slightly, voting against recognizing the Babrak government, yet forming a committee to meet with all the parties involved to try and find some political way to effect a Soviet pullout.

The committee proposed the neat solution of meeting Babrak and his associates, not as government officials, but as members of the ruling People's Democratic Party of Afghanistan.

Needless to say, the Babrak government has rejected that overture and is holding out for full diplomatic recognition. Similarly, the Soviets have thus far refused to meet with the Islamic conference committee, insisting the subject has to be discussed with the Babrak government, which it says invited the Soviet troops into Afghanistan.

Thus there was a minor diplomatic furor here last week when it was reliably reported that two Islamic nations -- Turkey and Iraq -- and the independent communist state of Yugoslavia had agreed to accept career diplomats as ambassadors from Afghanistan.

Afghanistan was credited with adroitly moving around the Islamic Conference ban on the recognition of the Babrak government by making its first overtures to two Moslem countries that had never withdrawn their ambassadors from Kabul.

There are rumors here that Afghanistan will next seek as ambasadorial exchange with its two neighboring Islamic nations, Iran and Pakistan, who have been far and away the staunchest opponents of the Soviet invasion.