R, 120120 114 bytes
m=matrix
p=m(c(0,rep(1,13),0),3)
r=m(" ",30,5)
x=3
for(i in 1:30){r[i,x]=0;x=x+sample(-1:1,1,,p[m(c(0,rep(1,13)),3)[,x])}
write(r,"",30,,"")
Thanks to @Giuseppe for the additional 6 bytes!
Uses a table of probabilities p
as follows:
> pmatrix(c(0,rep(1,13)),3)
[,1] [,2] [,3] [,4] [,5]
[1,] 0 1 1 1 1
[2,] 1 1 1 1 1
[3,] 1 1 1 1 0
Warning message:
In m(c(0, rep(1, 13)), 3) :
data length [14] is not a sub-multiple or multiple of the number of rows [3]
where each columns corresponds to a case, i. e. column 1 is picked if the snake is in row 1, giving probabilities 0, 1/2 and 1/2 to pick respectively -1 [go down], 0 [stay still] and 1 [go up] (sample
automatically normalize the probabilities to 1), column 2 for row 2 gives probabilities 1/3, 1/3 and 1/3, etc...