⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graph.cpp

📁 滑块问题求解系统:利用深度优先搜索和广度优先搜索解决有趣的滑块问题求解系统。
💻 CPP
字号:
// Graph.cpp : 实现文件
//

#include "stdafx.h"
#include "AI.h"
#include "Graph.h"
#include ".\graph.h"


// CGraph 对话框

IMPLEMENT_DYNAMIC(CGraph, CDialog)
CGraph::CGraph(CWnd* pParent /*=NULL*/)
	: CDialog(CGraph::IDD, pParent)
{
}

CGraph::~CGraph()
{
}

void CGraph::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CGraph, CDialog)
	ON_WM_PAINT()
END_MESSAGE_MAP()


// CGraph 消息处理程序


/*const int step = 25, len = 75;


void CGraph::paintLine(CPoint first, CPoint second, CDC * dc)
{
	if(first.x == second.x){
		dc->MoveTo(first.x + (len >> 1), first.y + len);
		dc->LineTo(second.x + (len >> 1), second.y);
	}else if(first.x < second.x){
		dc->MoveTo(first.x + len, first.y + (len >> 1) );
		dc->LineTo(second.x, second.y + (len >> 1) );
	}else{
		dc->MoveTo(first.x, first.y + (len >> 1) );
		dc->LineTo(second.x + len, second.y + (len >> 1) );
	}
}

void CGraph::ShowNode(int status, CPoint point, CDC *dc)
{
	const static int ten[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};
	CPoint save = point;
	for(int i = 0; i <= 3; ++i, point.y += step){
		dc->MoveTo(point);
		dc->LineTo(point.x + 75, point.y);
	}
	point = save;
	for(int i = 0; i <= 3; ++i, point.x += step){
		dc->MoveTo(point);
		dc->LineTo(point.x, point.y + 75);
	}
	for(int i = 0; i < 9; ++i){
		int num = status / ten[i] % 10;
		int x = i % 3, y = i / 3;
		if(num){
			char str[10];
			sprintf(str, "%d", num);
			dc->TextOut(save.x + x * step + 8, save.y + y * step + 5, str);
		}
	}
}
*/

BOOL CGraph::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  在此添加额外的初始化	
	char str[50];
	CString res;
	sprintf(str, "          %09d", path[0]);
	res += str;
	for(int i = 1; i < path.size(); ++i){
		if(i % 5 == 0)
			res += "\r\n\r\n\r\n";
		sprintf(str, "  ----->  %09d", path[i]);
		res += str;
	}
	SetDlgItemText(IDC_GRAPH, res);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE	
}

/*
void CGraph::OnPaint(){
	//CPaintDC dc(this); // device context for painting

	CDC *dc = GetDlgItem(IDC_GRAPH)->GetWindowDC();	
	int i;
	
	
	CPoint begin(5, 5), step_h(step + len, 0), step_v(0, step + len), save;
	static CPen pen(PS_SOLID, 2, RGB(255, 0 , 0));
	dc->SelectObject(&pen);
		
	i = 0;
	save.x = begin.x;
	save.y = begin.y;
	do{
		CPoint tmp;
		tmp.x = begin.x;
		tmp.y = begin.y;
		ShowNode(path[i], begin, dc);
		if( (i + 1) % 6 == 0){
			step_h.x *= -1;
			begin += step_v;
		}else
			begin += step_h;
		if(i > 0){
			paintLine(save, tmp, dc);
			save.x = tmp.x;
			save.y = tmp.y;
		}
		i++;
	}while(i < path.size() );
}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -