/*

File LeapfrogSquare.m

These are the squares used for leapfrog search.  When backjumping past a square, the square remembers its current value and tries that value first the next time through.

*/

#import <appkit/appkit.h>

#import "Leapfrog.h"
#import "Crossword.h"
#import "Puzzle.h"


/* 行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行  */


#define position(i)		((wordPosition *) [words  elementAt: i])
#define forword(c)		((c) == WILDCARD ? (c):(c) + 'a')
#define forcell(c)		((c) == WILDCARD ? EMPTY:(c) + 'A')


/* 行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行  */


@implementation LeapfrogSquare


- initPuzzle: (id) thePuzzle  cell: (id) theCell
{
	[super  initPuzzle: thePuzzle  cell: theCell];
	last = WILDCARD;
	
	return self;
}


- show
{
	char	symbol;
	
	symbol = (last == WILDCARD) ? letter:last;
	[[puzzle  getCrossword]  putLetter: forcell(symbol)  inSquare: cell];
	DPSFlush();
	
	return self;
}


- (char) chooseLetter
{
	char	best;
	
	if ((last != WILDCARD) && (count[last] != 0))
	{
		[self  clearStatus: JUMPED];
		best = last;
		last = WILDCARD;
	}
	
	else
	{
		last = letter;
		best = [super  chooseLetter];
		if (!injump) last = WILDCARD;
	}
	
	return best;
}


/* 行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行  */


- update
{
	[super  update];
	
	if ((last != WILDCARD) && (count[last] == 0))
	{
		last = WILDCARD;
		[self  show];
	}
	
	return self;
}


@end