import copy


def correct_Q(action, state, reward, old_Q, next_Q):
    """
    Produce a corrected Q(s,a) estimate according to:
    Q(s,a) = R + gamma*Q(s+1,a+1)
    """
    gamma = 0.5   # weights importance of future reward
    new_Q = copy.copy(old_Q)
    new_Q[action] = reward + gamma*next_Q[action]   # action indexes are 0,1,2, corresponding to position in Q-function

    return new_Q