ECE 272 Organization of Computers Spring 2022ECE 2220 System Programming Concepts10 of 10 Lab 4 – Arrays & Matrices – 2048 Game In this lab, each student is to write a program called p4.c that plays...

1 answer below »
I need to make a 2048 game with the arrow keys as the inputs


ECE 272 Organization of Computers Spring 2022ECE 2220 System Programming Concepts10 of 10 Lab 4 – Arrays & Matrices – 2048 Game In this lab, each student is to write a program called p4.c that plays the game “2048.” The student should exhibit a 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. 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: 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. 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 row: 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: Now, consider later in the game when four 2’s appear on row three: 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: 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: 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: 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. (I’ve gotten to 2048 many times, but I have never gotten to 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 *** ----------------------------- | | | | 4 | ----------------------------- | | | | 2 | ----------------------------- | | | | 4 | ----------------------------- | | 2 | 4 | 16 | ----------------------------- 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. Further Considerations Your program should be structured neatly, easily readable, and well commented. Furthermore, variable and function names should be such that the software is as “self-commenting” as possible. Creation and Submission Work must be completed by each individual student, and only that student. Students must not use code from another student or copied from a book or internet source. Students must not allow other students to copy from their code or make it possible for students to do so by making their code available to be copied. Sharing of code will not be tolerated and will be tested for. Any such act of cheating will result in failing the class and may result in dismissal from the University. Use the following line to compile your program gcc -Wall -g p4.c -o p4 [-lm] The code you submit must compile using the –Wall flag and no compiler errors or warnings should be printed. To receive credit for this assignment your code must compile and at a minimum perform some required function. Code that does not compile or crashes before performing some required function will not be accepted or graded. All students must do a final check on one of the CES Ubuntu machines to verify that gcc using Ubuntu shows no warning messages before submitting your project. Submit your program on Canvas before midnight on Monday, March 7th. MP1 grading criteria Name:Final score: ECE 222 MP1 grading criteria Late Deduction: Correctness 50 points Compiles Compiler warnings Runs Requires fix Errors when reading code Array boundary violation Correct input format Correct output format A series of test scripts are run against your code. Code design 25 points No global variables Named constants Header files Structured design Deviations from required design Documentation 25 points Comment block at top of each file Purpose Assumptions Known bugs Function comments Inline comments Meaningful names
Answered 5 days AfterMar 02, 2022

Answer To: ECE 272 Organization of Computers Spring 2022ECE 2220 System Programming Concepts10 of 10 Lab 4 –...

Nidhi answered on Mar 07 2022
99 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here