63 lines
No EOL
1.9 KiB
Python
63 lines
No EOL
1.9 KiB
Python
# archivo motor.py
|
|
|
|
from funciones import comprueba_ganador, datos_jugadores, imprime_tablero, tatetivsPC, pedir_numero, informa_ganador
|
|
|
|
# Creo una función que inicializa el tablero del juego con las casillas numeradas.
|
|
|
|
def crear_tablero():
|
|
return ["1", "2", "3",
|
|
"4", "5", "6",
|
|
"7", "8", "9"]
|
|
|
|
# Defino una función para crear y devolver el tablero inicial con las posiciones disponibles,
|
|
# permitiendo luego almacenar las X y O según los movimientos de los jugadores.
|
|
|
|
tablero = crear_tablero()
|
|
|
|
def jugar_tateti(opcion):
|
|
nombre_jugadorX, nombre_jugadorO = datos_jugadores(opcion)
|
|
imprime_tablero(tablero)
|
|
jugadas = 0
|
|
jugadorX = True
|
|
jugadorO = False
|
|
|
|
while jugadas < 9:
|
|
if jugadorX:
|
|
print("\nTurno del jugador X")
|
|
numeroElegido = pedir_numero()
|
|
else:
|
|
if opcion == str(1):
|
|
print("\nTurno del jugador O")
|
|
numeroElegido = pedir_numero()
|
|
else:
|
|
print("\nTurno PC")
|
|
numeroElegido = int(tatetivsPC(tablero))
|
|
|
|
if 1 <= numeroElegido <= 9:
|
|
|
|
if tablero[numeroElegido - 1] not in ['X', 'O']:
|
|
|
|
if jugadorX:
|
|
tablero[numeroElegido - 1] = 'X'
|
|
jugadorX = False
|
|
jugadorO = True
|
|
else:
|
|
tablero[numeroElegido - 1] = 'O'
|
|
jugadorX = True
|
|
jugadorO = False
|
|
|
|
jugadas += 1
|
|
|
|
imprime_tablero(tablero)
|
|
|
|
else:
|
|
print("Ubicación no disponible.")
|
|
|
|
else:
|
|
print("Ingrese un número válido del 1 al 9.")
|
|
|
|
if comprueba_ganador(tablero):
|
|
informa_ganador(jugadorX, nombre_jugadorO, nombre_jugadorX)
|
|
break
|
|
elif jugadas==9:
|
|
print("La partida terminó empatada") |