import numpy
from PIL import Image
from IPython.display import Image as dispImage

#Generate initial image
data = numpy.zeros((8, 8, 3), dtype=numpy.uint8)

white = [255, 255, 255]
grey = [128, 128, 128]
black = [0,0,0]

boardRows = 8
boardColumns = 8

for i in range(boardRows):
  for j in range(boardColumns):
    if (i == 3 and j == 3) or (i == 4 and j == 4):
      data[i, j] = white
    elif (i == 3 and j == 4) or (i == 4 and j == 3):
      data[i, j] = black
    else:
      data[i, j] = grey


image = Image.fromarray(data)
image.show()
image = image.save("prueba.jpg")
dispImage("prueba.jpg", width=100, height=100)

#Path to the file 15x10_w.txt
with open('/content/drive/MyDrive/Colab Notebooks/Hackathon/Board_To_Image/Data/Training Set/15x10_w.txt') as f:
    lines = f.readlines()
    f.close()

auxParams = lines[0].split("\n")
params = auxParams[0].split(" ")
print(params)
#0 5 4 ==> 
#First   0 == black - 1 == white 
#Second  parameter column index (from 0 to 7) 
#Third   parameter row    index (from 0 to 7) 

#Print first movement
#FROM THIS POINTS, THE FIRST PARAMETER "i" IS THE ROW AND THE SECOND "j" THE COLUMN
if params[0] == "0":
  color = black
else:
  color = white
i = int(params[2])
j = int(params[1])
data[i,j] = color
print(i,j)  

#Print all movements (WITHOUT FLIPPLIG SPOTS)
"""
for line in lines:
  auxParams = line.split("\n")
  params = auxParams[0].split(" ")
  if params[0] == "0":
    color = black
  else:
    color = white
  i = int(params[2]) #rows
  j = int(params[1]) #colummns
  data[i,j] = color
  print(data)  
"""

#Save image with movement
image = Image.fromarray(data)
image.show()
image = image.save("prueba.jpg")
dispImage("prueba.jpg", width=100, height=100)