//Download by http://www.NewXing.com
// BWChessDlg.cpp : implementation file
//
#include "stdafx.h"
#include <math.h>
#include <mmsystem.h>
#include "BWChess.h"
#include "SetupDlg.h"
#include "AboutDlg.h"
#include "HowToDlg.h"
#include "Globalvar0.h"
#include "HelperAPI.h"
#include "BWChessDlg.h"
#include "RecorDdlg.h"
#include "BestDlg.h"
#include <time.h>
#include "SettingDlg.h"
#include "Demo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//#define EDITION 17
#define PASSEDTIME 1
BOOL PlaySounds(UINT IDSoundRes, WORD wFlag = SND_ASYNC);
static TCHAR pSettings[]=_T("Settings");
/////////////////////////////////////////////////////////////////////////////
// CBWChessDlg dialog
BOOL PlaySounds(UINT IDSoundRes, WORD wFlag)
{
if (g_bSoundOn)
if (PlaySound(MAKEINTRESOURCE(IDSoundRes),
AfxGetInstanceHandle(),
wFlag|SND_RESOURCE|SND_NODEFAULT))
return TRUE;
return FALSE;
}
CBWChessDlg::CBWChessDlg(CWnd* pParent /*=NULL*/)
: CDialog(IDD_BWCHESS_DIALOG, pParent)
{
//{{AFX_DATA_INIT(CBWChessDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pMenu = new CMenu();
m_pDibEmpty = new CDib;
m_pDibBlack = new CDib;
m_pDibWhite = new CDib;
m_pDibBGo=new CDib;
m_pDibWGo=new CDib;
m_pDibCurB=new CDib;
m_pDibCurW=new CDib;
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<NUM+2;j++)
m_pDibHFrame[i][j]=new CDib;
for(j=0;j<NUM;j++)
m_pDibVFrame[i][j]=new CDib;
}
m_PaintNum=0;
hAccelerator=::LoadAccelerators(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_ACC));
g_nCanHintTimeB=AfxGetApp()->GetProfileInt(_T("Supior Option"), _T("CanHintTimesB"), 3);
g_nCanHintTimeW=AfxGetApp()->GetProfileInt(_T("Supior Option"), _T("CanHintTimesW"), 3);
g_nStrollSpeed=AfxGetApp()->GetProfileInt(_T("Supior Option"), _T("StrollSpeed"), 2);
//
g_nStrollSpeed=abs(g_nStrollSpeed);
g_nStrollSpeed%=3;
g_nCanHintTimeB=abs(g_nCanHintTimeB);
g_nCanHintTimeB%=31;
if(g_nCanHintTimeB<3)
g_nCanHintTimeB=3;
g_nCanHintTimeW=abs(g_nCanHintTimeW);
g_nCanHintTimeW%=31;
if(g_nCanHintTimeW<3)
g_nCanHintTimeW=3;
//
g_bPrompt =AfxGetApp()->GetProfileInt(pSettings,_T("Prompt"),1);
// g_nPortNum =AfxGetApp()->GetProfileInt(pSettings, _T("PortNum"), 1228);
g_bIsFromFile =AfxGetApp()->GetProfileInt(pSettings, _T("FromFiles"), 0);
// g_strName =AfxGetApp()->GetProfileString(pSettings, _T("CurrentName"), _T("Lovely Babby"));
// g_nNetPlayMode =AfxGetApp()->GetProfileInt(pSettings, _T("NetPlayMode"), 0);
g_nMoveSpeeds =AfxGetApp()->GetProfileInt(pSettings, _T("ComputerWalkSpeed"), 2);
g_nCbSkill =AfxGetApp()->GetProfileInt(pSettings, _T("ComputerBlackSkill"), 3);
g_nCwSkill =AfxGetApp()->GetProfileInt(pSettings, _T("ComputerWhiteSkill"), 3);
g_nCSpeed =AfxGetApp()->GetProfileInt(pSettings, _T("ComputerDemoSpeed"), 2);
g_nIsNoTimeLimit=AfxGetApp()->GetProfileInt(pSettings, _T("IsNoTimeLimit"), 0);
g_nTimeLimit =AfxGetApp()->GetProfileInt(pSettings, _T("TimeLimit"), 60);
g_bShowDynamic =AfxGetApp()->GetProfileInt(pSettings, _T("ShowDynamic"), 0);
g_bPeepOften =AfxGetApp()->GetProfileInt(pSettings, _T("PeepOften"), 1);
g_bTopMost =AfxGetApp()->GetProfileInt(pSettings, _T("TopMost"), 0);
g_bSoundOn =AfxGetApp()->GetProfileInt(pSettings, _T("SoundOn"), 1);
g_bUserBlack =AfxGetApp()->GetProfileInt(pSettings, _T("UserUseBlackStone"), 1);
g_nRunMode =AfxGetApp()->GetProfileInt(pSettings, _T("Player"), MODE_WITH_COMPUTER);
g_nSkill =AfxGetApp()->GetProfileInt(pSettings, _T("Skill"), 1);
g_nTime1 =AfxGetApp()->GetProfileInt(pSettings, _T("Time1"), 0);
g_nTime2 =AfxGetApp()->GetProfileInt(pSettings, _T("Time2"), 0);
g_nTime3 =AfxGetApp()->GetProfileInt(pSettings, _T("Time3"), 0);
g_nMark1 =AfxGetApp()->GetProfileInt(pSettings, _T("Mark1"), 0);
g_nMark2 =AfxGetApp()->GetProfileInt(pSettings, _T("Mark2"), 0);
g_nMark3 =AfxGetApp()->GetProfileInt(pSettings, _T("Mark3"), 0);
g_strName1 =AfxGetApp()->GetProfileString(pSettings, _T("Name1"), _T("Anonymous"));
g_strName2 =AfxGetApp()->GetProfileString(pSettings, _T("Name2"), _T("Anonymous"));
g_strName3 =AfxGetApp()->GetProfileString(pSettings, _T("Name3"), _T("Anonymous"));
g_strSec1 =AfxGetApp()->GetProfileString(pSettings, _T("Sec1"), _T(""));
g_strSec2 =AfxGetApp()->GetProfileString(pSettings, _T("Sec2"), _T(""));
g_strSec3 =AfxGetApp()->GetProfileString(pSettings, _T("Sec3"), _T(""));
g_bMovePlace =AfxGetApp()->GetProfileInt(pSettings, _T("ComputerPlaceDynamic"), 1);
CString str;
str.LoadString (IDS_AUTHOR);
AfxGetApp()->WriteProfileString(_T("Author"), _T("Shuker"), str);
}
CBWChessDlg::~CBWChessDlg()
{
delete m_pMenu;
delete m_pDibEmpty;
delete m_pDibBlack;
delete m_pDibWhite;
delete m_pDibBGo;
delete m_pDibWGo;
delete m_pDibCurB;
delete m_pDibCurW;
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<NUM+2;j++)
delete m_pDibHFrame[i][j];
for(j=0;j<NUM;j++)
delete m_pDibVFrame[i][j];
}
AfxGetApp()->WriteProfileInt(pSettings, _T("Prompt"),g_bPrompt);
AfxGetApp()->WriteProfileInt(pSettings, _T("ComputerBlackSkill"), g_nCbSkill);
AfxGetApp()->WriteProfileInt(pSettings, _T("ComputerWhiteSkill"), g_nCwSkill);
AfxGetApp()->WriteProfileInt(pSettings, _T("ComputerDemoSpeed"), g_nCSpeed);
AfxGetApp()->WriteProfileInt(pSettings, _T("ComputerWalkSpeed"), g_nMoveSpeeds);
AfxGetApp()->WriteProfileInt(pSettings, _T("ShowDynamic"), g_bShowDynamic);
AfxGetApp()->WriteProfileInt(pSettings, _T("PeepOften"), g_bPeepOften);
AfxGetApp()->WriteProfileInt(pSettings, _T("TopMost"), g_bTopMost);
AfxGetApp()->WriteProfileInt(pSettings, _T("SoundOn"), g_bSoundOn);
AfxGetApp()->WriteProfileInt(pSettings, _T("UserUseBlackStone"), g_bUserBlack);
AfxGetApp()->WriteProfileInt(pSettings, _T("Player"), g_nRunMode);
AfxGetApp()->WriteProfileInt(pSettings, _T("Skill"), g_nSkill);
AfxGetApp()->WriteProfileInt(pSettings, _T("Time1"), g_nTime1);
AfxGetApp()->WriteProfileInt(pSettings, _T("Time2"), g_nTime2);
AfxGetApp()->WriteProfileInt(pSettings, _T("Time3"), g_nTime3);
AfxGetApp()->WriteProfileInt(pSettings, _T("Mark1"), g_nMark1);
AfxGetApp()->WriteProfileInt(pSettings, _T("Mark2"), g_nMark2);
AfxGetApp()->WriteProfileInt(pSettings, _T("Mark3"), g_nMark3);
AfxGetApp()->WriteProfileString(pSettings, _T("Name1"), g_strName1);
AfxGetApp()->WriteProfileString(pSettings, _T("Name2"), g_strName2);
AfxGetApp()->WriteProfileString(pSettings, _T("Name3"), g_strName3);
AfxGetApp()->WriteProfileString(pSettings, _T("Sec1"), g_strSec1);
AfxGetApp()->WriteProfileString(pSettings, _T("Sec2"), g_strSec2);
AfxGetApp()->WriteProfileString(pSettings, _T("Sec3"), g_strSec3);
AfxGetApp()->WriteProfileInt(pSettings, _T("ComputerPlaceDynamic"), g_bMovePlace);
AfxGetApp()->WriteProfileInt(pSettings, _T("TimeLimit"), g_nTimeLimit);
AfxGetApp()->WriteProfileInt(pSettings, _T("IsNoTimeLimit"), g_nIsNoTimeLimit);
AfxGetApp()->WriteProfileInt(_T("Supior Option"), _T("StrollSpeed"), g_nStrollSpeed);
AfxGetApp()->WriteProfileInt(_T("Supior Option"), _T("CanHintTimesB"), g_nCanHintTimeB);
AfxGetApp()->WriteProfileInt(_T("Supior Option"), _T("CanHintTimesW"), g_nCanHintTimeW);
// AfxGetApp()->WriteProfileInt(pSettings, _T("NetPlayMode"), g_nNetPlayMode);
// AfxGetApp()->WriteProfileString(pSettings, _T("CurrentName"), g_strName);
AfxGetApp()->WriteProfileInt(pSettings, _T("FromFiles"), g_bIsFromFile);
// AfxGetApp()->WriteProfileInt(pSettings, _T("PortNum"), g_nPortNum);
}
void CBWChessDlg::InitParams()
{
for (int i=0; i<NUM;i++)
for (int j=0; j<NUM; j++)
kernel[i][j] = 0;
kernel[3][3]=kernel[4][4]=2;
kernel[3][4]=kernel[4][3]