myqueen.cpp

来自「八皇后的A*算法 利用矩阵的行列变换」· C++ 代码 · 共 52 行

CPP
52
字号
#include "state.h"
#include<list>
#define N 8
#include <iostream>
using namespace std;

list<state> closedlist,openlist;

bool isInopenlist(state *s)
{
	if(find(openlist.begin(),openlist.end(),*s)==openlist.end())
		return false;
	else return true;
}
bool isInclosedlist(state *s)
{
	if(find(closedlist.begin(),closedlist.end(),*s)==closedlist.end())
		return false;
	else return true;
}

void main()
{
	state res,state[8];
	int i,j,k,count=65535;

	for(i=0; i<N; i++)	
	{
		cout<<"i="<<i<<endl;
		for(j=0; j<N; j++)
		{
			state[j].trans(i,j);
			state[j].inc_h();
			state[j].compute_g();			
			if(count > state[j].get_f())
			{
				count=state[j].get_f();
				cout<<"此时f的值为:"<<count<<endl;				
				res.trans(i,j);				
				state[j].show();
			}
		}

		if(res.get_f()==0) exit(0);	

		res.compute_g();
		for(k=0; k<N; k++)
			state[k]=res;	
				
		cout<<"\n";
	}
}

⌨️ 快捷键说明

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