Advertisement
Matblinx

help

Jun 2nd, 2021
1,089
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. def imprime_tablero(tablero):
  2.     for l in tablero:
  3.         print("|" , " ".join(l), "|")
  4.     print("")
  5. def revisa_ganador(sim, mat):
  6.     objetivo = len(mat)
  7.     #filas
  8.     for l in mat: #cada linea
  9.         if l.count(sim)== objetivo:
  10.             return True
  11.     #diagonales
  12.     comp = []
  13.     comp_i = []
  14.     for i in range(objetivo):
  15.          comp.append(mat[i][i])
  16.          comp_i.append(mat[i][-(i+1)])
  17.     if comp.count(sim)== objetivo or comp_i.count(sim)==objetivo:
  18.         return True
  19.  
  20.     #columnas
  21.     for j in range(objetivo):
  22.         columna = []
  23.         for l in mat:
  24.             columna.append(l[j])
  25.         if columna.count(sim) == objetivo:
  26.             return True
  27.  
  28.     return False
  29. posicion = int(input())
  30. auxiliar = posicion
  31. tj1 = posicion//10
  32. tj2 = auxiliar%10
  33. if tj1 != 0 and tj2 !=0:
  34.     tj1 -= 1
  35.     tj2 -= 1
  36. tablero_jugadores = [["-","-","-"], ["-","-","-"],["-","-","-"]]
  37. tablero_jugadores[tj1][tj2] = "x"
  38. print(imprime_tablero(tablero_jugadores))
  39. posicion2 = int(input())
  40. auxiliar2 = posicion2
  41. tj3 = posicion2//10
  42. tj4 = auxiliar2%10
  43. if tj3 != 0 and tj4 !=0:
  44.     tj3 -= 1
  45.     tj4 -= 1
  46. tablero_jugadores = [["-","-","-"], ["-","-","-"],["-","-","-"]]
  47. tablero_jugadores[tj3][tj4] = "O"
  48. tablero2 = imprime_tablero(tablero_jugadores)
  49. print(tablero)
  50. victorio = revisa_ganador(tablero, tablero_jugadores)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement