I have an excercise to do and I'm stuck. It's the board game Alak, not much known, that I have to code in python. I can link the excercise with the rules so you can help me better. The code has the main part and the library with all the procedures and function.
And here is the library:
So my problems here are that I have few errors, the first one is that when I enter the number '1' when asked to enter a number of boxes ( which is the place to play on ) nothing happens. Then when entering any other number, either the error is : if board[place + x] == player: NameError: name 'x' is not defined or there seems to be a problem with the : if board[place + x] == player: NameError: name 'x' is not defined
I would appreciate a lot if anyone could help me. I'm conscious that it might not be as detailed as it should be and that you maybe don't get it all but you can contact me for more.
Rules of the Alak game:
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.
Moderators note : Removed hidden commercial link
Code:
fromLibrary_alakimport*
n =0while 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 =Trueif again(board, n, player, removed)isTrueelseFalseif player ==1and loop:
player, player2 =2,1elif player ==2and loop:
player, player2 =1,2
win(board, n)print(win(board, n))
Code:
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 notin removed:returnTrueelse:returnFalse
def possible(n, removed, player, i, board):for p in range(n +1):if p ==1:if board[p-1]==0:if p notin removed:returnTrueelse:returnFalse
def win(board, n):
piecesp1 =0
piecesp2 =0
for i in board(0):if i ==1:
piecesp1 +=1else:
piecesp2 +=1if piecesp1 > piecesp2:print('Victory : Player 1')elif piecesp2 > piecesp1:print('Victory : Player 2')else:return'Equality'
def select(board, n, player, removed):
loop =Truewhile loop:print('player', player)
i = int(input('Enter number of boxes : '))
loop =Falseif possible(n, removed, player, i, board)isTrueelseTruereturn i
def put(board, player, i):
i -=1if board[i]==0:if player ==1:
board[i]=1return board
else:
board[i]=2return board
else:
put(board, player, i)
I would appreciate a lot if anyone could help me. I'm conscious that it might not be as detailed as it should be and that you maybe don't get it all but you can contact me for more.
Rules of the Alak game:
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.
Moderators note : Removed hidden commercial link
Last edited by a moderator: