import random

import matplotlib.pyplot as plt
import numpy as np

xvec = {1: 3, 2: 2, 3: 1, 4: 3, 5: 2, 6: 1, 7: 3, 8: 2, 9: 1}
yvec = {1: 1, 2: 1, 3: 1, 4: 2, 5: 2, 6: 2, 7: 3, 8: 3, 9: 3}

neighbor = {1: [2, 4, 1, 1], 2: [3, 5, 1, 2], 3: [3, 6, 2, 3],
            4: [5, 7, 4, 1], 5: [6, 8, 4, 2], 6: [6, 9, 5, 3],
            7: [8, 7, 7, 4], 8: [9, 8, 7, 5], 9: [9, 9, 8, 6]}

list_vec = []
run = 1
if run < 10:
    run_str = '0' + str(run)
else:
    run_str = str(run)
for n_runs in range(100000):
    pos = 9
    for iter in range(run):
        pos = neighbor[pos][random.randint(0, 3)]
    list_vec.append(pos)
print(list_vec)
x = [xvec[k] for k in list_vec]
y = [yvec[k] for k in list_vec]

plt.xticks([])
plt.yticks([])
H, xedges, yedges = np.histogram2d(x, y, bins=(3, 3),
                                   range=[[1, 3], [1, 3]], normed=True)
print(H)
H /= np.sum(H)
print(H)
extent = [yedges[0], yedges[-1], xedges[-1], xedges[0]]
plt.imshow(H, extent=extent, interpolation='nearest', vmin=0.0, vmax=1.0)
plt.set_cmap('hot')
plt.colorbar()
plt.title('t = ' + str(run), fontsize=22)
plt.show()
