Link to College home pageLink to the University home page Link to the University home page
School of Informatics logo
   
Home | News | About | Undergraduate Study | Postgraduate Study | Research | People | Search | Intranet

Advances in Programming Languages: Coursework 1

This is an assessed practical exercise. The practical exercises on the course constitute 20% of the final mark of the course. The practical exercises are equally weighted and they are individual practical exercises. This means that your submission should be entirely your own work unless you declare it to be otherwise. Please see the School of Informatics guidelines on plagiarism for further clarification.

1. Task

You have been hired by Advanced Software Ltd to produce an open-source version of one of their popular games, which they no longer wish to maintain. The problem with the game at present is that it uses unsafe coding practices. Advanced Software Ltd is worried that their share price may fall if it becomes public that some of their developers sometimes use unsafe programming techniques, so a rewrite is necessary. In order to maintain the reputation of the company as a top-shelf software house your program should be portable across the Windows and Linux platforms.

Your task is to modify a C# version of Minesweeper that was ported from the highly-regarded Minesweeper game developed by Chailloux, Manoury and Pagano for the O'Reilly book Développement d'applications avec Objective Caml (version written in Objective Caml). The programmers on the project, who have had mainly C programming experience, have made frequent use of the unsafe keyword in C# to gain access to certain language features. Your project manager believes that none of these unsafe contexts are really necessary, and all could have been coded safely. You are to rewrite the program so that no remaining parts are marked with unsafe. Your refactored application is expected to look and behave as it did before you modified it.

At present, the application will only compile when the unsafe flag for the C# compiler is enabled. Your final program should compile without using this as it should have no code marked as unsafe.

2. Compiling and Running the Application

Start by downloading the application source code contained in the Game.cs file. The program can be compiled and executed under both Windows and Linux. You have a choice of which one you use whilst completing the practical, but bear in mind that your result should be portable. In particular, it should compile using Mono on a Linux machine, not only under the latest release of VisualStudio. However, choose whichever development environment you prefer, or you are most used to.

The Minesweeper application depends on a graphics library called GTK#. If you wish to develop on your own machine you will need to get a copy of this library and a C# compiler.

2.1 Developing on a Linux DICE machine

The GTK# libraries are expected to be available under DiCE. Check this using the following command:
rpm -ql gtk-sharp gtk-sharp-devel
If you get the message package gtk-sharp is not installed or package gtk-sharp-devel is not installed then you should contact Informatics support providing a full explanation of the problem. (Use this form.)
  1. To compile the program, type:
    mcs -r:gtk-sharp --unsafe Game.cs
  2. To run the program, type:
    mint Game.exe

When the program code no longer contains any unsafe keywords, you can remove the --unsafe switch from step 1. At that point the program may also work with the Mono JIT so you can try also mono Game.exe. Unsafe code is unlikely to work with the Mono JIT.

2.2 Developing on your own Linux machine

Make a copy of this release of GTK# or (at your peril) another version. Do the configure-make-install dance and then proceed with compiling and running as above.

2.3 Developing with the Mono compiler under Windows

The Mono C# compiler is freely available for Windows.
  1. Download and install the Mono and GTK# installer.
  2. Open a command-line prompt and change to the directory containing the program file.
  3. Set the path environment variable so that the Mono command-line tools are available by typing:
    set PATH=%PATH%;"C:\Program Files\Mono-1.0.5\bin\"
  4. To compile the program, type:
    mcs -pkg:gtk-sharp -target:winexe -unsafe Game.cs
  5. To run the program, type:
    mono Game.exe

When the program code no longer contains any unsafe keywords, you can remove the -unsafe switch from step 4.

2.4 Developing with VisualStudio.NET under Windows

If you have a copy of the (non-free) software VisualStudio.NET you can use the following development sequence.
  1. Install .NET SDK 1.1 from msdn.microsoft.com/downloads if VS.NET is not installed. Install the GTK# Win32 runtime.
  2. Open a command-prompt.
  3. set PATH=%PATH%;C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322;C:\Program Files\Common Files\GtkRun\2.4\bin
    for path to csc.exe and libgtk-win32-2.0-0.dll
  4. set LIB=%PATH%;C:\Program Files\Common Files\GtkRun\2.4\lib\gtk-sharp-2.0
    for path to gtk-sharp
  5. Compile with: csc /r:gtk-sharp.dll,atk-sharp.dll,glib-sharp.dll /unsafe Game.cs
  6. Run with: Game.exe

Deadline

This coursework exercise has been issued on Thursday 3rd February 2005 and is due for submission on Thursday 17th February 2005 at 5:00pm. Submit your code using the command submit cs4 apl 1 Game.cs.

This page maintained by Stephen Gilmore.
Last modified: Fri Mar 11 12:24:43 GMT 2005
Last CVS commit: Fri Mar 11 12:24:45 GMT 2005

School of Informatics, Appleton Tower, Crichton Street, Edinburgh, EH8 9LE, Scotland, UK
Tel: +44 131 650 2691, Fax: +44 131 650 6513, E-mail: hod@inf.ed.ac.uk
Please contact our webadmin with any comments or corrections.
Unless explicitly stated otherwise, all material is copyright © The University of Edinburgh