-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnot_so_greedy_player.m
75 lines (71 loc) · 2.41 KB
/
not_so_greedy_player.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function chosen_column = not_so_greedy_player(grid, player, how_many_to_connect)
global difficulty
if isempty(difficulty)
difficulty = 0.5;
end
preferred_columns = greedy_player(grid, player, how_many_to_connect);
if length(preferred_columns) == 1 || rand<0.5+difficulty/2
chosen_column = preferred_columns(1);
else
chosen_column = preferred_columns(2);
end
% second_best_column = 0;
% second_best_chains = zeros(2*how_many_to_connect,1);
%
% found_first = false;
% for column = 1:size(grid,2)
% if ~isempty(find(grid(:,column)==0, 1))
% [chains_made, chains_blocked] = evaluate_play(make_play(grid,column,player),column,how_many_to_connect);
% chains = reshape([chains_blocked';chains_made'],[2*how_many_to_connect,1]);
%
% if found_first == false
% best_chains = chains;
% best_column = column;
% found_first = true;
% else
% better_than_best = false;
% for chain_index = length(chains):-1:1
% if chains(chain_index) < best_chains(chain_index)
% break
% elseif chains(chain_index) > best_chains(chain_index)
% second_best_chains = best_chains;
% second_best_column = best_column;
% best_chains = chains;
% best_column = column;
% better_than_best = true;
% break;
% end
% end
%
% if better_than_best == false
% for chain_index = length(chains):-1:1
% if chains(chain_index) < second_best_chains(chain_index)
% break
% elseif chains(chain_index) > second_best_chains(chain_index)
% second_best_chains = chains;
% second_best_column = column;
% break;
% end
% end
% end
% end
% end
% end
%
% if second_best_column == 0 || rand<0.5+difficulty/2
% column_just_played = best_column;
% else
% column_just_played = second_best_column;
% end
%
% if column_just_played<= 0
% error('Rob2');
% end
%
% if column_just_played> size(grid,2)
% error('Rob3');
% end
%
% if isempty(find(grid(:,column_just_played)==0, 1))
% error('Rob');
% end