#ifndef MAHJONG_STRUCT_HEAD_FILE
#define MAHJONG_STRUCT_HEAD_FILE

#include <time.h>
#include "../molnet/common.h"

typedef int16 MJBYTE;										/*!< 齫.Ҫ8λ,16λ */
typedef int16 MJFLAG;										/*!< ʹõı.Ҫ16λ */

//////////////////////////////////////////////////////////////////////////

#define MASK_MAHJONGKIND(value)				((value)>>4)			/*!< 4λ */
#define MASK_MAHJONGNUM(value)				((value)&0x0F)			/*!< 4λ */
#define MASK_MAHJONG(kind,num)				(((kind)<<4)+num)		/*!< ͺϳ齫 */
//#define MASK_MAHJONGFENGORZI(value)			((value<0x35)?MahJongColor_Feng:MahJongColor_Word)			/*!< 0x31-0x34 0x35-0x39 */

//////////////////////////////////////////////////////////////////////////
#define MAX_ARRAY_MJ				38								/*!< ʱŸ齫010λòš38Ϊ  */
#define RANDOM_TIMES				10								/*!< 齫Ĵ */

#define	MAX_HAND_MJ					14								/*!< û */
#define MAX_BLOCK_COUNT				((MAX_HAND_MJ + 2) / 3)			/*!< 齫 */
#define CONST_MJ_HIDE				0								/*!< ƶʱֵ */

////////////////////////////////齫ṹ//////////////////////////////////////////
//! 齫
/*! 齫,ݺʱ */
enum enBlockStyle
{
	BlockStyle_Null	 = 0,											/*!<  */
	//////////////////////////////////еĽṹ////////////////////////////////////////
	BlockStyle_Chi,													/*!< 123ƽṹ */
	BlockStyle_Peng,	 											/*!< 111ƽṹ */
	BlockStyle_Gang_Ming,											/*!< 1111ܽṹ */
	BlockStyle_Gang_ZiMoMing,										/*!< 1111ܽṹ */
	BlockStyle_Gang_An,												/*!< 1111ܽṹ */
	BlockStyle_Gang_XF,												/*!<  з ܽṹ */
	BlockStyle_FengZiChi,											/*!<  з  */
	//////////////////////////////////еĽṹ////////////////////////////////////////
	BlockStyle_Shun,	 											/*!< ˳ṹ */
	BlockStyle_Ke,													/*!< ӽṹ,3ͬ, */
	BlockStyle_Jiang,												/*!< ƽṹ */
};

//! 齫ṹ
/*! 齫,ɼ齫 */
typedef struct tagMJBlock
{
	MJBYTE					first;									/*!< 齫һֵ */
	enBlockStyle			style;									/*!< 齫 */

	/////////////////////////////ֻĳ(ϲ齫)/////////////////////////////////////////////
	MJBYTE					second;									/*!< 齫ڶֵ */
	MJBYTE					last;									/*!< 齫ֵ */
	//! ÿ齫
	/*!
		ø3Ƶ
		\param mj 齫
		\param iCount 齫
		\return Ƿȷȡ
		\sa enBlockStyle
	*/
	bool getMJ(MJBYTE mj[], int &iCount)
	{
		iCount = 0;
		switch(style)
		{
		case BlockStyle_Chi:
		case BlockStyle_Shun:
			{
				mj[0] = first+0;
				mj[1] = first+1;
				mj[2] = first+2;
				iCount = 3;
			}
			break;
		case BlockStyle_Peng:
		case BlockStyle_Ke:
			{
				mj[0] = mj[1] = mj[2] = first;
				iCount = 3;
			}
			break;
		case BlockStyle_Gang_Ming:
		case BlockStyle_Gang_ZiMoMing:
			{
				mj[0] = mj[1] = mj[2] = mj[3] = first;
				iCount = 4;
			}
			break;
		case BlockStyle_Gang_An:
			{
				mj[0] =  mj[1] =  mj[2] = CONST_MJ_HIDE;
				mj[3] = first;
				iCount = 4;
			}
			break;
		case BlockStyle_Gang_XF:
			{
				//ƿ
				if(first == 0x31)
				{
					mj[0] = first+0;
					mj[1] = first+1;
					mj[2] = first+2;
					mj[3] = first+3;
					iCount = 4;
				}
				//зƿ
				else if (first == 0x35)
				{

					mj[0] = first+0;
					mj[1] = first+1;
					mj[2] = first+2;
					iCount = 3;
				}
			}
			break;
		case BlockStyle_FengZiChi:
			{
				mj[0] = first;
				mj[1] = second;
				mj[2] = last;
				iCount = 3;
			}
			break;
		case BlockStyle_Jiang:
			{
				mj[0] = mj[1] = first;
				iCount = 2;
			}
			break;
		default:
			return false;
		}
		return true;
	}
}MJBlock,*PMJBlock;

//! ͵Ľṹ
/*! ڴ洢 */
typedef struct tagHuNode
{
	MJBlock					mjBlock;								/*!< ǰ齫 */
	struct tagHuNode		*tKe;									/*!< һ */
	struct tagHuNode		*tShun;									/*!< һ˳ */
	struct tagHuNode		*tJiang;								/*!< һ */
}HuNode, *HuTree;

/////////////////////////////齫ض/////////////////////////////////////////////

//! 齫
/*! 齫: (1-9) (1-9) (1-9),,ƻ */
enum enMahJongKind
{
	MahJong_Wan = 0,												/*!<  1~9 */
	MahJong_Tiao,													/*!<  1~9 */
	MahJong_Bing,													/*!< Ͳ 1~9Ͳ */
	MahJong_Word,													/*!<  з */
	MahJong_Flower,													/*!<  ﶬ÷ */
	MahJong_Invalid = 99											/*!< Ƿֵ */
};

//! Բ
enum enOperationChiType
{
	Operation_Chi_Type_Null			= 0x00,							/*!< Ƿֵ */
	Operation_Chi_Type_Left			= 0x01,							/*!< ԣ0** */
	Operation_Chi_Type_Midd			= 0x02,							/*!< ԣ*0* */
	Operation_Chi_Type_Right		= 0x04							/*!< ԣ**0 */
};

//! ܲ
/*! ܲ */
enum enOperationGangType
{
	Operation_Gang_Type_Null		= 0x00,							/*!<  */
	Operation_Gang_Type_ZiMoMing	= 0x01,							/*!< ¸() */
	Operation_Gang_Type_Ming		= 0x02,							/*!< ֱ */
	Operation_Gang_Type_An			= 0x04,							/*!<  */
	Operation_Gang_Type_XF			= 0x08,							/*!<  */
};
//////////////////////////////////////////////////////////////////////////
#endif
