All problems
Monte Carlo Return
Problem
Estimate the value of a target state from a fixed episode using first-visit Monte Carlo.
Find the first index where states equals target and return the discounted sum of rewards from that index onward. If the target never appears, return 0.0.
Hint
The first visit matters: ignore later occurrences of the target state.
Test cases
case 1
in: [["A","B","A"],[1,2,3],"A",0.5]
expected: 2.75
case 2
in: [["A","B","A"],[1,2,3],"B",0.5]
expected: 3.5
case 3
in: [["A","B","A"],[1,2,3],"C",0.5]
expected: 0
case 4
in: [["S"],[5],"S",0.99]
expected: 5
Starter codePython
def monte_carlo_return(states, rewards, target, gamma):
# Your code here
pass4 test cases · run your code against them in the editor