implement BFS with checking repeated states