Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. #***************#
  2. # Fonctions #
  3. #***************#
  4.  
  5. def newBoard(n):
  6. Listes = []
  7. #Vertical
  8. for i in range (0,n): #Création des sous listes
  9. Listes.append([])
  10.  
  11. #Horizontal
  12. for y in range(0,n): #Création du carré
  13.  
  14. #Magnifique Carré
  15. if y == 0:
  16. Listes[i].append(1)
  17. elif y == n-1:
  18. Listes[i].append(2)
  19. elif i == 0 and y != 0:
  20. Listes[i].append(2)
  21. elif i == n-1:
  22. Listes[i].append(1)
  23. else :
  24. Listes[i].append(0)
  25. return Listes
  26.  
  27.  
  28. def displayBoard(board,n):
  29. for i in range(n): #Parcourir les listes
  30. print("")
  31. for i,player in enumerate(board[i]): # Enumerer les éléments
  32. if player == 1: # Point blanc = 'x' = 1
  33. print("x", end=' ')
  34. elif player == 2: # Point noir = 'o' = 2
  35. print("o", end=' ')
  36. else: # Case vide = '.' = 0
  37. print(".", end=' ')
  38.  
  39.  
  40. #***************#
  41. # Pawn #
  42. #***************#
  43.  
  44. def possiblePawn (board,n,player,i,j):
  45. # Vérification du pion dans le tableau
  46. if ( i < n and i >= 0 ) and (j < n and i >= 0) :
  47. if board[j][i] == player == 1:
  48. if board [j-1][i] == 0: # Haut
  49. return True
  50. if board [j][i-1] == 0: # Gauche
  51. return True
  52. if board [j][i+1] == 0: # Droite
  53. return True
  54. if board [j+1][i] == 0: # Bas
  55. return True
  56.  
  57. if board[j][i] == player == 2:
  58. if board [j-1][i] == 0: # Haut
  59. return True
  60. if board [j][i-1] == 0: # Gauche
  61. return True
  62. if board [j+1][i] == 0: # Bas
  63. return True
  64. if board [j][i+1] == 0: # Droite
  65. return True
  66. return False
  67. return False
  68. return False
  69.  
  70.  
  71.  
  72.  
  73. def selectPawn(board,n):
  74. j = int(input("\n(Pawn (j)) - Choisir votre ligne :"))-1
  75. i = int(input("(Pawn (i)) - Choisir votre colonne :"))-1
  76. while possiblePawn(board,n, player, i, j)== False:
  77. print("(Pawn) - Votre pion ne peut pas se déplacer")
  78. j = int(input("\n(Pawn (j)) - Erreur ! Choisir votre ligne :"))-1
  79. i = int(input("(Pawn (i) ) - Erreur ! Choisir votre colonne :"))-1
  80. else:
  81. print("(Pawn) - Selection OK.")
  82. return j,i
  83.  
  84.  
  85. #***************#
  86. # Destination #
  87. #***************#
  88.  
  89.  
  90. def possibleDestination(board,player,n,i,j,k,l):
  91. #Vérifier si la Destination est possible
  92. if ( l >= 0 and l < n ) and (k >= 0 and k < n) : # Vérification - Le joueur reste bien dans le tableau
  93. if board[k][l] == 0: # Vérification - Il se deplace bien sur un pion
  94.  
  95. if j == k: #Lignes
  96. for Pion_Sauter in range (j+1,l+1):
  97. print(board[k][Pion_Sauter])
  98. if board[k][Pion_Sauter] == 1 or board[k][Pion_Sauter] == 2:
  99. return False
  100. return True
  101.  
  102. if i == l: #Colonne
  103. for Pion_Sauter in range (i+1,k+1):
  104. if board[l][Pion_Sauter] == 1 or board[l][Pion_Sauter] == 2:
  105. return False
  106. return True
  107. return False
  108. return False
  109. return False
  110. return False
  111.  
  112.  
  113.  
  114. def selectDestination(board,n,i,j):
  115. k = int(input("\n(Destination(k)) - Choisir votre ligne:"))-1
  116. l = int(input("(Destination(l)) - Choisir votre colonne:"))-1
  117. while possibleDestination(board,player,n,i,j,k,l) == False:
  118. k = int(input("\n(Destination (k) ) - ERREUR ! Choisir votre ligne :"))-1
  119. l = int(input("(Destination(l)) - ERREUR ! Choisir votre colonne:"))-1
  120. else:
  121. print("(Destination) - Selection Ok.")
  122. return k,l
  123.  
  124.  
  125. def move(board,n,player,i,j,k,l):
  126. #Déplacement du pion - Remplacer le pion 0 par 1 ou 2
  127. #Joueur 1 - Déplacement du pion
  128. if player == 1:
  129. if board[j][i] == 1:
  130. board[j][i] -= 1
  131.  
  132. if board[k][l] == 0:
  133. board[k][l] += 1
  134.  
  135. #Joueur 2 - Déplacement du pion
  136. if player == 2:
  137. if board[j][i] == 2:
  138. board[j][i] -= 2
  139.  
  140. if board[k][l] == 0:
  141. board[k][l] += 2
  142.  
  143.  
  144. # Capture des Pions
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153. def lose(board,n,player):
  154. sdfsd
  155. #***************#
  156. # Variables #
  157. #***************#
  158. n = int(input("Nombre de lignes/colonnes : "))
  159. i = 0
  160. j = 0
  161. k = 0
  162. l = 0
  163. compteur = 0
  164. player = 0
  165. #****************#
  166. # Main Programme #
  167. #****************#
  168. while n < 3:
  169. n = int(input("ERREUR ! Votre chiffre est trop petit (Minimum 3) : "))
  170.  
  171. board = newBoard(n)
  172. displayBoard(board,n)
  173. while compteur != 10:
  174.  
  175. if player == 1: #Joueur 2
  176. player += 1
  177. else:
  178. player = 1
  179.  
  180. print("\nAu tour du joueur ", player)
  181. j,i = selectPawn(board,n)
  182. k,l = selectDestination(board, n, i, j)
  183. move(board,n,player,i,j,k,l)
  184. displayBoard(board,n)
  185. compteur+=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement