4 walls algorithm - DRAFT