/* Best Seen with tabstop = 3 */
/* By Delta Epsilon Software */
/* You may not use this file in your scrabble software without     
	signing a purchase agreement from Delta Epsilon Software.  You
	may however, evealuate the code for free conditional on not
	distributing this software to anyone else. */
/*
FILE: ap.h

	This file provides the interface between the AP and the AP_DICT.
	It is inclued in both ap.c and ap_dict.c.
*/

#include "ap.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>

/* If AP_DEBUG is defined then every time APMove is called a debug
	message is shown.  See AP_DEBUG_check_moves in "ap.c". */
//#define AP_DEBUG


/* Local Structures ======================================*/

/* These structures are only used within the AP, but by
	both the actual AP and the AP_DICT. */


/* The AP_word_node structure is used to hold a linked list
	of words.  It is a valid node only when word contains a NULL
	terminated string with length <= MAXBOARDSIZE. Also, next must either
	be NULL, or point to a valid node.  A node is the beginning
	of a AP_word_node list if no other word_node points to it, and it points
	to a node which is valid.
	
	AP_word_node lists are created by AP_DICT_get_initial_words and are
	created internally in AP_valid_words.  These lists must be destroyed by
	a call to AP_DICT_destroy_word_node.
*/
typedef struct AP_word_node {
	signed char word[MAXBOARDSIZE+1];
	struct AP_word_node *next;
	} AP_word_node;

/* AP_word_node_ptr is a pointer to an AP_word_node. */
typedef AP_word_node *AP_word_node_ptr;

/* The AP_valid_words array holds all words which can be made by adding
	one tile to the existing tiles.  All words which can be built off an
	'a' are in the first list, those built of 'z' are in the last.
	AP_valid_words are created only by AP_DICT_get_valid_words, and
	must always be destroyed by a call to
	AP_DICT_destroy_valid_words_sub_lists.
*/
typedef AP_word_node_ptr AP_valid_words['z'-'a'+1];

/* AP_DICT functions declarations ========================*/

/* These functions are all defined in ap_dict.c */

#define AP_DICT_FILE "blah.dic"

void AP_DICT_get_valid_words(t_move_list tiles, AP_valid_words result);
/* AP_DICT_get_valid_words

	requires: tiles must be a valid t_move_list,
		words must be a valid (non-NULL) empty AP_valid_words.
	effects: returns in result a AP_valid_words where each list
		within the returned array contains all words that could be
		created by adding the letter with that index to the
		letters contained in tiles.  If no words can be made then
		all lists will be empty.
	NOTE: The caller must call AP_DICT_destroy_valid_words_sub_lists
		on the result list.
*/

AP_word_node_ptr AP_DICT_get_initial_words(t_move_list tiles);
/* AP_DICT_get_initial_words

	requires: tiles must be a valid t_move_list.
	effects: returns an AP_word_node_ptr pointing to the beginning
		of a linked list of nodes which contains all words which
		can be made out of only the passed tiles.
	NOTE: The caller must call AP_DICT_destroy_word_node on the
		resulting list.
*/

int AP_DICT_check_spelling(signed char* word);
/* AP_DICT_check_spelling

	requires: word must point to a NULL terminated character string.
	effects: returns 1 if the word is in the dictionary, else 0.
*/

void AP_DICT_destroy_word_node(AP_word_node_ptr node);
/* AP_DICT_destroy_word_node

	requires: node must point to the start of a word_node list.
	effects: recursively frees all the nodes of the list.
*/

void AP_DICT_destroy_valid_words_sub_lists(AP_valid_words words);
/* AP_DICT_destroy_valid_words_sub_lists

	requires: words must be a valid AP_valid_words.
	effects: calls AP_DICT_destroy_word_node on each list within
		words.  It sets each element of words to NULL.
*/

/* AP functions declarations =============================*/

/* These functions are all defined in ap.c */

/* All exported AP functions were declared in scrabble.h */

