Miniproject - First Stage Report

Dated: 30/08/2009

Problem Statement

Design the front end for eight puzzle problem using GTK+ library

The 8-puzzle game

The eight-puzzle game is a board game which appears in a 3 x 3 grid with each tile of the grid occupied by a number from 1 - 8 and the ninth tile is empty. By clicking one of the (maximum) four tiles cardinally adjacent to the empty tile, the position of the adjacent tile clicked and the empty tile can be swapped. The aim of the game is to rearrange the tiles to be in the numerical order with the empty tile at the bottom right end.

Essential Features

  • A full featured front end for the game, where the tiles can be shifted by clicking with the mouse.
  • A method to store the highest scores of a game:
    • Minimum Time wise
    • Minimum Moves wise
  • Help and About menus describing the objective of the game and credits respectively.
  • Opensource code with ample documentation such that the desirable features can be implemented by other enthusiasts.

Desirable Features

  • A method to save/load games in progress.
  • The scores file should be encrypted.
  • Extend the game to a n^2-1 game
  • A networked version where players play the same game and start together and the winner is the person who finishes earliest and another winner who solves the puzzle using minimum moves.

Solution Design

I am needing the following header files:

  • gtk/gtk.h - for standard GtkWidgets and their properties.
  • sys/time.h & time.h - for timer and random number generation.
  • stdio.h - for standard exchange of data with the system.

There will also be a configuration file to store the user settings and another file to store the highest scores.

The basic working algorithm is as follows:

  • Generate random numbers.
  • Check whether the game is solvable or not.
  • If not solvable, adjust it to make it solvable.
  • Display the tiles with the random numbers on them.
  • Let the user play the game by clicking the tiles.
  • Stop the game when the user reaches the goal state.
  • Display the score.
  • Restart the game if the user wants to.

Implementation plan

The GTK+ 2.0 library needs to be installed alongwith the basic gcc compiler.
The amount of work done so far includes generating the playing area with the random numbers generated in the solvable domain. The game can also be played by clicking the tiles just as it would be played.
It has been a 220 line code (including documentation) with 6 hrs of programming effort.
I estimate the whole coding effort will be of around .8 KLoC to 1 KLoc in total.
The expected time needed for the rest of the implementation can be broken into the following parts:
   - Coding: 8 hours
   - Testing: 6 hours
   - Documentation: 2 hours

The eight puzzle game

The extended n^2-1 puzzle game

Testing/Evaluation Plan

Testing is done incrementally. Whenever a module is developed and integrated, the testing corresponding to it is carried out. Any failure calls for a closer inspection of the code just integrated. The possible points of failure are:-
   - A non-solvable grid is generated.
   - The swapping of tiles fails for a border case.
   - The dynamic score update fails to record events properly.
   - The reached goal state goes undetected.
   - The scores file/ user settings cannot be loaded.
   - The update to the scores file is faulty.

Context

The major motivation behind choosing such a miniproject is to learn designing the desktop environment in Linux. With fundamental knowledge as gathered from this project can be later utilised to build any desktop environment in Linux using the Gtk library. A major extension of the project can be a network version as mentioned in the desirable features above. The other games as being designed as part of miniproject can be bundled as a unit of games and officially listed as gnome games.