T÷lvunarfrŠ­i 2

Extra project

Part 1

Now it is time to start the extra project for the students in T÷lvunarfrŠ­i 2. The project involves implementing the game Foxhunting (Refavei­ar). It will be implemented in steps, so that the final version should be quite interesting.

The Foxhunting game is played on a chess board, and only uses the black squares. There are four dogs and they start at the top of the board (on squares B8, D8, F8, and H8). There is only one fox and it starts at the bottom of the table on square E1. In each round only one dog can move diagonally (to the next black square) and the fox can move one square diagonally. The dogs can only move forward, down the table, but the fox can also move backward. The goal of the dogs is to trap the fox, but the fox tries to escape the dogs. The fox has won if it gets to row 8, but the dogs win if one of them reaches the same square as the fox.

Note again that both the dogs and the fox only travel on the black squares. The white squares are not used at all in this game. Below is a rough picture of the initial position of the game:

    A  B  C  D  E  F  G  H    
 8 |  |H1|  |H2|  |H3|  |H4| 8
 7 |..|  |..|  |..|  |..|  | 7
 6 |  |..|  |..|  |..|  |..| 6
 5 |..|  |..|  |..|  |..|  | 5
 4 |  |..|  |..|  |..|  |..| 4
 3 |..|  |..|  |..|  |..|  | 3
 2 |  |..|  |..|  |..|  |..| 2
 1 |..|  |..|  |RR|  |..|  | 1
    A  B  C  D  E  F  G  H    
In the picture the dogs are marked with H1, H2, H3, and H4, but the fox with RR. Empty black squares have ".." in them.

In this first part of the project you are to implement a program that allows two users to play the game. The program will accept moves from the users (e.g. the player with the fox might start by moving to D2, but the player with the dogs might move dog 2 to E7), then check if the moves are legal, and if so, print out the new positon. The program should also be able to determine that the game is over and announce the winner.

You can only use character-base graphics, so the picture if the board will never be very fancy, but you can the picture above as a starting point.

To maintain the playing board you are to implement the class defined below:

class VeidiBord { 
  	// The constructor builds the board and put the dogs and fox on initial squares
	// Prints the current position to standard output
	void PrentaBord();

	// Makes a dog-move, returns false if it is illegal
	bool FaeraHund( int nrHund, reitur til );

	// Makes a fox-move, returns false if it is illegal
	bool FaeraRef( reitur til );

	// Returns the position of a particular dog
	reitur StadaHunds( int nrHund );

	// Returns the position of the fox
	reitur StadaRefs();

	// Returns true if game is over
	bool LeikLokid();

	// Returns true if the dogs have won
	bool HundarSigra();

	// Returns true if the fox has won
	bool RefurSigrar();
  	// Here come the hidden variables that are needed to implement the class
The type reitur (e. square) is a pair with the values rod and dalk, defined with
struct reitur {
	int rod;
	int dalk;
	reitur( int r=0, int d=0 ): rod(r), dalk(d) { };
Please note that even though columns are indicated with letters in the input and output their inner representation is with a nunber. This is often done to simplify the programming of data structures.

You can the implement the inner part of the class VeidiBord as you want, but you have to keep the interface as described above. You also have to implement a main program that accept input from the users, enters their moves, and displays the current position.

Hand in a printout of the output of the program during a game and the source code to your section teacher before 6pm friday february 18th. They will not accept solutions that arrive later.
hh (hja) hi.is, February 7th, 2005.