は、私が2人のための三目並べのプログラムを作成したが、条件が満たされた場合、Pythonは壊れていないならば:Pythonの三目並べ - ステートメントのクエリ
def display_board(moves):
print (' ' + moves[0] + ' | ' + moves[1] + ' | ' + moves[2])
print ('---- ---- ----')
print (' ' + moves[3] + ' | ' + moves[4] + ' | ' + moves[5])
print ('---- ---- ----')
print (' ' + moves[6] + ' | ' + moves[7] + ' | ' + moves[8])
moves = (' ')
turn = 1
player = 'X'
def play_move(moves, row, col, turn):
if turn % 2 == 1:
player = 'X'
else:
player = 'O'
pos = (3 * (row - 1) + col) - 1
moves = moves[:pos] + player + moves[pos + 1:]
return moves
game_end = False
if moves[0] == moves[1] and moves[1] == moves[2] and moves[0] != ' ':
game_end = True
if moves[3] == moves[4] and moves[4] == moves[5] and moves[3] != ' ':
game_end = True
if moves[6] == moves[7] and moves[7] == moves[8] and moves[6] != ' ':
game_end = True
if moves[0] == moves[3] and moves[3] == moves[6] and moves[0] != ' ':
game_end = True
if moves[1] == moves[4] and moves[4] == moves[7] and moves[0] != ' ':
game_end = True
if moves[2] == moves[5] and moves[5] == moves[8] and moves[0] != ' ':
game_end = True
if moves[0] == moves[4] and moves[4] == moves[8] and moves[0] != ' ':
game_end = True
if moves[2] == moves[4] and moves[4] == moves[6] and moves[2] != ' ':
game_end = True
while not game_end:
display_board(moves)
row = int(input('Please enter the row number: '))
col = int(input('Please enter the column number: '))
moves = play_move(moves, row, col, turn)
turn += 1
if game_end == True:
break
Link to code in a live environment
を、実際の例をリンクし、削除キッチン。 –
すべての 'if'文を' while'ループの中に入れます。 – LuCima