Академический Документы
Профессиональный Документы
Культура Документы
һ����Ŀ˵��
�������Ź���� ��һ��c��ľŹ����У������ ����һ�� ����İ ������ڷе ĸ � � � �
�� ��������
������Ŀ����
�����Ź�������� ������еľ�������֮һ�����������ڣc����������У��ţ�����ʣ�µ�û�зŵ���Ϊ�
�� �������� �� ��������
�����Ź������У��������������������תĿ�깲��}�ֿ��
ͬ�����ֲ�}�������ܣʱ��b��Ҳ�����������к�ż�����С����ǿ��
�һ��������е���������Ҵ�� �����һ��һά�����ʾ������ ���������Ǿ
�� �ʾ�ɣ������������������������������������У���� �
������������������ ������������
ܹ г�4�Ľ��ʽ���ǣ�
�ƣ��ƣ��٣����������أУƣ���أ
�ƣ�����������
�ƣ�����������
�ƣ�����������
�ƣ�����������
�ƣ�����������
�ƣ�����������
�ƣ�����������
�ƣ�����������
�٣�������������������������������������
�����٣�������ż��������������о����� �������Ľ��������4 �Ľ��
���㷨����
�� ��������
����Ҫ��õ����ŵľ���Ҫʹ�ù����������Ź������������У����֣�Ҳ��� ǣ ��������������ŷ
������ �Ƿdz���ģ���ʹ�õĹ��������Ҫ��סÿһ�����������ʽ��Ҫ���������¼�Ļ��� �
ú���
ܶ ڴ棬���ǰ��� ����ʵ� � � ѹ � �ʹ � ã ģ ףϣң���ʽ���棬
ѹ � � � �ʽ � � ÿ � � � � � � � ã � λ � �ʾ � � � � � � � � ǣ � � c � � � � � � � � � � ֽ��ڣ����ڣĶ���
�Ʊ�ʾ��ʽ���������������ã�λ��ʾ����ʹ����һ��С���ɾ��ǽ�����ʾλ��������Ȼ���ö��4�ģ����ֱ�ʾ���
�����˽���������ɺ �����·����
��ṹ���£�
class cninegird
{
public:
struct placelist
{
dword place;
placelist* left;
placelist* right;
};
struct scanbuf
{
dword place;
int scanid;
};
struct pathlist
{
unsigned char path[9];
};
private:
placelist *m_pplacelist;
scanbuf *m_pscanbuf;
rect m_rresetbutton;
rect m_rautobutton;
public:
int m_ipathsize;
clock_t m_itime;
uint m_istepcount;
unsigned char m_itargetchess[9];
unsigned char m_ichess[9];
hwnd m_hclientwin;
pathlist *m_ppathlist;
bool m_bautorun;
private:
inline bool addtree(dword place , placelist*& parent);
void freetree(placelist*& parent);
inline void arraytodword(unsigned char *array , dword & data);
inline void dwordtoarray(dword data , unsigned char *array);
inline bool movechess(unsigned char *array , int way);
bool estimateuncoil(unsigned char *array);
void getpath(uint depth);
public:
void movechess(int way);
bool computefeel();
void activeshaw(hwnd hview);
void drawgird(hdc hdc , rect clientrect);
void drawchess(hdc hdc , rect clientrect);
void reset();
void onbutton(point pnt , hwnd hview);
public:
cninegird();
~cninegird();
};
������������������ʹ����vectorģ����random_shuffle����������4�����������������ݣĿ��
����ʲô�����룺
void cninegird::reset()
{
if(m_bautorun) return;
vector vs;
int i;
for (i = 1 ; i < 9 ; i ++)
vs.push_back(i);
vs.push_back(0);
random_shuffle(vs.begin(), vs.end());
random_shuffle(vs.begin(), vs.end());
for ( i = 0 ; i < 9 ; i ++)
{
m_ichess[i] = vs[i];
}
if (!estimateuncoil(m_ichess))
{
unsigned char array[9] = {1,2,3,8,0,4,7,6,5};
memcpy(m_itargetchess , array , 9);
}
else
{
unsigned char array[9] = {1,2,3,4,5,6,7,8,0};
memcpy(m_itargetchess , array , 9);
}
m_istepcount = 0;
}
���ѹ����ʵ�֣�
array[night] = 0;
data = 0;
data = (dword)((dword)array[0] << 29 | (dword)array[1] << 26 |
(dword)array[2] << 23 | (dword)array[3] << 20 |
(dword)array[4] << 17 | (dword)array[5] << 14 |
(dword)array[6] << 11 | (dword)array[7] << 8 |
(dword)array[8] << 5 | night);
array[night] = 8;
}
��ѹ��ʱ��ѹ������ ����ѹ � � � 룺
���¼��һ�����������У�����С��������е����У������ʱ���ÿ���������ε���ʽ�Ƚ 켸
���������������л���ż�����еĴ��룺
�����ƶ����ո�λ�Ĵ��� � ֻҪ � � � � � Ƿ � � � ƶ � � � � � � � � �
����ˣ������ƶ���ʱ�� ˳ �����һ���Dz����Ѿ���Ŀ����������4���û��ֹ��ƶ��Ǹ�����ʾ�õģ����룺
�� õ ���������·���ˡ��ñ� m_ipathsize4��¼������
ܲ 庯����룺
dwordtoarray(m_pscanbuf[depth].place , m_ppathlist[++now].path);
while(parentid != -1)
{
if (now == maxpos)
{
maxpos += 10;
pathlist * temlist = new pathlist[maxpos];
memcpy(temlist , m_ppathlist , sizeof(pathlist) * (maxpos - 10));
delete[] m_ppathlist;
m_ppathlist = temlist;
}
dwordtoarray(m_pscanbuf[parentid].place , m_ppathlist[++now].path);
parentid = m_pscanbuf[parentid].scanid;
}
m_ipathsize = now;
}
� ɣΣ �
�����4� һ���
ͣ ̾ ����ˡ����룺
����������һ��������� � �
���
� �õ
ȵ��� 飬�������תɣģ
ףϣң�����Ŀ��
ͣ Ƚϣ��������ɣ����
ͬ ͬ ���һ����
�λ�ã���������������һ����ֱ��û�в������ˣ������� ������λ�õ���λ�ã�����ֱ���ҵ�Ŀ����Ϊֹ������
bool cninegird::computefeel()
{
unsigned char *array = m_ichess;
uint i;
const int maxsize = 362880;
unsigned char temparray[9];
freetree(m_pplacelist);
delete[] m_pscanbuf;
m_pscanbuf = null;
return false;
}