Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !c29_1_5snakes_ladders.f95
- integer function next_state(i,trans,n)
- real::trans(n,n),cum_prob(n),r
- integer::mnloc(1)
- ! the random next_state after i
- endfunction
- program snakes_ladders_individual
- real::trans(9,9)=0,average=0
- integer,parameter::inf=10**5
- integer::n,next_state,nummoves,history(200)
- ! 1, 2, ..., 9 = board positions, trans = transition probabilities
- trans(1,7)=.5; trans(1,5)=.5
- trans(2,5)=.5; trans(2,4)=.5
- trans(3,4)=.5; trans(3,5)=.5
- trans(4,5)=.5; trans(4,1)=.5
- trans(5,1)=.5; trans(5,7)=.5
- trans(7,4)=.5; trans(7,9)=.5
- trans(8,9)=.5; trans(8,9)=.5
- do n=1,inf
- !play game
- history=0;i=1;history(1)=1
- do k=2,200
- i=next_state(i,trans,9)
- history(k)=i; if(i==9) exit
- enddo
- !update records and print play
- nummoves=count(history/=0)-1
- average=(average*(n-1)+real(nummoves))/n
- if(mod(n,6000)/=1)cycle
- print 11,nummoves,history(1:nummoves+1)
- enddo
- 11 format(i3," moves",200(i3))
- print '(a,f5.3,/)', "Average number of moves is ",average
- endprogram
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement