Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Library_alak import *
- n = 0
- while n < 1:
- n = int(input('Saisir nombre de case strictement positif : '))
- loop = True
- player = 1
- player2 = 2
- removed = [-1]
- board = newboard(n)
- display(board, n)
- while loop:
- i = select(board, n, player, removed)
- print(i)
- board = put(board, player, i)
- display(board, n)
- capture(board, n, player, player2)
- loop = True if again(board, n, player, removed) is True else False
- if player == 1 and loop:
- player, player2 = 2, 1
- elif player == 2 and loop:
- player, player2 = 1, 2
- win(board, n)
- print(win(board, n))
- def newboard(n):
- board = ([0] * n)
- return board
- def display(board, n):
- for i in range(n):
- if board[i] == 1:
- print('X', end=' ')
- elif board[i] == 2:
- print('O', end=' ')
- else:
- print(' . ', end=' ')
- def capture(board, n, player, player2):
- for place in range(n):
- if place == player:
- place_beginning = place
- while board[place] != player:
- place_end = place
- if board[place + x] == player:
- return board
- else:
- return board
- def again(board, n, player, removed):
- for p in board(0):
- if p == 0:
- if p not in removed:
- return True
- else:
- return False
- def possible(n, removed, player, i, board):
- for p in range(n + 1):
- if p == 1:
- if board[p-1] == 0:
- if p not in removed:
- return True
- else:
- return False
- def win(board, n):
- piecesp1 = 0
- piecesp2 = 0
- for i in board(0):
- if i == 1:
- piecesp1 += 1
- else:
- piecesp2 += 1
- if piecesp1 > piecesp2:
- print('Victory : Player 1')
- elif piecesp2 > piecesp1:
- print('Victory : Player 2')
- else:
- return 'Equality'
- def select(board, n, player, removed):
- loop = True
- while loop:
- print('player', player)
- i = int(input('Enter number of boxes : '))
- loop = False if possible(n, removed, player, i, board)is True else True
- return i
- def put(board, player, i):
- i -= 1
- if board[i] == 0:
- if player == 1:
- board[i] = 1
- return board
- else:
- board[i] = 2
- return board
- else:
- put(board, player, i)
- 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.
- 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.
- 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.
- 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