Question: Please help me with this python code, I need help with the part written in BOLD. I want the body the function # The next

Please help me with this python code, I need help with the part written in BOLD. I want the body the function

Please help me with this python code, I need help with the

# The next several lines contain constants for you to use in your code.

# You must use these constants instead of the values they refer to.

# For example, use SQUARE_BLACK instead of '-'.

# You may not need to use all of the constants provided.

# Do NOT change the values these constants refer to.

NUM_COL = 5 # Number of columns in the game board

NUM_ROW = 4 # Number of rows in the game board

SQUARE_BLACK = '-' # The character that represents a black square

SQUARE_RED = 'R' # The character that represents a red square

SQUARE_YELLOW = 'Y' # The character that represents a blue square

DIR_ACROSS = 'across' # The horizontal direction

DIR_DOWN = 'down' # The vertical direction

DIR_DOWN_RIGHT = 'dright' # The diagonal direction: downward and rightward

DIR_DOWN_LEFT = 'dleft' # The diagonal direction: downward and leftward

# This function is completed for you as an example and you MUST NOT change it.

def create_empty_board() -> str:

"""Return a string representation of a game board of all empty symbols with

NUM_ROW rows and NUM_COL columns.

"""

return SQUARE_BLACK * NUM_ROW * NUM_COL

def is_board_full(game_board: str) -> bool:

"""Return True if and only if the game_board is full.

A game_board is full when it doesn't contain any SQUARE_BLACK characters.

>>> is_board_full('R--------YR----Y----')

False

>>> is_board_full('RYYRYYRYYRYYRYYRYYRY')

True

"""

# Write your code for the is_board_full function here

return SQUARE_BLACK not in game_board

def between(value: str, min_value: int, max_value: int) -> bool:

"""Return True if and only if value is between min_value and max_value,

inclusive.

Preconditions:

- value can be converted to an integer without error

- min_value

>>> between('2', 0, 2)

True

>>> between('0', 2, 3)

False

"""

# Write your code for the between function here.

return min_value

# Write the rest of your functions here.

def calculate_str_index(row:int, col:int) -> int:

"""Return index in the string representaion of the game board corresponding

to the given row and column.

>>> calculate_str_index (4, 5)

19

>>> calculate_str_index (4, 2)

16

"""

return (row - 1) * NUM_COL + (col - 1)

def calculate_increment(direction: str) -> int:

""" Returns how many increments needed to acheive the movement in

the four directions: DIR_DOWN, DIR_ACROSS, DIR_DOWN_RIGHT, or DIR_DOWN_LEFT.

>>> calculate_increment(DIR_DOWN)

5

>>> calculate_increment(DIR_DOWN_LEFT)

4

"""

5. Function: calculate_increment(str) -> int Specification: This function has one parameter. The parameter refers to a string that describes one of the four directions: down, across, down- right, or down-left. Assume that the str value is one of: DIR_DOWN , DIR_ACROSS , DIR_DOWN_RIGHT or DIR_DOWN_LEFT . The game board size is given by the constants NUM_ROW and NUM_COL . This function returns the difference between the str indices of two adjacent squares on a line that goes in the direction specified by the first parameter. j Notes: O Follow the Function Design Recipe to complete this function. o Re-read the Winning the game section to better understand the four different directions. o Re-read the Accessing a square in the game board section if you are stuck

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!