Given a natural number n and a chess board with 2^n squares on each side (the length of…
- User
Given a natural number n and a chess board with 2^n squares on each side (the length of the side is 2^n, called the board size) with a missing square in any location, you will use the divide and conquer approach to design and implement an algorithm to cover the chess board (with a missing square) by an arrangement of trominoes (an L-shaped arrangement of three squares) such that all trominoes are confined to the boundaries of the chess board, and no tromino overlaps another. For the L-shaped arrangement of three squares consider a board with dimensions 22 with 4 squares inside it of 11 dimension. In the first case a first square is empty i.e. it is a missing square in the upper left corner and the other 3 squares form an L-shaped arrangement. Similarly, in the second case a missing square is there in the upper right corner, in the third case a missing square is there in the lower right corner and in the fourth case a missing square is there in the lower left corner and the other squares are L-shaped arrangement. We will use x coordinate and y coordinate to record the location of the missing square. It is convenient to treat the origin (0, 0) as the lower left corner of the board. For instance, the coordinate of the missing square in the first case is (0, 1); the coordinate of the missing square in the second case is (1, 1). You will make a function called tromino as below. void tromino /* function to do tiling / ( int x_board, / x coordinate of board / int y_board, / y coordinate of board / int x_missing, / x coordinate of missing square / int y_missing, / y coordinate of missing square / int board_size ); / size of board, which is a power of 2*/
The main program should call tromino( 0, 0, x_missing, y_missing, board_size), which allows the user to input board_size by prompting the line “Please enter size of board as a power of 2 (0 to quit):” first, then to input coordinates of missing square for x_missing and y_missing by prompting the line “Please enter coordinates of missing square (separate by a space):”. If the board size from the user input is not a power of 2, please issue a message “The board size should be a power of 2” and prompt the same user input line “Please enter size of board as a power of 2 (0 to quit):”.
For the tromino function below, void tromino /* function to do tiling / ( int x_board, / x coordinate of board */
int y_board, /* y coordinate of board / int x_missing, / x coordinate of missing square / int y_missing, / y coordinate of missing square / int board_size ) / size of board, which is a power of 2*/
you will need to set up the base case for board_size = 2. What you need to do in the base case is to decide which L shape to be put in the three squares. Please print “LR” (Lower Right) in all three squares for the L shape in first case, print “LL” (Lower Left) for the L shape in second case, “UL” (Upper Left) for the L shape in third case, “UR” (Upper Right) for the fourth L shape in fourth case.
- Assistant
- User
Please enter size of board as a power of 2 (0 to quit): 2 Please enter coordinates of missing square (separate by a space): 0 0 MS L U L this output is wrong as the input asks for the missing square which should be represented by MS to be in the 0 0 position i.e. in the lower left corner and the other parts to be filled by UR as described in the question. The correct output is Please enter size of board (need to be 2^n and 0 to quit): 2 Please enter coordinates of missing square (seperated by a space): 0 0 UR UR MS UR
- Assistant
- User
- Assistant
- User
For the L-shaped arrangement of three squares consider a board with dimensions 22 with 4 squares inside it of 11 dimension. In the first case a first square is empty i.e. it is a missing square in the upper left corner and the other 3 squares form an L-shaped arrangement. Similarly, in the second case a missing square is there in the upper right corner, in the third case a missing square is there in the lower right corner and in the fourth case a missing square is there in the lower left corner and the other squares are L-shaped arrangement. We will use x coordinate and y coordinate to record the location of the missing square. It is convenient to treat the origin (0, 0) as the lower left corner of the board. For instance, the coordinate of the missing square in the first case is (0, 1); the coordinate of the missing square in the second case is (1, 1). You will need to set up the base case for board_size = 2. What you need to do in the base case is to decide which L shape to be put in the three squares. Please print “LR” (Lower Right) in all three squares for the L shape in first case, print “LL” (Lower Left) for the L shape in second case, “UL” (Upper Left) for the L shape in third case, “UR” (Upper Right) for the fourth L shape in fourth case. For Example Please enter size of board (need to be 2^n and 0 to quit): 4 Please enter coordinates of missing square (seperated by a space): 1 3 LL MS UR UR LL LL LR UR LL LR LR LR LL LL LR LR
- Assistant
- User
Please enter size of board (need to be 2^n and 0 to quit): 2 Please enter coordinates of missing square (separated by a space): 0 0 LR LL MS UL the output that i got from the above code is wrong as according to the requirements when there is a missing square at 0 0 there L-shaped arrangement is UR. Similarly Please enter size of board (need to be 2^n and 0 to quit): 4 Please enter coordinates of missing square (separated by a space): 1 3 LR MS LR LL UR UL UR UL LR MS LR LL UR UL UR UL is also wrong as there is only 1 missing square at 1 3 position and the other L-shaped arrangements need to be arranged accordingly. The correct and expected output is Please enter size of board (need to be 2^n and 0 to quit): 2 Please enter coordinates of missing square (seperated by a space): 0 0 UR UR MS UR Please enter size of board (need to be 2^n and 0 to quit): 4 Please enter coordinates of missing square (seperated by a space): 1 3 LL MS UR UR LL LL LR UR LL LR LR LR LL LL LR LR
- Assistant
- User
Please enter size of board (need to be 2^n and 0 to quit): 2 Please enter coordinates of missing square (separated by a space): 0 0 MS LL LL LL the output of the above program you gave is incorrect as the missing square is in the 0 0 position and your program is giving the position as 0 1. The origin is (0, 0) as the lower left corner of the board. So the expected output should be Please enter size of board (need to be 2^n and 0 to quit): 2 Please enter coordinates of missing square (seperated by a space): 0 0 UR UR MS UR where MS represents the missing square at the 0 0 position and UR is the notation for the Upper right L-shaped arrangement as it has corner at the Upper right in the board. Similarly consider the expected output for Please enter size of board (need to be 2^n and 0 to quit): 4 Please enter coordinates of missing square (seperated by a space): 1 3 LL MS UR UR LL LL LR UR LL LR LR LR LL LL LR LR where MS is the missing square at the 1 3 position considering (0, 0) as the origin at the lower left corner. The LL notation stands for the Lower left L-shaped arrangement as it has corner at the lower left in the board, UR is the notation for the Upper right L-shaped arrangement as it has corner at the Upper right in the board and LR is the notation for the Lower right L-shaped arrangement as it has corner at the Lower right in the board. Your program should use x coordinate and y coordinate to record the location of the missing square. The origin (0, 0) as the lower left corner of the board. After recording the missing square (MS) the program should fill the remaining squares with Lower Left(LL), Lower right(LR), Upper left(UL) and Upper right(UR) considering the L-shaped arrangement as I had explained in the above expected outputs
- Assistant
- User
the above program that you gave is giving the output as Please enter size of board (need to be 2^n and 0 to quit): 2 Please enter coordinates of missing square (separated by a space): 0 0 UR UL MS LL which is incorrect. The missing square is placed at the correct location but the other notations are wrong. According to the L-shaped arrangement that I had explained above the correct output is Please enter size of board (need to be 2^n and 0 to quit): 2 Please enter coordinates of missing square (seperated by a space): 0 0 UR UR MS UR where MS is the missing square and UR is the notation for the Upper right L-shaped arrangement as it has a corner in the upper right of board in the L-shaped arrangement. Take the reference of the below for your better understanding. Consider in the first case there is a board with dimensions 21 dimension. The first square is empty i.e. it is a missing square in the upper left corner, so the L-shaped arrangement for this case will be LR and it will be filled at the remaining coordinates as it has the corner for the L-shaped arrangement at the lower right. Similarly, In the second case a missing square is there in the upper right corner so the L-shaped arrangement for this case will be LL and it will be filled at the remaining coordinates as it has the corner for the L-shaped arrangement at the lower left, in the third case a missing square is there in the lower right corner so the L-shaped arrangement for this case will be UL and it will be filled at the remaining coordinates as it has the corner for the L-shaped arrangement at the upper left and in the fourth case a missing square is there in the lower left corner so the L-shaped arrangement for this case will be UR and it will be filled at the remaining coordinates as it has the corner for the L-shaped arrangement at the upper right. Your program should use x coordinate and y coordinate to record the location of the missing square. The origin (0, 0) as the lower left corner of the board. After recording the missing square (MS) the program should fill the remaining squares with Lower Left(LL), Lower right(LR), Upper left(UL) and Upper right(UR) considering the L-shaped arrangement as I had explained in the above expected output.
- Assistant