Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

python program Players decide at random who moves first. In a turn, a player mus

ID: 3717039 • Letter: P

Question

python program

Players decide at random who moves first. In a turn, a player must make one of two types of move (passing is not allowed):

A normal move, in which a player moves one of their pieces from one intersection to an adjacent intersection, horizontally, vertically, or diagonally. Pieces may not jump over other pieces, and only one piece may occupy an intersection at any point in time. The circular tracks around each corner may not be used for normal moves.

To make it simpler to define test cases for your function, the board state may be defined in terms of an N-by-N string specifying the state of the board; eg, for the four-by-four game, the string 'xxxx........oooo' specifies the initial board state.

Tip: To make the relationship between a string and the corresponding board state clearer, it may help to represent the string as follows:

Remember that + concatenates two strings.

In this representation 'x' represents a black piece, 'o'represents a white piece, and '.' represents an empty location. A string is unlikely to be the most convenient internal representation for the board state: a list of lists (a nested list) is a better choice.

You have been provided with three functions to assist with converting between board strings and board states; and drawing graphical representations of the board, which may assist with developing and debugging your code and test cases:

The function get_board_state(board_string)will return a board state based on the specified board string. Board strings must be 16 or 36 characters long, and the dimension of the board state returned will be four-by-four or six-by-six respectively.

Note that you can obtain the value of a specific location from a board state (ie, black, white, or empty): the first index will be the x-coordinate (column) and the second index will be the y-coordinate (row).

The function get_board_string(board_state)will return a board string representation of the specified board state.

Question:

Write a function make_move_normal(board_string,start, end) that takes as input a string representation of the current board state, a tuple representing a the initial position of the piece to be moved (start), and a tuple representing the end position (end) the piece is to be moved to. This function will validate if the move is valid and if so, execute the move.

The function should return a string representation of the board reflecting the position of the pieces after the move if the move is valid, or None if the move is invalid.

Assumptions: Capture moves need not be considered for the purpose of this task (ie, they would be deemed invalid).

If you would like to view the visual representation, you can use the functions you have been provided

from reference import draw_sura, get_board_state, get_board_string

def make_move_normal(board_string, start, end):
# TODO implement this function.
return None


if __name__ == '__main__':
# Run the examples from the question.
print(make_move_normal('xxxx........oooo', (0, 0), (0, 1)))
print(make_move_normal('xxxx........oooo', (0, 0), (2, 2)))

Explanation / Answer

#please upvote if you like the answer it helps the community a lot.

#If you have any doubt with the code feel free to ask in comments

#if you just need the last function only copy that one

#chegg.py Code begins here

def get_board_state(board_string):
    #conversion of string to grid
    board=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
    for i in range(16):
        board[i%4][i//4]=board_string[i]
    return board

def get_board_string(board_state):
    board_string=''
    #conversion of grid to string
    for i in range(4):
        for j in range(4):
            board_string=board_string+board_state[j][i];
    return board_string

def make_move_normal(board_string, start, end):

    #conversion to board grid
    board=get_board_state(board_string)

    #testing validity of coordinates entered
    if 0<=start[0]<4 and 0<=start[1]<4 and 0<=end[0]<4 and 0<=end[1]<4 :
        #check if destination of piece is vacant
        if board[end[0]][end[1]] == '.':
            #check if the piece can reach there in one step
            if abs(start[0]-end[0])<=1 and abs(start[1]-end[1])<=1:
                #modifying board grid only if move is valid
                board[end[0]][end[1]]=board[start[0]][start[1]]
                board[start[0]][start[1]]='.'
              
    #returning it in string format
    return get_board_string(board)