计算板的中心

时间:2013-11-12 17:19:46

标签: python list reversi

考虑到用户定义的行和列,我试图打印一个反转广告。在实施和打印电路板时找到中心四件有点麻烦。以下是我到目前为止的情况:

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  .  .
.  .  .  .  .  .
.  .  .  .  .  .

1 个答案:

答案 0 :(得分:0)

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

import math

middle_start_row = math.floor(rows/2)
middle_start_col = math.floor(columns/2)