void getNh(int x, int y, int nh[4][2], int nodes[100][38]) { int pos = 0; if (canCross(x, y, x + 1, y) && nodes[x + 1][y] < 0) { nh[pos][0] = x + 1; nh[pos][1] = y; pos++; } if (canCross(x, y, x - 1, y) && nodes[x - 1][y] < 0) { nh[pos][0] = x - 1; nh[pos][1] = y; pos++; } if (canCross(x, y, x, y + 1) && nodes[x][y + 1] < 0) { nh[pos][0] = x; nh[pos][1] = y + 1; pos++; } if (canCross(x, y, x, y - 1) && nodes[x][y - 1] < 0) { nh[pos][0] = x; nh[pos][1] = y - 1; pos++; } }
bool AIInput::Private::canMove(Point p, enum Command dir) { const auto level = core.getLevel(); switch (dir) { case InputMethod::MoveUp: --p.y; break; case InputMethod::MoveDown: ++p.y; break; case InputMethod::MoveLeft: --p.x; break; case InputMethod::MoveRight: ++p.x; break; default: // Not a move command. return false; break; }; if (level->canCross(p)) return true; else return false; }