#ident "$Id: panex.h,v 1.4 2004/11/17 17:27:36 pwh Rel $"

/*
 * Panex puzzle object.
 */

#if	!defined ( _PANEX_PUZZLE_H_ )
#define	_PANEX_PUZZLE_H_ 

#define		PUZZLE_TITLE	"Panex Puzzle"
#define		ESC		27

/* Peg mnemonics. */
#define		LEFT_PEG	0
#define		CENTER_PEG	1
#define		RIGHT_PEG	2
#define		OTHER_PEG(a,b)	(3-(a)-(b))
 
/* Animation speed settings. */
#define		WARP_SPEED	2
#define		XTREME_SPEED	10
#define		HIGH_SPEED	20
#define		NORMAL_SPEED	50
#define		SLOW_SPEED	100

/* Solution methods. */
#define	OBVIOUS_SOLUTION		1
#define	RECURSIVE_SOLUTION		2
#define	ALTERNATING_SOLUTION		3
#define	BETTER_ALTERNATING_SOLUTION	4
#define	ZIGZAG_SOLUTION			5
#define	BETTER_ZIGZAG_SOLUTION		6
#define	BOTTOM_UP_SOLUTION		7
#define BETTER_BOTTOM_UP_SOLUTION	8
#define	EFFICIENT_SOLUTION		DEFAULT_SOLUTION
#define	DEFAULT_SOLUTION		10000

typedef struct {

	int	size;
	int	color;
	int	peg;
	int	height;
	int	solved;

} DISK;


/* Puzzle object. */
typedef struct {

	int		height;		/* Height of tower. */
	int		y0;		/* Upper left corner of puzzle space. */
	int		x0;		/* Upper left corner of puzzle space. */
	int		yc;		/* Current row being updated. */
	int		xc;		/* Center column of screen. */
	int		speed;		/* Animation speed. */
	int		warpFactor;	/* Animation speed. */
	int		moves;		/* Move count. */
	int		unsolved;	/* Number of disks out of place. */
	int		peg_tops [3];	/* Number of disks on each peg. */
	DISK		*disks [2];	/* Location of each disk. */
	DISK		**pegs [3];	/* Internal representaion of puzzle. */

} PUZZLE;


#define		isInteractive(a)	((a)->speed)
#define		isSolved(a)		(!((a)->unsolved))

int		displayPuzzle ( PUZZLE *puzzle );
void		closePuzzle ( PUZZLE *puzzle );
void		resetPuzzle ( PUZZLE *puzzle );
PUZZLE		*openPuzzle ( int height, int interactive, int speed );
int		moveDisk ( PUZZLE *puzzle, int src, int dest );

/* Solution modules. */
#define	generalSolution(a,b)	(resetPuzzle (a),displayPuzzle(a),\
				timeout(200),getch(),timeout(-1),\
				solvePuzzle((a),(b),DEFAULT_SOLUTION))

int		solvePuzzle ( PUZZLE *puzzle, int height, int solution );

/* Game module. */
int		playGame ( PUZZLE *puzzle );

#endif	/* !_PANEX_PUZZLE_H_ */


Last updated: Saturday, August 01, 2009 11:49:29 PM