/******************************************************************
 *						Author:	Zhou Yundong
 *						Time: 20080425 20:49
 ******************************************************************/
#include "Stdafx.h"
#include "Think.h"
#include "time.h"

char basePath[256]; // 基础目录
bool fix[81]; // 0: unfixed, 1: fixed
bool oldFix[81]; // just for show 0: unfixed, 1: fixed
int flagAnswer; // 0: noanswer, 1: only one, 2: more than one
bool underQuestion; // under getting the question
int rightStatus; // status of the right board
bool dropable[81]; // can be dropped in condition of keeping flagAnswer is 1
int countQuestion; // the count of numbers of the question
bool underThinking; // computer is working to get answer or to get question
HANDLE runThread;
int transMethod; // 变换模式代号
int gameKind; // 0:sodoku,1:sosum,2:sopare,3:somix,4:jigsaw,5:extra default is sodoku
int gameKindRight;
LARGE_INTEGER Frequency;
LARGE_INTEGER StartTime;
LARGE_INTEGER EndTime;
double SpendTime;
bool autoSolute; // 允许自动解题
bool firstIntoSodoku; // 第一次进入数独状态
int editKind; // 数和:1，数扭:2
int rightKind; // 用于显示右盘的数扭
// 数独用
int board[81];
int bakBoard[81]; // reserve board for getting question
int answerBoard[81]; // save the answer
int leftBoard[81]; // save the left board
int rightBoard[81]; // save the right board
int tempBoard[81]; // save the temp board
int cntBoard;
bool fixation[81]; // 固定的数，clean时不会被清除
// 数和用
int sum[81];
int bakSum[81]; // reserve sum for getting question
int answerSum[81]; // save the answer
int leftSum[81]; // save the uniq sum
int rightSum[81]; // save the right sum
int idx[81];
int bakIdx[81]; // reserve idx for getting question
int answerIdx[81]; // save the answer
int leftIdx[81]; // save the left idx
int rightIdx[81]; // save the right idx
int leftHead[81]; // 簇头，每个簇只有一个
int rightHead[81];
bool leftUniq[81]; // 群头，每个群只有一个
bool rightUniq[81];
int underSumEditing; // 处在和编辑状态
int selectIdx; // 选中的idx值
int maxIdx; // 当前最大idx数
bool editingIdx[81]; // 编辑中被选中的格点表
int editingHead; // 编辑状态时的头索引
POINT endPoint[100];
int cntEndPoint;
POINT endPoints[40][100];
int pEndPoints[40];
POINT rightEndPoints[40][100];
int pRightEndPoints[40];
int pCircle;
int pRightCircle;
int colorGroup[40];
int rightColorGroup[40];
// 数比用
int pare[144];
int bakPare[144]; // reserve pare for getting question
int answerPare[144]; // save the answer
int leftPare[144]; // save the left pare
int rightPare[144]; // save the right pare
int cntPare;
int glidingPare;
int tempPare[144]; // save the temp pare
// KillerPare用
int kilpare[144];
int bakKilpare[144]; // reserve killer pare for getting question
int answerKilpare[144]; // save the answer
int leftKilpare[144]; // save the left killer pare
int rightKilpare[144]; // save the right killer pare
int tempKilpare[144]; // save the temp killer pare
int cntKilpare;
int glidingKilpare; // 鼠标滑过的killer pare的索引
// 数扭用
int saw[81];
int leftSaw[81];
int headSaw[81];
int selectSaw;
int colorSaw[81][4];
int colorSawRight[81][4];
bool editingSaw[81];
int maxSaw; // 当前最大saw数
int underSawEditing; // 处在数扭编辑状态
int rightSaw[81];
// 数超用
int extra[81];
int leftExtra[81];
int rightExtra[81];
int headExtra[81];
int selectExtra;
bool editingExtra[81];
int maxExtra; // 当前最大extra数
int underExtraEditing; // 处在数扭编辑状态

// 计算用
int posStack[27];
int valueStack[27];
int SCnt;
int PIdx;
struct GameBoard G[IndexEnd];
// Sopare专用
int startGrid;
int differTop[81][81];
int pDifferTop[81];
int differBottom[81][81];
int pDifferBottom[81];
int maxBoard[81], minBoard[81];
int maxBoardFlg[81], minBoardFlg[81];
int priority[81];// 优先度

void loadGame()
{
	srand(time(0));
	GetCurrentDirectory(256, basePath);
	flagAnswer = -1;
	gameKind = 0;
	gameKindRight = 0;
	autoSolute = true;
	glidingPare = 144;
	glidingKilpare = 144;
	firstIntoSodoku = false;
	editKind = 0;
	rightKind = 0;
}

void initialCommon()
{
	int i;
	terminateSumEdit();
	getEndPoint();
	terminateSawEdit();
	getColorSaw();
	flagAnswer = -1;
	selectIdx = 0;
	selectSaw = 0;
	glidingPare = 144;
	glidingKilpare = 144;
	rightStatus = 0;
	for(i=0; i<81; i++)
	{
		fixation[i] = false;
	}
}
