私は4つのコンソールを接続し、何らかの理由でボードが "。"の代わりに0を表示しています。私は何が間違っていたのか分かりません。 3つのモジュールがありますが、根本的な問題がどこにあるかを仮定しているので、私はこのモジュールを表示します。ボードは正しく印刷されません
import connectfour
def _print_board_num():
for i in range(len(connectfour.new_game().board)):
print(str(i+1), end = ' ')
print()
def print_board(game: 'connectfour.GameState')->[(str)]:
_print_board_num()
for row in range(connectfour.BOARD_ROWS):
for column in range(connectfour.BOARD_COLUMNS):
if game.board[column][row] == ' ':
print('.', end = ' ')
else:
print(game.board[column][row], end = ' ')
print()
def move()->str:
input('Drop or Pop? ')
def column1()->int:
int(input('What number of column? '))
私のボードは次のように印刷されています
1 2 3 4 5 6 7
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
それは同じように印刷されることになっています:
1 2 3 4 5 6 7
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
これは四目並べモジュール
def _new_game_board() -> [[int]]:
'''
Creates a new game board. Initially, a game board has the size
BOARD_COLUMNS x BOARD_ROWS and is comprised only of integers with the
value NONE
'''
board = []
for col in range(BOARD_COLUMNS):
board.append([])
for row in range(BOARD_ROWS):
board[-1].append(NONE)
return board
def _copy_game_board(board: [[int]]) -> [[int]]:
'''Copies the given game board'''
board_copy = []
for col in range(BOARD_COLUMNS):
board_copy.append([])
for row in range(BOARD_ROWS):
board_copy[-1].append(board[col][row])
用ゲームボード機能であります
私はそれは、この2つのうちのどちらかです。私はプレイヤーのエラーをコメントアウトして以来、ほとんどのドロップ機能が、それはドロップ機能のために表示されます。
def player(game: 'connectfour.GameState') -> None:
while True:
player = input('Would you like to drop(d) or pop(p)?')
if player == 'd':
drop(game)
return
elif player == 'p':
pop(game)
return
else:
connectfour.InvalidMoveError(Exception)
#print('Invalid Move')
def drop(game: 'connectfour.GameState') -> bool:
try:
col = connectfouroverlap.column1()
board = connectfour.drop(game,col-1)
connectfouroverlap.print_board(board)
if gameover(board) != connectfour.NONE:
return
else:
player(board)
except:
connectfour.InvalidMoveError(Exception)
print('Invalid Move')
これは、実行時の出力です。あなたのコードをチェックした後
1 2 3 4 5 6 7
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
Would you like to drop(d) or pop(p)?d
What number of column? 2
1 2 3 4 5 6 7
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. 1 . . . . .
Invalid Move
game.boardには何がありますか? – vmonteco
@vmonteco私は、connectfourモジュールが私たちのために準備されているので、その部分は重要ではないと思います。 – accelerate
私たちがあなたを助けるために何を操作しているのかを知る必要があるからです。 – vmonteco