def printBoard(a: gameLogic.gameState, count: int): """ Prints the current board with the row and column numbers. It uses unicode to print black dots for black and white one for white and '-' for blank spaces. Then it prints the score and whose turn it is. """ blackCount, whiteCount, rowNum, colNum = 0, 0, 1, 1 B = u" \u25CF " # Black dot W = u" \u25CB " # White dot print("=================================================") # Division between each board print print("\t Current Board:") print("=================================================") # Division between each board print topRow = "" print(" ", end=" ") for col in range(0, a.getCol()): # Prints the column numbers at the top of the board if col < 9: # To format spaces properly add 0 before all single digits. print("0{}".format(colNum), end=" ") colNum += 1 else: print("{} ".format(colNum), end="") # Prints two-digit column numbers. colNum += 1 print() for row in range(0, a.getRows()): # Runs through rows currentRow = "" for col in range(0, a.getCol()): # Runs through columns if a.getBoard()[col][row] == gameLogic.NONE: # Checks if space is empty and places '-' in it if true currentRow += " - " elif a.getBoard()[col][row] == gameLogic.BLACK: # Places black dot if piece is black currentRow += B blackCount += 1 elif a.getBoard()[col][row] == gameLogic.WHITE: # Places white dot if piece is white currentRow += W whiteCount += 1 if rowNum < 10: # Formats column numbers if less than 10 print("0{}".format(rowNum), end="") print(currentRow) rowNum += 1 else: # Formats colum numbers with two digits. print("{}".format(rowNum), end="") print(currentRow) rowNum += 1 print("BLACK: {}\tWHITE: {}".format(blackCount, whiteCount)) # Prints current score of black and white gameLogic.checkWin(a, a.getTurn(), count) # Checks if game has ended printTurn(a) # Prints whose turn it is.
def _redraw_board(self) -> None: ''' Redraws the board. It deletes everything previously on the window and then adds player 1, player 2 player turn and winner labels onto the grid. Then it redraws the board with the correct grid size and the new pieces. ''' state = self._state#game state self._canvas.delete(tkinter.ALL)#deletes everything on the board canvas_width = self._canvas.winfo_width()#Canvas width canvas_height = self._canvas.winfo_height()#canvas height self._player2 = tkinter.Label(self._root_window, text = 'BLACK: \n'+state.getBlackCount())#Label for black player and score self._player2.grid(row = 0, column = 2, padx = 20, pady = 10,#Puts it on grid sticky = tkinter.W) self._player1 = tkinter.Label(self._root_window, text = 'WHITE: \n'+state.getWhiteCount())#Label for white player and score self._player1.grid(row = 0, column = 1, padx = 20, pady = 10,#Puts it on the grid sticky = tkinter.W) if gameLogic.checkWin(state,state.getTurn(),1)=='':#If no winner self._playerTurn = tkinter.Label(self._root_window, text = 'It is '+state.getGuiTurn()+"'s turn.")#Label for player turn self._playerTurn.grid(row=0,column=1,padx=10,pady=10,#Puts it on the grid sticky = tkinter.N) self._winner = tkinter.Label(self._root_window, text = gameLogic.checkWin(state,state.getTurn(),1))#Label for winner self._winner.grid(row=0,column=1,padx=10,pady=10,#Puts it on the grid sticky = tkinter.S) else: self._playerTurn = tkinter.Label(self._root_window, text = ' ')#Label for player turn self._playerTurn.grid(row=0,column=1,padx=10,pady=10,#Puts label on the grid sticky = tkinter.N) self._winner = tkinter.Label(self._root_window, text = gameLogic.checkWin(state,state.getTurn(),1))#Label for winner self._winner.grid(row=0,column=1,padx=10,pady=10,#Puts it on the grid sticky = tkinter.S) for i in range(0,self._state._rows):#Prints the board for x in range(0,self._state._col): self._canvas.create_rectangle(x*(canvas_width)/self._state._col,i*canvas_height/self._state._rows,(x+1)*(canvas_width)/self._state._col,(i+1)*canvas_height/self._state._rows) for spot in self._spaces:#Prints the pieces on the board self._canvas.create_oval(spot[0]*(canvas_width),spot[1]*canvas_height,spot[2]*(canvas_width),spot[3]*canvas_height,outline = spot[4],fill = spot[5])