% 血液型の分布が世代交代によりどう変化するか
% n人の男性とn人の女性が全員結婚する．
% 各ペアは男児1名，女児1名を生む．
% 子供の血液型は遺伝の法則に従い，ランダムに決める

%seed = 1;
seed = 3;
rng(seed);
fprintf("seed = %d\n", seed);
%rng('shuffle')

nc = 500; % 男性人口，女性人口の1/100
n = 100*nc; % 男性人口，女性人口

fileid = fopen("simulation_result.txt", "w");

% AA:20 AO:20 OO:30 BB:10 BO:10 AB:10 分布を%で与える
dist = [ 20, 20, 30, 10, 10, 10 ];

% AA: 8 AO:32 OO:30 BB: 4 BO:16 AB:10 分布を%で与える
%dist = [  8, 32, 30,  4, 16, 10 ];

[father,mother] = blood_type_distribution_init(nc, dist);
count = count_distribution(father) + count_distribution(mother);
disp_gen_count(fileid, 0, count);

for gen = 1:10
    p = matching(n);
    [childf,childm] = children(n,father,mother,p);
    father = childf;
    mother = childm;
    count = count_distribution(father) + count_distribution(mother);
    disp_gen_count(fileid, gen, count);
end

fclose(fileid);
