private boolean inMap(Position pos) {
        if (pos.getX() < 0 || pos.getX() >= width) {
            return false;
        }
        if (pos.getY() < 0 || pos.getY() >= height) {
            return false;
        }
        return true;
    }