ElemType friendoperator >>(ElemType source, int direct) {
//
对于
L
,
R
,
U
,
D
四个方向作出的移动
ElemType result = source;
int
i = result.locate0();
switch
(direct) {
case
U: if(i < 6){
result.maze[i] = result.maze[i+3];
result.maze[i+3] = 0;
} break;
case
D: if(i > 2){
result.maze[i] = result.maze[i-3];
result.maze[i-3] = 0;
} break;
case
L: if(i%3 != 2) {
result.maze[i] = result.maze[i+1];
result.maze[i+1] = 0;
} break;
case
R: if(i%3 != 0) {
result.maze[i] = result.maze[i-1];
result.maze[i-1] = 0;
}
}
result.depth++;
return
result;
}
for
(
int
i = 0; i < 9; i++)
if
(maze[i] == 0)
return
i;
return
-1;
}
bool
isSuccess() {
return
maze[0]==1 && maze[1]==2 && maze[2]==3 &&
maze[3]==8 && maze[4]==0 && maze[5]==4 &&
maze[6]==7 && maze[7]==6 && maze[8]==5;
}
//
下面是评价函数
int
evaluate() {
return
depth + numWrong(); }
void
disrupt() {
//
打乱初始矩阵
clrscr();
gotoxy(7,3);
cout <<
"Disrypt the maze as you wish, press enter to see the AMAZING thing!"
;
this
->print();
int
input;
while
((input=_getch()) != ENTER) {
switch
(input) {
case
UP: *
this
= *
this
>> U;
this
->print();
break
;
case
DOWN: *
this
= *
this
>> D;
this
->print();
break
;
case
LEFT: *
this
= *
this
>> L;
this
->print();
break
;
case
RIGHT: *
this
= *
this
>> R;
this
->print();
}
}
}
void
print() {
for
(
int
i = 0; i < 3; i++) {
for
(
int
j = 0; j < 3; j++) {
gotoxy(36+j*3, 8+i);
if
(maze[i*3+j]!=0) cout <<
'['
<< maze[i*3+j] <<
']'
;
else
cout <<
" "
;
} cout << endl;
}
Sleep(200);
}
};
void
print(ElemType &e) { e.print(); }
ElemType null(0,0,0,0,0,0,0,0,0);
//
每个位置都是
0
,这是不存在的
#include
"dso.h"
typedef
ElemType Status;