Tres en raya (PYTHON)
Samuel Ferro MartiñoTarea23 de Marzo de 2020
1.349 Palabras (6 Páginas)673 Visitas
#Tres en raya
#-*- coding: utf-8 -*-
"""Juego del tres en raya
"""
#------------------------------------
#Creamos el tablero
tab1=[[0,0,0],[0,0,0],[0,0,0]]
tab2=[["","",""],["","",""],["","",""]]
#------------------------------------
#Librerias
import random
#------------------------------------
#Variables
turnojugador1=True
terminado=False
ganador=False
cantturnos=0
#------------------------------------
#Comienza el programa
nombre1=input("Cual es tu nombre jugador 1?").capitalize()
nombre2=input("Cual es tu nombre jugador 2?").capitalize()
print('Bienvenidos al tres en raya',nombre1,'y',nombre2,'!')
print('Que gane el mejor :V')
if __name__ == '__main__':
tab1 = [[float() for ind0 in range(3)] for ind1 in range(3)]
tab2 = [[str() for ind0 in range(3)] for ind1 in range(3)]
for i in range(1,4):
for j in range(1,4):
tab1[i-1][j-1] = 0
tab2[i-1][j-1] = " "
while terminado==False:
# comentarios
print("") # no hay forma directa de borrar la pantalla con Python estandar
print(" ")
print(" || || ")
print(" ",tab2[0][0]," || ",tab2[0][1]," || ",tab2[0][2])
print(" 1|| 2|| 3")
print(" =====++=====++======")
print(" || || ")
print(" ",tab2[1][0]," || ",tab2[1][1]," || ",tab2[1][2])
print(" 4|| 5|| 6")
print(" =====++=====++======")
print(" || || ")
print(" ",tab2[2][0]," || ",tab2[2][1]," || ",tab2[2][2])
print(" 7|| 8|| 9")
print(" ")
if ganador ==False and cantturnos<9:
#Comentarios
if turnojugador1:
ficha='O'
valor=1
objetivo=1
print("Te toca jugar ",nombre1,"(X)")
else:
ficha='X'
valor=2
objetivo=8
print("Te toca jugar ",nombre2," (O)")
#Comentarios
print("Ingrese la posición(1-9):")
while True:
pos = float(input())
if pos<1 or pos>9:
print("Posicion incorrecta, ingrese nuevamente: ")
pos = 99
else:
i = int((pos-1)/3+1)
j = int((pos-1)%3+1)
if tab1[i-1][j-1]!=0:
pos = 99
print("Posicion incorrecta, ingrese nuevamente: ")
if pos!=99: break
# comentarios
cantturnos = cantturnos+1
tab1[i-1][j-1] = valor
tab2[i-1][j-1] = ficha
# comentarios
aux_d1 = 1
aux_d2 = 1
...