function NC=risk2(Nastart,Ndstart,Nsim),
## RISK2: GNU Octave/Matlab Program for calculation of the number of countries that can be defeated in the game of Risk during one turn, if one attacker army is left in each country.
## Call: NC=risk(Nastart,Ndstart,Nsim)
## Example: NC=risk(1:2,1,3000)
## Input parameters: Na is number of attacking armies in the first attack. 
## (Scalar, or vector of several cases.)
## Nd is the number of defending armies in each country. (Scalar, the same in each country.)
## Nsim is the number of randomized runs. (Scalar)
## 
## Output parameter: NC consist of Nsim columns and length(Nastart) rows, and is the number of defeated countries.
## Each row in NC is sorted.
##
## Example of analysis: 
## mean(NC,2) gives the average number of defeated countries for each Nastart case.
## NC(:,round((1-p)*Nsim)) gives the p percentile of the number of defeated countries, 
## or the median number if p is .5.
##
## This program calls: risk.m. 
##
## Author: Magnus Eriksson <magnus.eriksson@miun.se>
## Created: 2010-07-09


if length(Nastart)>1
	for k=1:length(Nastart)
		NC(k,:)=risk2(Nastart(k),Ndstart,Nsim); % Resulting in matrix of number of defeated countries
		save risk2result NC
	end
else
	NC=[]; % Row vector of number of defeated countries, one value per simulation run.
	for k=1:Nsim, 
		Na=Nastart;
		Nc=0; % Counter of number of defeated contries (scalar).
		while Na>=1, %Anfall land för land tills högst en anfallare kvar i sista landet. 
			[p,Na,Nd]=risk(Na,Ndstart,1);
			if Na>=1, 
				Nc=Nc+1; % The attacker won. Another country is defeated.
				Na=Na-1; % Leave one army in the country and continue with the rest.
			end 
		end,
			NC=[NC Nc]; 
	end
	NC=sort(NC);
end