Final Exam

Welcome to our final exam for the CSE 251 Lecture Introduction to programming C

Like the last exam you will get a file to download, which contains several functions. Please find the prototypes on the top, and the implementations after main. Next to the prototypes you will find the number of points a correct implementation gives you. Keep in mind that every compile error will give you -1 point, which means that I strongly suggest that you actually compile and run your code!

The code has the main function already done, and I also added a couple of functions myself to help me test your code and to provide you with a context. You will find that some of the calls to these functions do not happen, because they are commented. Please uncomment these functions if you want to test your code by yourself.

Because I want this game to be 4×4 big I defined a Macro called BoardSize which is set to 4, please always assume that the board is BoardSize times BoardSize never smaller, never bigger. Your code should run even if I set BoardSize to 5, or 3, or even 9.

This exam deals with the hypothetical game of Tic-Tac-Toc, a game similar to tic-tac-toe. You play it with three players, and take turns putting down numbers into a 4×4 grid. Each player has a number (1,2, or 3) while the 4×4 field starts out to be filled with 0 in the beginning. Each player can only set his/her number into a field that is empty. The player that either fills a row, or a column, or a square of size 2×2 anywhere in the grid wins.

Examples Three wins:
0101
2121
0202
3333

Two wins:
0201
3211
0201
3203

One wins:
1100
1123
2233
0000

You don’t have to program the entire game, but you have to complete all the functions I provided. I already defined two structures you have to use. The first is called Board, and contains a single pointer two a 2d array. Entries in the array of this structure should only be 1, 2, or 3 as they indicate which cell in the grid already belongs to which player.
The second structure I defined is called Move, it has an x and y coordinate, and a variable c which indicates the player who this move belongs to. Imagine the board is:

0000
0000
0000
0000,

and I have the Move x=1 y=1 c=1. This move applied to the current board will turn the board into:

0000
0100
0000
0000

There is another file called game.txt which contains a recorded game which at some point should be loaded and used.
The program you should write should have this naming convention:
CSE251_final_AH.c – where AH are my initials and they are to be replaced with your initials of cause.

I will call the program using game.txt as the first and only command line parameter, like so:
CSE251_final_AH game.txt

Good luck, enjoy, Arend

Here are the files:
main
game

and if you want to test your lode function independently here is a winning board file:
winningBoard

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply