2017-11-19 3 views
-1

私はエクササイズをしており、私は立ち往生しています。これはあまり知られていないボードゲームAlakです。私はPythonでコーディングする必要があります。私はexecrciseをルールとリンクさせることができますので、より良い助けをすることができます。コードには、主要な部分とライブラリがすべての手順と機能を備えています。私はPythonでボードゲームの作成に悩まされています

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) 

だからここに私の問題は、最初のものは、私が番号を入力するときということで、私はいくつかのエラーを持っているということである「1」の番号を入力するように求め(これは、プレイする場所です)何も起こりません。他の数字を入力すると、エラーが発生します:if board [place + x] == player: NameError:名前 'x'が定義されていません :if board [place + x ] == player: NameError:名前 'x'が定義されていません

誰かが私を助けることができたら、私は多くのことを感謝します。私はそれがそうでなければならないほど詳細ではない可能性があることを意識しており、おそらくすべてを得ることはできないが、あなたはもっと私に連絡することができる。 Alakゲームの

ルール:

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.

+2

'board [place + x] == player'を発行するときにPythonに' place + x'を計算させたいのですが、Pythonに 'x'が何であるかを決して伝えませんでした。それがエラーメッセージです。 – timgeb

+1

エラーメッセージについては何が不明ですか?変数 'x'を使用しようとしていますが、' x'は存在しません。 – melpomene

+0

'loop =不可能(n、removed、player、i、board)'を書く複雑な方法です。 – melpomene

答えて

-2

あなただけのプレーヤーに応じて値1または2を取る「プレーヤー」を使用し、簡単な方法があります、変数として「player2」を使用しないでください。 x%2 == 0の場合はplayer = 1、それ以外の場合は2 xはゲームの終了まで0から増加するintです。

+0

質問に答えることができない場合は、コメントオプションを使用してください。 – mrCarnivore

関連する問題