C programming. Please program in C, not in any other programming language.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

C programming. Please program in C, not in any other programming language.

Post by answerhappygod »

C programming. Please program in C, not in any other programminglanguage.
C Programming Please Program In C Not In Any Other Programming Language 1
C Programming Please Program In C Not In Any Other Programming Language 1 (184.32 KiB) Viewed 48 times
C Programming Please Program In C Not In Any Other Programming Language 2
C Programming Please Program In C Not In Any Other Programming Language 2 (101.83 KiB) Viewed 48 times
C Programming Please Program In C Not In Any Other Programming Language 3
C Programming Please Program In C Not In Any Other Programming Language 3 (124.18 KiB) Viewed 48 times
C Programming Please Program In C Not In Any Other Programming Language 4
C Programming Please Program In C Not In Any Other Programming Language 4 (327.69 KiB) Viewed 48 times
C Programming Please Program In C Not In Any Other Programming Language 5
C Programming Please Program In C Not In Any Other Programming Language 5 (239.35 KiB) Viewed 48 times
C Programming Please Program In C Not In Any Other Programming Language 6
C Programming Please Program In C Not In Any Other Programming Language 6 (67.97 KiB) Viewed 48 times
Write program called p4. c that plays the game "2048." Proficiency in: ● ● ● Storing, Indexing, Searching, and Manipulating Arrays and Matrices Escape Codes Keyboard Inputs Formatted Output Performing Systematic Sequential Logic Implementing a Game Algorithm Background The game 2048 is an electronic board game that requires the user to move cells of a matrix to create a cell equal to 2048. The board is a four-by-four matrix which initially contains fourteen empty cells and two random cells containing the number 2. 2 2 The player can input an up-, down-, left-, or right-arrow key which slides all filled cells in the given direction as far they can move without overwriting a non-empty cell. If the move next to an cell with the same, number, the cell furthest in the desired direction becomes a cell filled with a number equal to the sum of the two, or twice the single cell. (Therefore, all non-empty cells will contain a number equal to a power of two.) Furthermore, after all cells are moved in a given direction as far as they can and all cells that can be combined are combined, a random non-empty cell will be filled by either a 2 or a 4. A 2 will appear 90% of the time and a 4 will appear 10% of the time. If no cells can move from an arrow input, then the board does not change including adding a new random cell.
The image below shows the above board moved down, with a new 2 created in the third row and third column: 2 row: The next image shows the board above with a right arrow entered moving the cells right which combine the 2's on the fourth row. Notice a new 2 appears in the first row and third column. 2 2 2 2 2 After playing for a while, you see the board below which has a 2 in column two on both the third and fourth row, and also a 4 in third column on both the third and fourth 2 4 2 4 4 8 4 16
So, when the user presses the down arrow, both the 2's in column two and the 4's in column three have been combined, and a new 2 is created in row three, column two, while the two in row two, column three moves down to row three: 2 4 2 2 2 4 2 Now, consider later in the game when four 2's appear on row three: 4 4 8 16 2 8 4 4 8 When a right arrow is entered, the board combines the two right 2's, and also combines the two left 2's as they are also moved right. Also a new 2 appears in the upper left: 2 32 128 4 8 4 32 128
The game ends when either a 2048 is created, as shown below where on the left I have two 1024 squares waiting to be joined, and on the right after a right-arrow produces a 2048: 2 4 16 2 2 4 2 16 4 2 32 64 8 4 64 1024 1024 8 2 16 32 16 16 64 128 32 32 256 1024 256 or the board has no empty cells and there are no more moves which will allow at least two cells to combine to one. Notice below that the board on the left can combine the two 2's, but if a new 2 is created instead of a 4, then the game will be lost as shown on the right: 2 You win! Keep going 16 2 Try again 16 6 8 N 64 2048 Try again Game over! 16 32 8 2 32 256 1024 256
Note also that the online game will let you continue to play if you want, and your program can allow that too if you wish. (The highest I've gotten to is 4096 with a score of 62,672.) 2048 Join the tiles, get to 2048! How to play → 4 64 2 SCORE 62672 BEST 62672 128 256 New Game 8 8 32 4 128 256 512 1024 4096 Input The program should look for one of six inputs: the up-, down-, left- and right-arrow keys, and a 'q' or 'Q' to quit the game. The arrow keys use multiple-byte "escape codes" for their codes and they can be different depending on the operating system. The programmer needs to look up those codes for Linux. Operation As already stated, the program should move and combine cells in the direction of the arrow key if when an up-, down-, left- or right-arrow key is input. And again, if no cells can be moved from an arrow input, the board should remain the same but be reprinted to let the user know the input was received. The program should terminate if a 'q' or 'Q' is input. Output The program should redraw the new board after each move, showing the current score and high score after each move. The board should look something like that shown below:
*** Score = 52, High Score = 52 *** I I | | 1 1 1 1 2 1 4 4 | Use the following line to compile your program 2 1 I 1 16 1 4 | The score starts at zero and is incremented every time two squares are joined. That is, when two 128 squares are combined, 256 is added to the score. The program should also notify the player when they have won or lost. If they win, they can be asked if they'd like to keep playing. After each game, the player should be asked if they would like to play again. gcc -Wall -g p4.c -o p4 [-1m]
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply