Joueur_o.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from random import randint
  2. def joueur_o(P4, num_joueur):
  3. for i in range(len(P4)): #blocage horizontal de droite a gauche
  4. for j in range(len(P4[0])):
  5. if P4[i][j] == P4[i][j-1] and P4[i][j] != 0 and j-2 >=0 and P4[i][j-2] == 0:
  6. return j-2
  7. for i in range(len(P4)): #blocage horizontal de gauche a droite
  8. for j in range(len(P4[0])):
  9. if P4[i][j] == P4[i][j-1] and P4[i][j] != 0 and j+1 <= len(P4):
  10. if P4[i][j+1] == 0:
  11. return j+1
  12. for i in range(len(P4)): #blocage colonne
  13. for j in range(len(P4[0])):
  14. if P4[i][j] == P4[i-1][j] and P4[i][j] != 0 and P4[i-2][j] == 0:
  15. return j
  16. for i in range(len(P4)): #blocage diagonal a partir de la gauche
  17. for j in range(len(P4[0])):
  18. if P4[i][j] == P4[i-1][j-1] and P4[i][j] != 0 and (j-2) >= 0 and (i-1) != 0 and j+1 <= len(P4):
  19. return j-2
  20. for i in range(len(P4)): #blocage diagonal a partir de la droite
  21. for j in range(len(P4[0])):
  22. if P4[i][j] != 0 and (j-2) >= 0 and (i-1) != 0 and j+2 <= (len(P4[0])-1):
  23. if P4[i][j] == P4[i-1][j+1]:
  24. return j+2
  25. for i in range(len(P4)): #debut partie, commence des petites colonnes
  26. for j in range(len(P4[0])): # et lignes
  27. if P4[i][j] == num_joueur and P4[i-1][j] == 0 and i-1 >= 0:
  28. return j
  29. elif P4[i][j] == num_joueur and j+1 <= (len(P4[0])-1) and P4[i][j+1] == 0:
  30. return j+1
  31. elif P4[i][j] == num_joueur and j-1 >= 0 and P4[i][j-1] == 0:
  32. return j-1
  33. milieu = 0 #premier joueur
  34. for e in P4[-1] :
  35. if e != 0:
  36. milieu += 1
  37. if milieu == 0:
  38. return len(P4[-1])//2
  39. return randint(0,6)