Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Skeleton Code: #include #define SIZE 4 #define LENGTH 21 void readGrid(int [][SIZE]); void printGrid(int [][SIZE]); int main(void) { int grid[SIZE][SIZE], target; char directions[LENGTH]; printf(Enter grid:

image text in transcribed

image text in transcribed

Skeleton Code:

 #include  #define SIZE 4 #define LENGTH 21 void readGrid(int [][SIZE]); void printGrid(int [][SIZE]); int main(void) { int grid[SIZE][SIZE], target; char directions[LENGTH]; printf("Enter grid: "); readGrid(grid); printf("Enter directions: "); printf("Enter target: "); printGrid(grid); printf("%d is formed. ", target); printf("%d is not formed. ", target); return 0; } // Read in the grid void readGrid(int grid[][SIZE]) { int i,j; for (i=0; i  Exercise 2: 2048 Game Problem Statement 2048 is a game in which the player moves numbered tiles in four possible directions (i.e., up, down, left and right) on a 4x4 grid. The objective is to merge the tiles to eventually create a tile with the number 2048. Tiles can move as far as possible in the chosen direction until they are stopped by either another tile or the edge of the grid. If a tile is stopped by another tile of the same value, both of them will merge into one tile with the total value of the two combined. Figure 1 shows a 2048 game in progress 2 4 4 16 32 8 2 Figure 1. A 2048 game in progresS In this exercise, you are to write a program 2048.c to simulate a simplified version of the 2048 game. In this simplified version, there are only two possible directions (i.e., up or left) for moving the tiles When the move direction is up, the tiles at the higher row (i.e., with lower row index) are moved before the tiles at the lower row (i.e. with higher row index) For tiles in the same row, the tile on the left (i.e., lower column index) is moved before the tile on the right (i.e., higher column index) When the move direction is left, the tiles at the left column are moved before the tiles at the right column. For tiles in the same column, the tile at the top is moved before the tile at the bottom " . No new tiles are generated after each move For example, Figure 2a shows a sample grid with non-zero values denoting the tiles and Os denoting spaces. If the direction of moving is up, the order of tiles chosen to move up is (0,1), (0,2), (1,0), (1,3)... and so on 120 02 3 02 40 Fig.2a. A sample 4x4 grid Non-zero values denote tiles and Os denote spaces Fig.2b. After the tiles at (0,1), (0,2), (1,0) and (1,3) have moved up Fig.2c. After the tiles at (2,0), (2,3), (3,1) and (3,2) have moved up

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago