So if your selfish miner works on its own private chain, you don't have to accept blocks from the main chain.
AFAIK above some treshold selfish miner may decide to drop his chain (fork) and restart a new one over the new point of main chain.
Another concern is to compare chain lengths in order to decide when to publish his 'private'.
Of course, you're right on that, it can have some elaborated program logic behind it. (when release private blockchain, when to drop it and follow the main chain, ect.)
But I think
RoeiDimi can first implement something simple. Something like:
if (privateChainLen > 4)
ReleasePrivateChain();
else (nBlocksBehindMainChain > 2)
DropPrivateChain();