Depth-first Search implementation in State Design Pattern