-1

在给定用户定义的行和列的情况下,我正在尝试打印黑白棋。在实现和打印电路板时,我很难找到中心的四块。这是我到目前为止所拥有的:

def new_game_board(columns,rows) -> [[str]]:
    ''' Creates a new game board.  Initially, a game board has the size
    BOARD_COLUMNS x BOARD_ROWS and is comprised only of strings with the
    value NONE
    '''
    board = []

    for col in range(columns):
        board.append([])
        for row in range(rows):
            board[-1].append('*')
    black = (rows+1)*columns//2
    white = rows//2
    white = columns//2

    return board

def drawBoard(board,columns,rows):
    print('  '.join(map(lambda x: str(x + 1), range(columns))))
    for y in range(rows):
        print('  '.join(board[x][y] for x in range(columns)))

如何根据用户输入找到新的中心件?最终的电路板应如下所示:

1  2  3  4  5  6 
.  .  .  .  .  .
.  .  .  .  .  .
.  .  B  W  .  .
.  .  W  B  .  .
.  .  .  .  .  .
.  .  .  .  .  .
4

1 回答 1

0

您有大小为矩形的矩形,columns x rows因此中间位于每个轴的中间:columns/2并且rows/2.

import math

middle_start_row = math.floor(rows/2)
middle_start_col = math.floor(columns/2)
于 2013-11-12T17:34:54.877 回答