In Vedic culture, military science recognizes two kinds of warfare - the dharmayuddha and the kutayuddha. Dharmayuddha is war carried on according to the principles of dharma. Ksatradharma, then, is the law of Kings and Warriors.
Wars which were just and righteous, initiated by a pious King under counsel of the brahmanas, had the approval of society. These are dharmayuddha wars. Kutayuddha wars, on the other hand, were unrighteous wars, led by a demoniac King, against the counsel of the brahmanas, and without keep the welfare of society in the forefront. Such unbonafide wars were generally conducted in secret.
The Vedic science of warfare values both niti and saurya, that is, ethical principles and valor. It was understood that the waging of war without regard for moral standards would only degrade the instigator and his supporters into mere animal ferocity.
A monarch desirous of dharma vijaya would conform to the code of ethics enjoined by warriors of good principle. These two kinds of warfare - principled and unprincipled -- are elaborately described in the Dharmasutras and Dharmasastras, including the epic Mahabharata, Ramayana, the Arthasastra treatises of Kautalya, Kamandaka, and Sukra.
Vedic India possessed the classical fourfold force of chariots, elephants, horsemen, and infantry, collectively known as the Caturangabala. Those familiar with the ancient game of Chess will know that it also goes by the name of 'Caturanga'. From references to the game of Chess in the Rg Veda and the Atharva Veda, and in Buddhist and Jain tests, we can see that the game was very popular in ancient India. The Persian term 'Chatrang' and the Arabic 'Shatrang' are forms of the Sanskrit 'Caturanga'.
Dharmayuddha is a Sanskrit word made up of two roots: 'dharma' meaning righteousness, and 'yuddha' meaning warfare. In the ancient Vedic texts, Dharmayuddha refers to a war that is fought while following the rules for righteous warfare. For instance, in a righteous war, equals fight equals. Chariot warriors are not permitted to attack cavalry and infantry, those on elephants are not permitted to attack infantry, and so on. The rules also forbid the use of celestial weapons (divine weapons bestowed by the Lord or the demigods) on ordinary soldiers. The build-up of weapons and armies is done with the full knowledge of the opposing side, and no surprise attacks are made.
The rules of engagement in a righteous war also specify how warriors are to deal with noncombatants. For example, no one may attack an enemy who has temporarily lost or dropped their weapon. The lives of women, prisoners of war, and farmers were also sacred. Pillaging the land was forbidden. Dharmayuddha signifies that the war is not fought for gain or selfish reasons, but rather to uphold the principles of righteousness.
In the Mahabharata, which describes the great war of Kurukshetra, the two sides on the battlefield agreed to accept the following rules:
Fighting must begin no earlier than sunrise and end exactly at sunset
Multiple warriors may not attack a single warrior
Two warriors may "duel," or engage in prolonged personal combat only if they carry the same weapons and are on the same mount (i.e., no mount, a horse, an elephant, or a chariot)
No warrior may kill or injure a warrior who has surrendered
One who surrenders becomes a prisoner of war and a slave
No warrior may kill or injure an unarmed warrior
No warrior may kill or injure an unconscious warrior
No warrior may kill or injure a person or animal not taking part in the war
No warrior may kill or injure a warrior whose back is turned away
No warrior may strike an animal not considered a direct threat
The rules specific to each weapon must be followed. For example, it is prohibited to strike below the waist in mace warfare
Warriors may not engage in any "unfair" warfare whatsoever
While King Yudishtira began his war for righteous reasons, by the end of the 18 days of fighting, he and his relatives had broken every rule of righteous warfare.
While the rules noted above were agreed upon by the adversaries at Kurukshetra, they are not necessarily imposed. For example, in the Valmiki Ramayana, Yuddha Kanda, Canto 44, is described a war that took place under cover of nighttime. Like all rules of warfare, the rule that battle must cease at sunset was a condition set down before the commencement of the great Mahabharata war. There, Bhishma was present to negotiate the rules, being highly respected by both sides of the battle. Bhishma's rules were followed until he headed the Kauravas. But even in the Mahabharata, we read of ‘nocturnal engagements' from the 14th day of the war on.
Beyond the Ramayana and Mahabharata, the principles of Dharmayuddha are referred to in many other ancient Vedic texts, including the Ramayana and the Dharmashastras, or texts of law.
Sources: Valmiki's Ramayana, Tribute to Hinduism and Wikipedia