Guest User

Untitled

a guest
Nov 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. from Library_alak import *
  2. n = 0
  3. while n < 1:
  4. n = int(input('Saisir nombre de case strictement positif : '))
  5. loop = True
  6. player = 1
  7. player2 = 2
  8. removed = [-1]
  9. board = newboard(n)
  10. display(board, n)
  11.  
  12. while loop:
  13. i = select(board, n, player, removed)
  14. print(i)
  15. board = put(board, player, i)
  16. display(board, n)
  17. capture(board, n, player, player2)
  18. loop = True if again(board, n, player, removed) is True else False
  19. if player == 1 and loop:
  20. player, player2 = 2, 1
  21. elif player == 2 and loop:
  22. player, player2 = 1, 2
  23. win(board, n)
  24. print(win(board, n))
  25.  
  26. def newboard(n):
  27. board = ([0] * n)
  28. return board
  29.  
  30.  
  31. def display(board, n):
  32. for i in range(n):
  33. if board[i] == 1:
  34. print('X', end=' ')
  35. elif board[i] == 2:
  36. print('O', end=' ')
  37. else:
  38. print(' . ', end=' ')
  39.  
  40.  
  41. def capture(board, n, player, player2):
  42. for place in range(n):
  43. if place == player:
  44. place_beginning = place
  45. while board[place] != player:
  46. place_end = place
  47. if board[place + x] == player:
  48. return board
  49. else:
  50. return board
  51.  
  52.  
  53. def again(board, n, player, removed):
  54. for p in board(0):
  55. if p == 0:
  56. if p not in removed:
  57. return True
  58. else:
  59. return False
  60.  
  61.  
  62. def possible(n, removed, player, i, board):
  63. for p in range(n + 1):
  64. if p == 1:
  65. if board[p-1] == 0:
  66. if p not in removed:
  67. return True
  68. else:
  69. return False
  70.  
  71.  
  72. def win(board, n):
  73. piecesp1 = 0
  74. piecesp2 = 0
  75.  
  76. for i in board(0):
  77. if i == 1:
  78. piecesp1 += 1
  79. else:
  80. piecesp2 += 1
  81. if piecesp1 > piecesp2:
  82. print('Victory : Player 1')
  83. elif piecesp2 > piecesp1:
  84. print('Victory : Player 2')
  85. else:
  86. return 'Equality'
  87.  
  88.  
  89. def select(board, n, player, removed):
  90. loop = True
  91. while loop:
  92. print('player', player)
  93. i = int(input('Enter number of boxes : '))
  94. loop = False if possible(n, removed, player, i, board)is True else True
  95. return i
  96.  
  97.  
  98. def put(board, player, i):
  99. i -= 1
  100. if board[i] == 0:
  101. if player == 1:
  102. board[i] = 1
  103. return board
  104. else:
  105. board[i] = 2
  106. return board
  107. else:
  108. put(board, player, i)
  109.  
  110. Black and white take turns placing stones on the line. Unlike Go, this placement is compulsory if a move is available; if no move is possible, the game is over.
  111. No stone may be placed in a location occupied by another stone, or in a location where a stone of your own colour has just been removed. The latter condition keeps the game from entering a neverending loop of stone placement and capture, known in Go as ko.
  112. If placing a stone causes one or two groups of enemy stones to no longer have any adjacent empty spaces--liberties, as in Go--then those stones are removed. As the above rule states, the opponent may not play in those locations on their following turn.
  113. If placing a stone causes one or two groups of your own colour to no longer have any liberties, the stones are not suicided, but instead are safe and not removed from play.
Add Comment
Please, Sign In to add comment