#include "bot.h" #include "maze.h" Bot::Bot( Maze& m ) : maze( m ) {} // It amazes me that an algorithm this short is sufficient. // You should try compiling it and seeing that it really solves // the maze. bool Bot::solve() { maze.reset(); maze.start(); maze.getCell().setMark( true ); Dir before = EAST; while( !maze.isGoal() ) { Dir d = nextCCW( before ); for( int idx = 0; idx < 4; d = nextCW( d ), ++idx ) { if( maze.move( d ) ) { if( maze.getCell().isMarked() ) { maze.move( opposite( d ) ); maze.getCell().setMark( false ); maze.move( d ); } maze.getCell().setMark( true ); before = d; break; } } } }