Problem Description Given a square grid (a 2-D array called puzzleMap) of size 2N x 2N…
- User
Problem Description Given a square grid (a 2-D array called puzzleMap) of size 2N x 2N (N = 1, 2, 3), you need to fill the grid with L-shaped blocks with the given one empty cell.
Please note that the algorithm works in all positive integers N. We restrict N to 3 because we use 21 letters to represent at most 21 L-shapes in an 8x8 square. It is hard to have meaningful characters if N is larger than 3.
The program accepts the following inputs:
The width / height of the grid (either 2, 4, or 8). The x and y coordinates of the empty cell (which should lie within the grid). The output mode: 0: Exit directly for testing checkInput function; 1: Output Quadrant of the empty cell; 2 for console output without normalization; 3 for console output with normalization. The normalization process will be explained later. The number of L-shaped blocks:
2 x 2 square = 1 L-shapes and 1 empty cell (3 filled cells + 1 empty cell). 4 x 4 square = 5 L-shapes and 1 empty cell (15 filled cells + 1 empty cell). 8 x 8 square = 21 L-shapes and 1 empty cell (63 filled cells + 1 empty cell). Coordinate A coordinate, (x, y), can be used to represent an element in the 2-D array (e.g., puzzleMap in this assignment). The coordinate system is zero-indexed, meaning it starts from 0. It's worth noting that coordinate (x, y) corresponds to array_2d[x][y]. Please compare carefully the grid and the actual data stored in puzzleMap.
finish TODO parts in the code (C++): /*
The following program solves the L-shape blocks problem
Given A 2^N x 2^N array (In this assignment, we restrict the value N as 1, 2 and 3 ) The location of the empty cell (x,y) The legal (x,y) coordinates of the empty cell:
codeFor a 2 x 2 block, the legal range is 0-1 For a 4 x 4 block, the legal range is 0-3 For a 8 x 8 block, the legal range is 0-7 You can assume all the input values are correct Output: The empty cell (x,y) remains empty All other cells are filled by non-overlapping L-shape blocks Output mode: (0) Console output without normalization (1) Console output with normalization Author: Peter, Brian, Tommy*/
#include using namespace std;
// Constants in global scope const int MAX_WIDTH = 8; const int LOCATEQUADRANT_NOT_IMPLEMENTED = 0;
// TODO: // function locateQuadrant: // @param x: x coordinate of the empty cell // @param y: y coordinate of the empty cell // // If x < half width, y < half width, then return 1 // If x >= half width, y < half width, then return 2 // If x >= half width, y >= half width, then return 3 // If x < half width, y >= half width, then return 4 // // @return: int // The function returns after getting valid values for width, emptyXPos and emptyYPos int locateQuadrant(int width, int x, int y) {
- Assistant
In this program, we are given a square grid of size 2N x 2N, where N can be 1, 2, or 3. We need to fill the grid with L-shaped blocks, except for one empty cell. The program accepts inputs for the width/height of the grid, the coordinates of the empty cell, and the output mode. The output can be the quadrant of the empty cell, console output without or with normalization.
To solve this problem, we need to implement several functions:
-
locateQuadrant: This function takes in the width of the grid and the coordinates of the empty cell and returns the quadrant in which the empty cell lies. The quadrants are numbered from 1 to 4, starting from the top left and going in clockwise direction.
-
- User
thats why i need you to complete the todo parts
- Assistant