In this assignment you will write a C program 2048.c to implement the recently developed game 2048
2048 has been most popular as Javascript web application.
You will write a command line program which display the game in ASCII.
This assignment is largely specified by a reference implementation available on CSE machines.
/home/rz9280/bin/2048 Enter 16 numbers making up initial board: 0 0 0 0 0 0 2 0 8 0 2 4 0 0 2 4 Repeat game by running: /home/rz9280/bin/2048 1399537570 Enter h for left, j for down, k for up, l for right, q to quit +------------------------+ | . . . . | | | | . . 2 . | | | | 8 . 2 4 | | | | . . 2 4 | +------------------------+ Your score is 0. > j +------------------------+ | . 2 . . | | | | . . . . | | | | . . 2 . | | | | 8 . 4 8 | +------------------------+ Your score is 12. >
You must use the reference implementation to understand what is required for this assignment.
An important part of the assignment is analysing the requirements by running the reference implementation and exploring its behaviour.
You must use the reference implementation to understand what is required for this assignment. It is important that you match the output from this reference implementation exactly (character-for-character). If you believe the reference implementation behaves inappropriately raise this with Angela via the course message board.
The file 2048.c contains starting point code which you must use for this assignment.
You cannot change some of the code in 2048.c.
Do not change the code in the functions main, insertNewNumber and printHelp
Note insertNewNumber depends on a vacant square containing the value 0 so you must use this representation.
There are 8 functions moveLeft, moveRight, moveDown, moveUp, gameOver, boardContains2048, printBoard, readBoard which you must implement.
Do not change the type of these functions - just change the function body. You can change the code provided for the function bodies - this code (return statements) is provided to allow the starting point code compiles.
You may (should) add your own functions to 2048.c.
Your code must work if the SIZE constant changed. So for example if it it is changed to 10. You code should work with a 10x10 board. You can assume b>SIZE >= 2.
The boardContains2048 function can be implemented simply.
Get one of the move functions e.g. moveLeft working before attempting the other move functions..
You can use dryrun to test your program like this:
/home/rz9280/bin/dryrun 2048
Dryrun can produce a very large amount of output for this assignment So you may need to pipe it to more which will let you scroll through it:
/home/rz9280/bin/dryrun 2048 | more
Or you may need to use dryrun's optional second argument to specify that only a single test should be run:
/home/rz9280/bin/dryrun 2048 0
The first 2 dryrun tests check readBoard/printBoard so run them ASAP.
The code you've been supplied pseudo-randomly places new numbers on the board. By default this will occur differently for every or this execution of the program. This can confuse debugging & testing
If you specify an integer command-line argument - this will be used used to seed (initialize) the pseudo-random number generator. This allows executions of the program to be made repeatable
Given the same starting position and the same moves, if the same seed is specified on the command line then the new numbers will be placed in the same squares.
The dryrun tests specify an integer command-line argument for this reason.
You can request the operating system send individual characters immediately to your program (unbuffered I/O). This has not been incorporated in the code you have been given because it would require including compiler and operating system dependant code which might intefere with students developing on their own computers.
On Linux it is also possible to request unbuffered I/O from the operating system by running a separate program stty, before you run 2048. For example:
stty -icanon /home/rz9280/bin/2048 .... stty icanonNote this produces more enjoyable game-play on Linux but has absolutely no effect on the code you must write for the assignment!
Date | Start | Stop | Activity | Comments |
---|---|---|---|---|
29/04 | 16:00 | 17:30 | coding | implemented exit |
30/04 | 20:00 | 10:30 | debugging | found bug in for loops |
This assignment will contribute 30% to your final mark.
Style marks for the assignment will come from hand marking of the readability of the C you have written. These marks will be awarded on the basis of clarity, commenting, elegance and style. In other words, your tutor will assess how easy it is for a human to read and understand your program.
This will be based on the performance of your program. It will be automatically tested on a large number of inputs and will receive marks according to how many times it produces the correct output.
Do not provide or show your assignment work to any other person, apart from the teaching staff of REGZ9280. If you knowingly provide or show your assignment work to another person for any reason, and work derived from it is submitted you may be penalized, even if the work was submitted without your knowledge or consent. This may apply even if your work is submitted by a third party unknown to you.
Note, you will not be penalized if your work is taken without your consent or knowledge.
Submit the assignment using this give command:
regz9280 classrun 14s2 give assn 2048.c diary.txt
If your assignment is submitted after this date, each day it is late reduces the maximum mark it can achieve by 1 mark per day for the first day and 2 marks per day after that. No submissions will be accepted after Friday 9th August 23:59:59.