📄 eightnumber.h
字号:
//------------------------------------------------------------------------------------------------
//-------八数码问题的头文件 作者:申徐洲 日期:2004年5月6日 AllRightsReserve
//------------------------------------------------------------------------------------------------
#ifndef EIGHTNUMBER_H
#define EIGHTNUMBER_H
#pragma once
#include"EightNumberHead.h" // 使用结构TEightNumber TPosition TLevel
class CEightNumber
{
public:
CEightNumber(void); // 构造函数
virtual ~CEightNumber(void); // 虚拟析构函数
public:
bool initEightNumber(int aCurrent[3][3]); // 初始化八数码问题
bool searchByAlgorithm(void); // A*算法搜索
bool searchByBreadth(void); // 广度优先搜索
bool searchByDepth(void); // 深度优先搜索
TEightNumberPtr getResultList(void); // 获取结果链表
int getResultNum(void); // 获取结果总结点数量
int getResultDepth(void); // 获取结果深度
CSize showAll(CDC* pDC,TEightNumberPtr pResultList,int nResultNum); // 显示全部结点
CSize showResult(CDC* pDC,TEightNumberPtr pResultList,int nResultNum);// 只显示结果
private:
bool isValid(int aCurrent[3][3]); // 判断源状态是否合法
bool isGoal(TEightNumberPtr pCurrent); // 判断当前结点是不是目标状态
TEightNumberPtr newState(TEightNumberPtr pCurrent, int nDirection); // 新建状态
TEightNumberPtr newEightNumber(TEightNumberPtr pParent, int nDirection); // 新建结点
TPosition findBlank(TEightNumberPtr pCurrent, int nValue); // 找出当前结点空格的位置
TEightNumberPtr findMaxDepth(void); // 找出深度最大的结点
TEightNumberPtr findMinCost(void); // 找出A*算法中代价最小的结点
bool findNext(TEightNumberPtr pCurrent, int nDirection); // 判断结点的下一个位置是否合法
void findAnswer(TEightNumberPtr pEightNumber); // 如八数码问题有解 找出哪些结点是正解
void calcWeight(TEightNumberPtr pCurrent); // 计算A*算法中结点的权值
void reCalcPosition(void); // 重新计算A*算法中结点的位置
private:
TPosition m_tDirection[4]; // 八数码问题的搜索方向
int m_aGoal[3][3]; // 八数码问题的目标状态
TEightNumberPtr m_pHead; // 八数码问题的头指针
TEightNumberPtr m_pTail; // 八数码问题的尾指针
TLevelPtr m_pLevel; // 八数码问题的第N层结点数量的头指针
TLevelPtr m_pLevelTail; // 八数码问题的第N层结点数量的尾指针
int m_nTotalNum; // 八数码问题的总结点数
int m_nDepth; // 八数码问题的深度
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -