// 推箱子,增加箱子是否卡死的简单判断,别小看这段代码,可大量剪枝,效率提升客观。
// 其实可以预先在棋盘上置上箱子不可以到达的位置,另外“死棋”的逻辑还可以增加。。。
//
//
// 判断箱子推到pt位置后,是否卡死
//
//
bool SokoState::isDead(Point& pt) const
{
if ( !isDest(pt) && (
isWall(pt.down())&&isWall(pt.left())
|| isWall(pt.down())&&isWall(pt.right())
|| isWall(pt.up())&&isWall(pt.left())
|| isWall(pt.up())&&isWall(pt.right())
) )
{
return true;
}
return false;
}
bool SokoState::moveBox(SokoState& r, Point& box, Point& soko, Point& nBox,
char d) const
{
if (!isSoko(soko) || !isSpace(nBox))
return false;
// Added by anning 2010年8月17日
if (isDead(nBox))
return false;
r = *this;
for (int i = 0; i < r.rows_; i++) // 清除soko标志
{
for (int j = 0; j < r.cols_; j++)
{
r.map_[i][j] &= ~FlagSoko;
}
}
r.map_[box.x_][box.y_] &= ~FlagBox; // 移动箱子
r.map_[box.x_][box.y_] |= FlagSoko;
r.map_[nBox.x_][nBox.y_] |= FlagBox;
r.stateEq();
r.steps_.push_back(SokoStep(box.x_, box.y_, d));
return true;
}