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

📄 eightnum.cpp

📁 一个很经典的问题_八数码! 算法速度快,解决问题多...有兴趣的可以
💻 CPP
字号:
// EightNum.cpp : implementation file
//

#include "stdafx.h"
#include "BSM.h"
#include "EightNum.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static int target[9]={1,2,3,4,5,6,7,8,0};

/////////////////////////////////////////////////////////////////////////////
// EightNum

//EightNum::EightNum()
//{
//}

EightNum::~EightNum()
{
}


BEGIN_MESSAGE_MAP(EightNum, CWnd)
	//{{AFX_MSG_MAP(EightNum)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// EightNum message handlers

void EightNum::cul_para()
{
	int i;
	int temp_nipn=0;
	for (i=0;i<9;i++)
		if (num[i]!=target[i])
			temp_nipn++;
	not_in_position_num=temp_nipn;
	if (this->parent==NULL)
		deapth=0;
	else
		deapth=this->parent->deapth+1;
	eva_function=not_in_position_num+deapth;

}

void EightNum::get_numbers_to(int other_num[])
{
	for (int i=0;i<9;i++)
		other_num[i]=num[i];

}

void EightNum::set_num(int other_num[])
{
	for (int i=0;i<9;i++)
		num[i]=other_num[i];

}

EightNum& EightNum::operator =(EightNum &another_8num)
{
	for (int i=0;i<9;i++)
		num[i]=another_8num.num[i];
	not_in_position_num=another_8num.not_in_position_num;
	deapth=another_8num.deapth+1;
	eva_function=not_in_position_num+deapth;
	return *this;

}

EightNum& EightNum::operator =(int other_num[])
{
	for (int i=0;i<9;i++)
		num[i]=other_num[i];
	return *this;

}

int EightNum::operator ==(EightNum &another_8num)
{
	int match=1;
	for (int i=0;i<9;i++)
		if(num[i]!=another_8num.num[i])
		{
			match=0;
			break;
		}
	if (match==0)
		return 0;
	else 
		return 1;

}

int EightNum::operator ==(int other_num[])
{
	int match=1;
	for (int i=0;i<9;i++)
		if(num[i]!=other_num[i])
		{
			match=0;
			break;
		}
	if (match==0)
		return 0;
	else 
		return 1;

}

int EightNum::get_nipn()
{
	return not_in_position_num;

}

int EightNum::get_deapth()
{
	return deapth;
}

int EightNum::get_evafun()
{
	return eva_function;

}
















⌨️ 快捷键说明

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