#include "bot.h" #include "maze.h" Bot::Bot( Maze& m ) : maze( m ) {} bool Bot::solve() { maze.reset(); maze.start(); return findSolution( EAST ) || findSolution( SOUTH ); } bool Bot::findSolution( Dir dir ) { if( maze.isGoal() ) { maze.getCell().setMark( true ); return true; } else if( maze.move( dir ) ) { for( Dir ndir = nextCW( opposite( dir ) ); ndir != opposite( dir ); ndir = nextCW( ndir ) ) { if( findSolution( ndir ) ) { // Solution was found in that direction. Mark this // square and return home. maze.move( opposite( dir ) ); maze.getCell().setMark( true ); return true; } } // Nothing beyond here maze.move( opposite( dir ) ); } // No solution involving this square. Back up. return false; }