ABlock[x_, y_] := {
Circle[{x-1/2,y-1/2}, 1/2, {0, Pi/2}],
Circle[{x+1/2,y+1/2}, 1/2, {Pi, 3Pi/2}]
};
BBlock[x_, y_] := {
Circle[{x+1/2,y-1/2}, 1/2, {Pi/2, Pi}],
Circle[{x-1/2,y+1/2}, 1/2, {3Pi/2, 2Pi}]
}

Show[Graphics[
Table[
If[Random[] > 0.5, ABlock[x,y], BBlock[x,y]],
{x,50}, {y, 50}
]
], AspectRatio -> 1]

Dynamic[Length[trail]]

Clear[BlockType];
BlockType[pos_] := BlockType[pos] = If[Random[]>0.5, 1, -1];
{pos, dir} = {0,1};
trail = First[Last[Reap[
Sow[pos += dir];
dir = BlockType[pos]*Replace[dir, {1->-I, I->-1, -1->I, -I->1}];
While[{pos, dir} =!= {0,1},
Sow[pos += dir];
dir = BlockType[pos]*Replace[dir, {1->-I, I->-1, -1->I, -I->1}]
];
]]];
Show[Graphics[{
RGBColor[1,0,0], Disk[{Re[#], Im[#]}, 1/3]& /@ {First[trail]}, RGBColor[0,0,0],
If[BlockType[#]===1, ABlock[Re[#], Im[#]], BBlock[Re[#], Im[#]]]& /@ trail
}], AspectRatio -> Automatic]