Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # from the starting state, select the next state according to the
- # transition matrix T
- function rungame(T)
- # start at state 140
- current = 140
- # count turns
- turns = 0
- while current != 134
- # get transitions from current state
- A = [(i,j) for (i,j) in enumerate(T[:,current]) if i != 0]
- # separate transitions into states and probabilities
- states = [i[1] for i in A]
- probs = [i[2] for i in A]
- # select the next state from the transitions distribution
- current = sample(states, Weights(probs))
- turns+=1
- end
- return turns
- end
- # run function rungame on transition matrix T
- # and return the average turns over N runs
- function getAverageTurns(T,N)
- result=0
- for i=1:N
- result+=rungame(T)/N
- end
- return result
- end
- println("turns:\t",getAverageTurns(T,1000),"\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement