CSC231 Homework 9

From dftwiki3
Revision as of 17:39, 13 November 2008 by Thiebaut (talk | contribs)
Jump to: navigation, search

(c) --DT 13:42, 30 October 2008 (UTC)

The deadline for this assignment is Fri. Nov 20th, at 11:59 p.m. plus 1 minute. You may work in pairs on this assignment, in which case you can submit only one program with two names in the header.

CSC231 Tetrix.png


Expert at Tetris...

You have this friend who spends a great deal of time playing games on the computer, and who brags about her expertise at playing Tetris. Also brags at how much better a it she is than you are.

So, what do you do?

You use your computer skills to play a cool trick on her! You modify the program so that when the game shows the top ten scores, your name always appears as the top score, with a score of 10 points higher than the next score! Now, the next time she plays the game she will see think you have played since the last time she did, and that you do better than the best score (probably hers) by 10 points! Cool, no?

Downloading the game

First download and install the game in a folder called tetris, following these steps (you really should be doing this on a Linux box, ssh-ing to Beowulf using the command ssh -Y 231a-xx@beowulf.csc.smith.edu.

         cd 
         cp  ~thiebaut/public_html/classes/231/tetrix.tgz  .
         tar -xzvf tetrix.tgz
         cd  tetrix
         qmake 
         make


Do not forget the dot at the end of the cp command.

The first line insures that you are in your home directory. The second line makes you copy an archive file from my directory to yours. The third line extracts the archive to a folder named tetrix. The fourth line makes you enter the folder tetrix. The fifth and sixth line make you compile the program and generate an executable file, the game, named tetrix.

Verify that the game works (by the way, the game uses graphics, and will work only if you are logged in to your account on a Linux box, not through Windows.)

            ./tetrix abc


where you should replace abc by your initials. Play for a while, then quit the game. Verify that the highest scores are displayed in the shell window where you started the game. The game only keeps the all-times 10 highest scores, which are located in a file called scores.dat.

Play the game several times using different initials to create a record of 10 scores.

File format

You will need to figure out the way the information is stored in the score.dat file. Linux sports a command to examine the contents of files: od, for octal dump. Try this (the user input is in boldface):

            cd
            cd tetrix
            od -tx1 scores.dat
            0000000 41 41 41 97 00 00 00 42 42 42 9e 00 00 00 43 43
            0000020 43 7e 00 00 00 44 44 44 73 00 00 00 44 46 54 80
            0000040 00 00 00 46 46 46 96 00 00 00
            0000052


You can get more information on the od command by typing man od at the prompt.

Grab an ASCII table and a printout of the scores output when you last played your game. Compare the two to the output of the od command: you should be able to figure out how the information is stored in the file.

When you read the scores file in a buffer in memory, using the Linux System Calls we saw in class, the information returned to you by od will occupy consecutive bytes in the buffer, in the same order shown by the od command. You should be able to easily access the different pieces of information you are interested in (initials and scores).

Your assignment

Write a program in assembly (with the driver.c wrapper) called hw9.asm that will

  1. Read the file scores.dat,
  2. Sets your initials as the initials of the player with the highest score, such that this score is 10 points higher than the original highest score.
  3. Store the buffer back to the file such that the tetris game will recognize it as a valid score file.

We assume that the score file contains only unique initials. Therefore it is illegal for the score file to have two sets of identical initials associated with two scores.

If the file didn't originally contain your initials, your program will replace the lowest scoring player and replace his/her information by yours.

If the file already contains your initials, but you are not the highest scoring player, the program will make you so.

If the file already contains your initials, and you are the highest scoring player, even if the score is more than 10 points higher than the next highest, the program will not modify the file.

To make the grading and testing easier, plase use "231" as the initials your program uses as yours.

Submission

Submit your program as follows:

         submit hw9 hw9.asm


Final details

If you really want to fool your friend, you will have to perform a simple modification: modify the name of the original tetris program (say, tetrixorg), and create a shell file with the original name.

Here's a way to do this.

          cd 
          cd tetrix
          mv tetrix tetrixorg


Then use emacs to create a shell file called tetrix with the following information in it:

          #!/usr/local/bin/bash
          ./hw9
          ./tetrixorg


and make it executable:

          chmod a+rx tetrix

Now go ahead and play the game as usual (./tetrix). You should verify that Player 231 is very very good!

Observations

The Tetris game you are using was taken from Trolltech's Qt3 example programs which are distributed free of charge by Trolltech. The game is written in C++ using the Qt libraries. I modified the program and added two files (scores.h and scores.cpp) so that it keeps track of the 10 highest scores.

Normally you wouldn't have access to the source code of a game, and the type of modification that you are performing here would be the simplest one to implement. But for this assignment, however, you have access to the source code for the game. Feel free to look at the C++ code if you feel like it. You can even modify it and recompile it if you want to add debugging statements of any kind. Just remember, though, that your assembly program should work with the original game, not a modified version of it!

Your program should work with a score file containing between 0 and 10 scores!