Write a function called is_full(board) which accepts a board and returns True if the board is full (i.e., there are no empty spaces), and False otherwise.For example:Test Resultboard = ['....', '....', '....', '....']print(is_full(board))
Question
Write a function called is_full(board) which accepts a board and returns True if the board is full (i.e., there are no empty spaces), and False otherwise.For example:Test Resultboard = ['....', '....', '....', '....']print(is_full(board))
Solution
False
Similar Questions
def create_board(size): size = int(size) board = [[' '] * size for i in range(size)] return boarddef is_occupied(board, x, y): if x >= 0 and y >= 0 and board[x][y] != ' ': return True else: return False def place_on_board(board, stone, position): x = int(input('Please enter row line: ')) y = ord(input('Please enter column line: ')) if is_occupied(board, x, y): return False else: board[x][y] = stone return Trueboard = create_board(3)stone = "●"position = (1,2)place_on_board(board, stone, position)
Write a function called get_width(board) which accepts a list of strings representing a Connect Four board, and returns an integer representing the width of the board.For example:Test Resultboard = ['....', '....', '....', '....', '....']print(get_width(board))4board = ['......', '......', '......', '......', '......', '......', '......']print(get_width(board))6
def check_available_moves(board): available_moves = [] size = len(board) for row in range(size): # iterate go through rows for co in range(size): # iterate through column for each row if board[row][co] == ' ': #check the positoin is occupied or not available_moves.append(row, chr(co + 65)) return available_moves # return the available movesboard = create_board(9)print_board(board)check_available_moves(board)
Write a function called display_board(board) which accepts a list of strings representing a Connect Four board. The function should print the board in the following format:The first string in the board list represents the bottom row of the board and subsequent strings represent higher rows, with the last string in the list representing the top row.Each row should be printed with a vertical bar "|" before the first column and after the last column, signifying the edges of the board.Each location in the board (initially represented by ".") is separated from adjacent locations by a space.No space is used between the location and the edge of the board.Below the contents of the board is a row of hyphen characters "-" signifying the bottom of the board. This row is surrounded by vertical bars "|"A single character corresponding to the label of each column appears below the corresponding column. This row is surrounded by vertical bars "|"Each column is labelled with a single digit starting at 0 in the left column and increasing consecutively towards the right column.Notes:You can assume that the create_board(width, height) and get_width(board) functions are defined within CodeRunner for this question. However, if you submit these yourself in the answer then the tests will still work correctly (if they meet the requirements specified in earlier questions).For example:Test Resultdisplay_board(['....', '....', '....', '....'])|. . . .||. . . .||. . . .||. . . .||-------||0 1 2 3|board = create_board(9, 7)display_board(board)|. . . . . . . . .||. . . . . . . . .||. . . . . . . . .||. . . . . . . . .||. . . . . . . . .||. . . . . . . . .||. . . . . . . . .||-----------------||0 1 2 3 4 5 6 7 8|
def game_menu(): print("Game Menu: ") print("1. Start a Game") print("2. Print the Board") print("3. Place a Stone") print("4. Reset the Game") print("5. Exit") def play_game(): board = None mode = None game_in_progress = False current_player = "●" while True: game_menu() num = input('Please enter a number: ') if num == "1": if game_in_progress: print('A game is in progress.') choice = str(input('Do you want to reset and restart the game? (Y/N): ')) if choice.lower() == 'y': board = None mode = None game_in_progress = False print('Game reset.') else: size = int(input('Please enter the board size (9, 13, 15): ')) mode = int(input('Enter the number of mode you want (1.pvp or 2.pve): ')) if mode != 1 and mode != 2: print('Invalid mode, please try again.') continue board = create_board(size) game_in_progress = True print('New game start, Mode{}'.format('pvp' if mode == 1 else 'pve')) elif num == '2': if board: print_board(board) else: print('No game in progress. Start a new.') elif num == '3': if board is None: print("No game in progress, start first.") else: position = input('Please enter the position to place (row, column -- e.g. 1 B): ') position = position.split(' ') if len(position) != 2: print('Invalid format, please try again.') continue row = int(position[0]) column = ord(position[1].upper()) - ord('A') if row < 0 or row >= len(board) or column < 0 or column >= len(board): print('Invalid position, try again.') continue if not place_on_board(board, current_player, position): print('Position occupied, try again.') continue winner = check_for_winner(board) if winner: print('Player', winner, 'wins.') board = None mode = None elif len(check_available_moves(board)) == 0: print('Draw!') board = None mode = None else: current_player = "●" if current_player == "●" else "○" if mode == 1: current_player = "●" else: place_on_board(board, current_player, random_computer_player(board, position)) winner = check_for_winner(board) if winner: print('Player', winner, 'wins.') board = None mode = None game_in_progress = False else: current_player = "●" if current_player == "●" else "○" elif num == '4': board = None mode = None game_in_progress = False print('Game reset.') elif num == '5': print('Exit. Thanks for playing and enjoy.') break else: print('Invalid choose. Try again.')play_game()
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.