//grammar.h
//by John Ahlschwede
//defines node classes

#include "board.h"


const int chunk = 5;
/*
Used for grow(int) function.  Grow function generates a random index to determine 
which type of new node to create.  An ever increasing number is added to the index,
so that eventually, the highest tier of index is reached -- indicating a terminal
node.  (This ensures that growth won't continue indefinitely.)  The chunk int is
rate at which the index is ensured to grow by.					
*/




/////////////////////////////////////////////////////////////////////////////////
//  node class; base class off of which other node classes are derived
/////////////////////////////////////////////////////////////////////////////////
class node : public player
{
protected:

public:
	node();
	virtual ~node();
	virtual int exe(int[]);
	virtual void print();
	virtual void grow(int);
	virtual node *copyNode(); //will return a copy of subtree
	virtual node *findNode(int depth2dig);
	virtual void addTree(node *tree);
	virtual int countSize();
	node *make_new(int);
};



/////////////////////////////////////////////////////////////////////////////////
// if_lessthan_do_else class
/////////////////////////////////////////////////////////////////////////////////

class if_lessthan_do_else : public node
{
private:
	node *operand1;
	node *operand2;
	node *then_do;
	node *else_do;


public:
	if_lessthan_do_else();
	~if_lessthan_do_else();
	virtual int exe(int[]);
	virtual void print();
	virtual void grow(int);
	virtual node *copyNode();
	virtual node *findNode(int depth2dig);
	virtual void addTree(node *tree);
	virtual int countSize();
	node *getOperand1() {return operand1;}
	node *getOperand2() {return operand2;}
	node *getThen_do() {return then_do;}
	node *getElse_do() {return else_do;}
	void setOperand1(node *temp) {operand1 = temp;}
	void setOperand2(node *temp) {operand2 = temp;}
	void setThen_do(node *temp) {then_do = temp;}
	void setElse_do(node *temp) {else_do = temp;}
};



/////////////////////////////////////////////////////////////////////////////////
// addition class
/////////////////////////////////////////////////////////////////////////////////

class addition : public node
{
private:
	node *operand1;
	node *operand2;


public:
	addition();
	~addition();
	virtual int exe(int[]);
	virtual void print();
	virtual void grow(int);
	virtual node *copyNode();
	virtual node *findNode(int depth2dig);
	virtual void addTree(node *tree);
	virtual int countSize();
	node *getOperand1() {return operand1;}
	node *getOperand2() {return operand2;}
	void setOperand1(node *temp) {operand1 = temp;}
	void setOperand2(node *temp) {operand2 = temp;}
};



/////////////////////////////////////////////////////////////////////////////////
// subtraction class
/////////////////////////////////////////////////////////////////////////////////

class subtraction : public node
{
private:
	node *operand1;
	node *operand2;


public:
	subtraction();
	~subtraction();
	virtual int exe(int[]);
	virtual void print();
	virtual void grow(int);
	virtual node *copyNode();
	virtual node *findNode(int depth2dig);
	virtual void addTree(node *tree);
	virtual int countSize();
	node *getOperand1() {return operand1;}
	node *getOperand2() {return operand2;}
	void setOperand1(node *temp) {operand1 = temp;}
	void setOperand2(node *temp) {operand2 = temp;}	
};



/////////////////////////////////////////////////////////////////////////////////
// value_at class
/////////////////////////////////////////////////////////////////////////////////


class value_at : public node
{

private:
	node *operand1;

public:
	value_at();
	~value_at();
	virtual int exe(int[]);
	virtual void print();
	virtual void grow(int);
	virtual node *copyNode();
	virtual node *findNode(int depth2dig);
	virtual void addTree(node *tree);
	virtual int countSize();
	node *getOperand1() {return operand1;}
	void setOperand1(node *temp) {operand1 = temp;}
};

/////////////////////////////////////////////////////////////////////////////////
// terminal class
/////////////////////////////////////////////////////////////////////////////////

class terminal : public node
{
	
private:
	int value;
	
public:
	terminal();
	virtual int exe(int[]);
	virtual void print();
	virtual void grow(int);
	virtual node *copyNode();
	virtual node *findNode(int depth2dig);
	virtual void addTree(node *tree);
	virtual int countSize();
	int getValue() {return value;}
	void setValue(int temp) {value = temp;}
};


