function check3(r, cellsize)
    while ~r.is_bord('s')
        r.step('s');
    end
    while ~r.is_bord('w')
        r.step('w');
    end

    pflag = 1;
    while ~fill_line_block(r, cellsize, pflag);
        pflag = ~pflag;
    end
end

function dir = invert_dir(dir)
    switch dir
        case 'n'
            dir = 's';
        case 's'
            dir = 'n';
        case 'w'
            dir = 'o';
        case 'o'
            dir = 'w';
    end
end

function bottomfound = fill_line_block(r, cellsize, pflag)
    bottomfound = 0;
    for i = 1:cellsize
        fill_line(r, 'o', cellsize, pflag);
        if r.is_bord('n')
            bottomfound = 1;
            break
        end
        r.step('n');
    end
end

function fill_line(r, dir, cellsize, pflag)
    offset = 0;
    if pflag
        r.mark();
    end
    while ~r.is_bord(dir)
        r.step(dir);
        offset = mod(offset + 1, cellsize);
        if offset == 0
            pflag = ~pflag;
        end
        if pflag
            r.mark();
        end
    end
    dir = invert_dir(dir);
    while ~r.is_bord(dir)
        r.step(dir);
    end
end
