def makeMove(a: gameLogic.gameState, turn: str): """ Asks the user to enter a space on the board in row,col format. Then checks if its valid and places it on the board. If invalid, it remprompts. """ count = 0 while True: temp = [18, 18] # Initializing move = [] while len(move) != 2 or gameLogic.inBoard(a, turn, temp) == False: # Checks if move is in the board try: move = input( "Please select a space on the board by entering (row #,col #) like 3,4 or q to quit: " ) # Asks for the move from the user if move.upper() == "Q": os._exit(0) move = move.split(",") move[0] = int(move[0]) move[1] = int(move[1]) temp = [move[0], move[1]] except: print("Please enter a valid move") # Prints when invalid characters are used. if count > 0 and gameLogic.inBoard(a, turn, temp) == False: print("Enter a move on the board please") # Prints if not on board count += 1 legal = gameLogic.validateMove(a, turn, temp) # Validates whether the move is legal flipPieces = legal[1] # Gets the list of pieces that were to be flipped. if turn == gameLogic.BLACK: # Checks if black's turn if a.getBoard()[int(move[1]) - 1][int(move[0]) - 1] == "-" and legal[0]: # Checks if move is valid a.flipPiece(flipPieces) # Flips pieces a.makeBlack(int(move[1]), int(move[0])) # Makes new piece black break else: if ( a.getBoard()[int(move[1]) - 1][int(move[0]) - 1] == "-" ): # Checks if space is blank which means invalid move would have to been entered print("Please enter a valid move.") else: print("Please enter an unfilled space.") # Otherwise the space is taken already. else: if a.getBoard()[int(move[1] - 1)][int(move[0]) - 1] == "-" and legal[0]: # Checks if move is valid a.flipPiece(flipPieces) # Flips Pieces a.makeWhite(int(move[1]), int(move[0])) # Places new white piece break else: if ( a.getBoard()[int(move[1]) - 1][int(move[0]) - 1] == "-" ): # Checks if space is blank which means invalid move would have to been entered print("Please enter a valid move.") else: print("Please enter an unfilled space.") # Otherwise the space is taken already.
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.