?? state.cpp
字號:
#include "state.h"
#include <cmath>
#include <iostream>
using namespace std;
state::state()
{
for(int i=0; i<N; i++)
x[i]=N-1-i;
h=0;
g=N-1;
f=h+g;
}
state::~state()
{
}
void state::compute_g()
{
int i,j;
for(i=0; i<N; i++)
{
for(j=i+1; j<N; j++)
if(abs(x[i]-x[j])==abs(i-j)) g++;
g--;
}
f=g+h;
}
void state::inc_h()
{
h++;
f++;
}
int state::get_f()
{return f;}
void state::show()
{
for(int i=0; i<N; i++)
{
for(int j=0; j<N; j++)
{
if(x[i]==j) cout<<"|*";
else cout<<"| ";
}
cout<<"|\n";
}
}
void state::trans(int i, int j)
{
int t=x[i];
x[i]=x[j];
x[j]=t;
}
void state::operator =(state p)
{
for(int i=0; i<N; i++)
x[i]=p.x[i];
h=p.h;
g=p.g;
f=p.f;
}
bool state::operator ==(state p)
{
for(int i=0; i<N; i++)
if(x[i]!=p.x[i]) return false;
return true;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -