Am trying to print an Reversi broad given a user defined rows and columns. Am having a bit trouble with finding the center four pieces in implementing and printing the board. Here is what I have so far:
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)))
How can I find the new center pieces are place accordingly to the user input? The final board should look like this:
1 2 3 4 5 6
. . . . . .
. . . . . .
. . B W . .
. . W B . .
. . . . . .
. . . . . .
You have rectangle with size columns x rows
so the middle is in the middle of each axis: columns/2
and rows/2
.
import math
middle_start_row = math.floor(rows/2)
middle_start_col = math.floor(columns/2)