rewardFunction = -3*ones(nStates,nActions);
%%
position = 28;
GraphicalAnimation(A,B,...                          % Maze layout
                       [x(position) y(position)],fi(position),...         % Robot location
                       IPoint_IR_sensor(:,:,position),t)  % IR sensor data
                   
%%
aux1 = 1;
v = 0;
c = unique(state(1,:));
for i = 3:length(c)
    if rewardFunction(c(i),:) == rewardFunction(1,:)
        v(aux1) = c(i);
        aux1 = aux1 +1;
    end
end
for i = 1:length(v)
    v(i)
    position = find(state==v(i));
    GraphicalAnimation(A,B,...                          % Maze layout
                       [x(position(1)) y(position(1))],fi(position(1)),...         % Robot location
                       IPoint_IR_sensor(:,:,position(1)),t)  % IR sensor data
    pause
end
%%
change = [2329 2332 2396 2400 2526];
for i=1:length(change)
    rewardFunction(change(i),:)=rewardFunction(2460,:);
end

%%
%[e,f]=hist(state,unique(state))
%[d,indice] = maxk(e,30)
    
auxiliar=unique(state);
visited = zeros(1,length(auxiliar));
for ii=1:length(auxiliar)
    auxiliar(ii);
    visited(ii)=size(find(state==auxiliar(ii)),1);
end
maximun_values=maxk(visited,12)
states_visited=zeros(1,length(maximun_values));
for ii=1:length(maximun_values)
    ans=find(visited==maximun_values(ii));
    states_visited(ii)=auxiliar(ans)
end