-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkers.m
58 lines (53 loc) · 1.57 KB
/
checkers.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
load('values.mat');
load('strat.mat');
%% Make sure to set done=0 if youre starting over
%also run aiGen to generate new data before
generations=64;%how many gens you want to run right now
done=0;
population = 15;
children = 15;
total_pop = population + children;
games=5;%number of opponets an AI will face a generation
d = 6; %number of turns to look ahead
%I update done manually, Im storing the points data and need how many were
%done previously to keep up with the indexes
%%
%record = zeros(population,generations)
if done==0
aiGen(population);
end
for i=1:generations
points=zeros(total_pop,1);
for j =1:children
tempvar1=ceil(population*rand);
tempvar2=mod(tempvar1+ceil((population -1)*rand),population);
if tempvar2==0
tempvar2=ceil(population*rand);
end
tempStrat=sex(strat(tempvar1,:),strat(tempvar2,:));
strat(population + j,:)=tempStrat;
end
for j=1:total_pop
count=0;
for k=1:games
tempvar3=ceil(total_pop*rand);
point=fight(strat(j,:),strat(tempvar3,:),d);
count=count+1;
points(j)=point+points(j);
points(tempvar3)=4-point+points(tempvar3);
clc
fprintf('gen %d of %d\ngame %d of %d',i,generations,games*(j-1)+count,(games*total_pop));
end
end
for j =1:children
strat(find(points==min(points),1),:)=[];
points(find(points==min(points),1),:)=[];
end
subplot(8,8,i)
hist(points)
title(i)
end
for i=1:population
disp(points(i));
end
save('strat.mat');