function train(turn, t_k)
%  TRAIN  Trains the neural network using a modified version of temporal diff.
%  TRAIN(TURN, T_K), where TURN specifies the current player, and T_K is
%  the target evaluation for the network to learn, returns nothing.
%  THIS FUNCTION UPDATES GLOBAL VARIABLES.


global HISTORY LAMBDA;


%
%  For every previous move of this player, starting with the most recent,
%  run backprop on the network where the moves are the input vectors, t_k
%  is the target output vector, and a decaying learning rate is used.
%
[X, Y] = size(HISTORY{turn});
for i = 1:Y
    a_k = evaluate(HISTORY{turn}(:, i));
    learn(HISTORY{turn}(:, i), a_k, t_k, LAMBDA ^ i);
end
