Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.64 KB | None | 0 0
  1. def mostrarTablero():
  2. print("-".join(board[0]))
  3. print("|\|/|\|/|")
  4. print("-".join(board[1]))
  5. print("|/|\|/|\|")
  6. print("-".join(board[2]))
  7. print("|\|/|\|/|")
  8. print("-".join(board[3]))
  9. print("|/|\|/|\|")
  10. print("-".join(board[4]))
  11.  
  12. def elegirNumero(rol):
  13. if rol== "Gallina":
  14. datosIngresados= queQuiereGallinas.split(",")
  15. pos_x_inicial= int(datosIngresados[0])
  16. pos_y_inicial= int(datosIngresados[1])
  17. pos_x_final= int(datosIngresados[2])
  18. pos_y_final= int(datosIngresados[3])
  19.  
  20. #MOVIMIENTO VERTICAL Y HORIZONTAL
  21. if pos_y_inicial==pos_y_final and abs(pos_x_inicial-pos_x_final)==1:
  22. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  23. board[pos_y_final][pos_x_final]="G"
  24. board[pos_y_inicial][pos_x_inicial]="N"
  25.  
  26. elif pos_x_inicial==pos_x_final and abs(pos_y_inicial-pos_y_final)==1:
  27. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  28. board[pos_y_final][pos_x_final]="G"
  29. board[pos_y_inicial][pos_x_inicial]="N"
  30.  
  31. #DIAGONAL DERECHA
  32. elif pos_x_inicial==pos_y_inicial and pos_x_final==pos_y_final:
  33. if pos_y_final+1==pos_y_inicial or pos_y_final-1==pos_y_inicial:
  34. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  35. board[pos_y_final][pos_x_final]="G"
  36. board[pos_y_inicial][pos_x_inicial]="N"
  37.  
  38. #CUADRADO SUPERIOR IZQ
  39. elif pos_x_inicial and pos_y_inicial and pos_x_final and pos_y_final in range(0,3):
  40. if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
  41. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  42. board[pos_y_final][pos_x_final]="G"
  43. board[pos_y_inicial][pos_x_inicial]="N"
  44. if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial-1:
  45. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  46. board[pos_y_final][pos_x_final]="G"
  47. board[pos_y_inicial][pos_x_inicial]="N"
  48.  
  49. #CUADRADO INFERIOR DERECHO
  50. elif pos_x_inicial and pos_x_final and pos_y_final and pos_y_inicial in range (2,5):
  51. if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
  52. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  53. board[pos_y_final][pos_x_final]="G"
  54. board[pos_y_inicial][pos_x_inicial]="N"
  55. if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial-1:
  56. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  57. board[pos_y_final][pos_x_final]="G"
  58. board[pos_y_inicial][pos_x_inicial]="N"
  59.  
  60. #CUADRADO INFERIOR IZQ
  61. elif pos_x_inicial and pos_x_final in range(0,3) and pos_y_inicial and pos_y_final in range(2,5):
  62. if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial-1:
  63. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  64. board[pos_y_final][pos_x_final]="G"
  65. board[pos_y_inicial][pos_x_inicial]="N"
  66. if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial+1:
  67. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  68. board[pos_y_final][pos_x_final]="G"
  69. board[pos_y_inicial][pos_x_inicial]="N"
  70. if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
  71. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  72. board[pos_y_final][pos_x_final]="G"
  73. board[pos_y_inicial][pos_x_inicial]="N"
  74.  
  75. #CUADRADO SUPERIOR DERECHO
  76. elif pos_y_inicial and pos_y_final in range(0,3) and pos_x_inicial and pos_x_final in range(2,5):
  77. if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial-1:
  78. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  79. board[pos_y_final][pos_x_final]="G"
  80. board[pos_y_inicial][pos_x_inicial]="N"
  81. if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial+1:
  82. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  83. board[pos_y_final][pos_x_final]="G"
  84. board[pos_y_inicial][pos_x_inicial]="N"
  85. if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
  86. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="G":
  87. board[pos_y_final][pos_x_final]="G"
  88. board[pos_y_inicial][pos_x_inicial]="N"
  89.  
  90. elif board[pos_y_inicial][pos_x_inicial]=="C":
  91. return False
  92.  
  93. else:
  94. return False
  95.  
  96.  
  97. if rol== "Coyote":
  98. datosIngresados= queQuiereCoyote.split(",")
  99. pos_x_inicial= int(datosIngresados[0])
  100. pos_y_inicial= int(datosIngresados[1])
  101. pos_x_final= int(datosIngresados[2])
  102. pos_y_final= int(datosIngresados[3])
  103.  
  104. #MOVIMIENTO VERTICAL Y HORIZONTAL
  105. if pos_y_inicial==pos_y_final and abs(pos_x_inicial-pos_x_final)==1:
  106. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  107. board[pos_y_final][pos_x_final]="C"
  108. board[pos_y_inicial][pos_x_inicial]="N"
  109.  
  110. elif pos_x_inicial==pos_x_final and abs(pos_y_inicial-pos_y_final)==1:
  111. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  112. board[pos_y_final][pos_x_final]="C"
  113. board[pos_y_inicial][pos_x_inicial]="N"
  114.  
  115. #DIAGONAL DERECHA
  116. elif pos_x_inicial==pos_y_inicial and pos_x_final==pos_y_final:
  117. if pos_y_final+1==pos_y_inicial or pos_y_final-1==pos_y_inicial:
  118. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  119. board[pos_y_final][pos_x_final]="C"
  120. board[pos_y_inicial][pos_x_inicial]="N"
  121.  
  122. #CUADRADO SUPERIOR IZQ
  123. elif pos_x_inicial and pos_y_inicial and pos_x_final and pos_y_final in range(0,3):
  124. if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
  125. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  126. board[pos_y_final][pos_x_final]="C"
  127. board[pos_y_inicial][pos_x_inicial]="N"
  128. if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial-1:
  129. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  130. board[pos_y_final][pos_x_final]="C"
  131. board[pos_y_inicial][pos_x_inicial]="N"
  132.  
  133. #CUADRADO INFERIOR DERECHO
  134. elif pos_x_inicial and pos_x_final and pos_y_final and pos_y_inicial in range (2,5):
  135. if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
  136. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  137. board[pos_y_final][pos_x_final]="C"
  138. board[pos_y_inicial][pos_x_inicial]="N"
  139. if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial-1:
  140. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  141. board[pos_y_final][pos_x_final]="C"
  142. board[pos_y_inicial][pos_x_inicial]="N"
  143.  
  144. #CUADRADO INFERIOR IZQ
  145. elif pos_x_inicial and pos_x_final in range(0,3) and pos_y_inicial and pos_y_final in range(2,5):
  146. if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial-1:
  147. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  148. board[pos_y_final][pos_x_final]="C"
  149. board[pos_y_inicial][pos_x_inicial]="N"
  150. if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial+1:
  151. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  152. board[pos_y_final][pos_x_final]="C"
  153. board[pos_y_inicial][pos_x_inicial]="N"
  154. if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
  155. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  156. board[pos_y_final][pos_x_final]="C"
  157. board[pos_y_inicial][pos_x_inicial]="N"
  158.  
  159. #CUADRADO SUPERIOR DERECHO
  160. elif pos_y_inicial and pos_y_final in range(0,3) and pos_x_inicial and pos_x_final in range(2,5):
  161. if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial-1:
  162. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  163. board[pos_y_final][pos_x_final]="C"
  164. board[pos_y_inicial][pos_x_inicial]="N"
  165. if pos_x_final==pos_x_inicial+1 and pos_y_final==pos_y_inicial+1:
  166. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  167. board[pos_y_final][pos_x_final]="C"
  168. board[pos_y_inicial][pos_x_inicial]="N"
  169. if pos_x_final==pos_x_inicial-1 and pos_y_final==pos_y_inicial+1:
  170. if board[pos_y_final][pos_x_final]=="N" and board[pos_y_inicial][pos_x_inicial]=="C":
  171. board[pos_y_final][pos_x_final]="C"
  172. board[pos_y_inicial][pos_x_inicial]="N"
  173.  
  174.  
  175.  
  176. print("Bienvenido al juego del collote y las gallinas")
  177. n= input("¿Quieres cargar una partida (1) o empezar de nuevo (2)?")
  178.  
  179. if n=="2":
  180. NombreJugadorCoyote= input("¡Perfecto! Dime el nombre del jugador que será el coyote:")
  181. NombreJugadorGallinas= input("Dime el nombre del jugador que será las gallinas:")
  182. print("¡Comencemos!")
  183. 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"]]
  184. if n=="1":
  185. path= input("¿Cuál es el nombre del archivo?")
  186. file= open(path,"w")
  187.  
  188.  
  189. mostrarTablero()
  190. queQuiereGallinas= 0
  191. queQuiereCoyote= 0
  192.  
  193. while queQuiereGallinas!="S" and queQuiereGallinas!="G" and queQuiereCoyote!="-1" and queQuiereCoyote!="-2":
  194. queQuiereGallinas =input("Es tu turno " + NombreJugadorGallinas +" ¿Cuál es tu movimiento? ¿o deseas guardar la partida y salir (G)? ¿o simplemente salir (S)?")
  195. while elegirNumero("Gallina") == False:
  196. queQuiereGallinas =input("Este movimiento es inválido, por favor intenta de nuevo: ")
  197. elegirNumero("Gallina")
  198. elegirNumero("Gallina")
  199. mostrarTablero()
  200. queQuiereCoyote=input("Es tu turno " +NombreJugadorCoyote + " ¿Cuál es tu movimiento? ¿o deseas guardar la partida y salir (-1)? ¿o simplemente salir (-2)?")
  201. elegirNumero("Coyote")
  202. mostrarTablero()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement