本次中国香港代写是一个Python代码修改的assignment
Your task in this question is to forbid illegal moves and detect winning/draw conditions. If
a player attempts to drop a disc in a column that is already full it is called an illegal
move. The move will be ignored at the same player will be prompted again. If player X
has won the game by being the first to form a horizontal, vertical, or diagonal line of four
of his/her own discs, the game will output Player X has won!. If player O has won the
game by being the first to form a horizontal, vertical, or diagonal line of four of his/her
own discs, the game will output Player O has won!. If there is draw, i.e., no players can
place any discs any more because the board is full, the game will output Draw!
Investigate the following sample runs to understand the I/O requirements. Test your
program extensively by playing games for various win conditions.
def createBoard():
r, c = 6, 7
if ‘n’ == input(‘Standard game? (y/n): ‘):
r, c = int(input(‘r? (2 – 20): ‘)), int(input(‘c? (2 – 20): ‘))
return [[‘·’] * c for i in range(r)]
def printBoard(board):
r, c = len(board), len(board[0])
spaces = 1
if r>9 or c>9: spaces = 2
x = ”
for row in range(r-1,-1, -1):
x += f'{row:>{spaces}}’
ss = ‘ ‘
if spaces==2: ss = ‘ ‘
for col in range(c):x += ss+board[row][col]
x += ‘ \n’
x += ‘ ‘ + ‘ ‘*spaces
for col in range(c): x += f'{col:>{spaces}}’+’ ‘
print(x)
def makeMove(board, player, col):
r = len(board)
for row in range(r):
if board[row][col]!=’·’ and board[row+1][col]==’·’:
board[row+1][col] = player
break
elif board[row][col]==’·’:
board[row][col] = player
break
board = createBoard()
printBoard(board)
player = ‘X’
while True:
move = input( ‘player’+player+’ (col #): ‘)
if move == ‘e’: break
makeMove(board, player, int(move))
printBoard(board)
if player == ‘X’: player = ‘O’
else: player = ‘X’
print(‘bye’)
程序辅导定制C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB

本网站支持 Alipay WeChatPay PayPal等支付方式
E-mail: vipdue@outlook.com 微信号:vipnxx
如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。
