Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mostrarTablero():
- print("-".join(board[0]))
- print("|\|/|\|/|")
- print("-".join(board[1]))
- print("|/|\|/|\|")
- print("-".join(board[2]))
- print("|\|/|\|/|")
- print("-".join(board[3]))
- print("|/|\|/|\|")
- print("-".join(board[4]))
- def elegirNumero(rol):
- if rol== "Gallina":
- datosIngresados= queQuiereGallinas.split(",")
- pos_x_inicial= int(datosIngresados[0])
- pos_y_inicial= int(datosIngresados[1])
- pos_x_final= int(datosIngresados[2])
- pos_y_final= int(datosIngresados[3])
- #MOVIMIENTO VERTICAL Y HORIZONTAL
- if pos_y_inicial==pos_y_final and abs(pos_x_inicial-pos_x_final)==1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- elif pos_x_inicial==pos_x_final and abs(pos_y_inicial-pos_y_final)==1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- #DIAGONAL DERECHA
- elif pos_x_inicial==pos_y_inicial and pos_x_final==pos_y_final:
- if pos_y_final+1==pos_y_inicial or pos_y_final-1==pos_y_inicial:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- #CUADRADO SUPERIOR IZQ
- elif pos_x_inicial and pos_y_inicial and pos_x_final and pos_y_final in range(0,3):
- if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial-1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- #CUADRADO INFERIOR DERECHO
- elif pos_x_inicial and pos_x_final and pos_y_final and pos_y_inicial in range (2,5):
- if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial-1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- #CUADRADO INFERIOR IZQ
- elif pos_x_inicial and pos_x_final in range(0,3) and pos_y_inicial and pos_y_final in range(2,5):
- if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial-1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial+1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- #CUADRADO SUPERIOR DERECHO
- elif pos_y_inicial and pos_y_final in range(0,3) and pos_x_inicial and pos_x_final in range(2,5):
- if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial-1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial+1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
- board[pos_y_final][pos_x_final]="G"
- board[pos_y_inicial][pos_x_inicial]="N"
- elif board[pos_y_inicial][pos_x_inicial]=="C":
- return False
- else:
- return False
- if rol== "Coyote":
- datosIngresados= queQuiereCoyote.split(",")
- pos_x_inicial= int(datosIngresados[0])
- pos_y_inicial= int(datosIngresados[1])
- pos_x_final= int(datosIngresados[2])
- pos_y_final= int(datosIngresados[3])
- #MOVIMIENTO VERTICAL Y HORIZONTAL
- if pos_y_inicial==pos_y_final and abs(pos_x_inicial-pos_x_final)==1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- elif pos_x_inicial==pos_x_final and abs(pos_y_inicial-pos_y_final)==1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- #DIAGONAL DERECHA
- elif pos_x_inicial==pos_y_inicial and pos_x_final==pos_y_final:
- if pos_y_final+1==pos_y_inicial or pos_y_final-1==pos_y_inicial:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- #CUADRADO SUPERIOR IZQ
- elif pos_x_inicial and pos_y_inicial and pos_x_final and pos_y_final in range(0,3):
- if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial-1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- #CUADRADO INFERIOR DERECHO
- elif pos_x_inicial and pos_x_final and pos_y_final and pos_y_inicial in range (2,5):
- if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial-1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- #CUADRADO INFERIOR IZQ
- elif pos_x_inicial and pos_x_final in range(0,3) and pos_y_inicial and pos_y_final in range(2,5):
- if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial-1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial+1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- #CUADRADO SUPERIOR DERECHO
- elif pos_y_inicial and pos_y_final in range(0,3) and pos_x_inicial and pos_x_final in range(2,5):
- if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial-1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial+1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
- if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
- board[pos_y_final][pos_x_final]="C"
- board[pos_y_inicial][pos_x_inicial]="N"
- print("Bienvenido al juego del collote y las gallinas")
- n= input("¿Quieres cargar una partida (1) o empezar de nuevo (2)?")
- if n=="2":
- NombreJugadorCoyote= input("¡Perfecto! Dime el nombre del jugador que será el coyote:")
- NombreJugadorGallinas= input("Dime el nombre del jugador que será las gallinas:")
- print("¡Comencemos!")
- board= [["G","G","G","G","G"],["G","G","G","G","G"],["G","N","C","N","G"],["N","N","N","N","N"],["N","N","N","N","N"]]
- if n=="1":
- path= input("¿Cuál es el nombre del archivo?")
- file= open(path,"w")
- mostrarTablero()
- queQuiereGallinas= 0
- queQuiereCoyote= 0
- while queQuiereGallinas!="S" and queQuiereGallinas!="G" and queQuiereCoyote!="-1" and queQuiereCoyote!="-2":
- queQuiereGallinas =input("Es tu turno " + NombreJugadorGallinas +" ¿Cuál es tu movimiento? ¿o deseas guardar la partida y salir (G)? ¿o simplemente salir (S)?")
- while elegirNumero("Gallina") == False:
- queQuiereGallinas =input("Este movimiento es inválido, por favor intenta de nuevo: ")
- elegirNumero("Gallina")
- elegirNumero("Gallina")
- mostrarTablero()
- queQuiereCoyote=input("Es tu turno " +NombreJugadorCoyote + " ¿Cuál es tu movimiento? ¿o deseas guardar la partida y salir (-1)? ¿o simplemente salir (-2)?")
- elegirNumero("Coyote")
- mostrarTablero()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement