######################################################################## # This fxn provided by Dr. Gibson, and may be modified as you see fit. # ######################################################################## # prettyPrintBoard() prints the board with row and column labels, # # and spaces the board out so that it looks square # # Input: board; the rectangular 2d gameboard to print # # Output: none; prints the board in a pretty way # def prettyPrintBoard(board): # if board is large enough, print a "tens column" line above the rows if len(board[0]) - 2 >= 10: firstLine = "\n " + (" ") * (10 - 1) for i in range(10, len(board[0])-1 ): firstLine += str(i // 10) + " " print(firstLine, end="") # create and print top numbered line (and empty line before) topLine = "\n " # only go from 1 to len - 1, so we don't number the borders for i in range(1, len(board[0])-1 ): # only print the last digit (so 15 --> 5) topLine += str(i % 10) + " " print(topLine) # create the border row borderRow = " " for col in range(len(board[0])): borderRow += board[0][col] + " " # print the top border row print(borderRow) # print all the interior rows for row in range(1, len(board) - 1): # create the row label on the left rowStr = str(row) + " " # if it's a one digit number, add an extra space, so they line up if row < 10: rowStr += " " # add the row contents to the row string, and print it out for col in range(len(board[row])): rowStr += str(board[row][col]) + " " print(rowStr) # print the bottom border row and an empty line print(borderRow) print()