
% Takes as parameter the X value of the event, and the
% distribution D_y|x. Returns an optimal guess for the
% value of the green dice.
function green = t2_2(x_val, y_x)

% Choose the probability row accosiated to given X value.
probRow = y_x(x_val, :);

% Find the maximum probability.
max_prob = max(probRow);

% Set probability of lesser probability events to zero.
% (In this case this doesn't matter, since all events have equal
% probability, but in general, if you wish to hit most often to
% the correct answer, it is best to choose the event with the
% greatest probability.)
probRow(probRow < max_prob) = 0;

% Find one of the best events and return this as the guess.
for i = 1:6;
    if probRow(i) ~= 0;
        green = i;
        return;
    end
end

% If user gave us an x_val that doesn't occur in the data,
% return 0.
green = 0;