Example #1
0
	/**
	Get the number of open & untried options at this cell.
	Only consider cells that aren't the previous cell and aren't in the actualPath
	*/
	int Mouse::CheckForOptions()
	{
		int count = 0;
		std::vector<Room*>* children = currentRoom->get_children(previousRoom);

		std::vector<Room*>::iterator cI = children->begin();
		while (cI != children->end())
		{
			Room* cuRom = *cI;
			if (backtracking == false)
			{
				if (!actualPath->Contains(cuRom->Location().x, cuRom->Location().y))
					count++;
			}
			else
				count++;
			cI++;
		}

		return count;
	}
Example #2
0
	void Mouse::Explore()
	{
		std::unique_ptr<Path_new> * path_chosen;

		// Turn to face a direction where there's actually an opening
		// Start off going forward once, set previous to start
		MoveForward();

		maze->printClean();
		maze->printMaze(true);
		maze->printClean();
		
		while (true)
		{
			// Delay *******************************************************
			std::this_thread::sleep_until(
				std::chrono::system_clock::now() + std::chrono::seconds(1));
			// *************************************************************

			// Get sensor data
			this->sensor->sense(maze.get());

			// Check to see if there's more than one new path in the current physical room
			switch (CheckForOptions())
			{
			// dead end
			case 0:	
				TurnAround();
				// Reverse backtracking variable
				backtracking ? backtracking = false : backtracking = true;
				MoveForward();
				break;

			// only one option
			case 1:	
				// Get the next cell to turn to as there's only one option 
				Turn(currentRoom->get_children(previousRoom)->front());
				MoveForward();
				break;

			// 2 or 3 options in direction
			case 2:	
			case 3:
				if (!backtracking)
				{
					// Guess all the possible paths from the current "cross-roads"
					path_chosen = Evaluate();

					// Get the next room from the new completePathGuess, aka path_chosen
					delete(completePathGuess);
					completePathGuess = path_chosen->get();
					Room * nextr = completePathGuess->Rooms()->at(actualPath->Rooms()->size());

					// Start down the new path
					Turn(nextr);
					MoveForward();
				}
				else
				{
					// backtracking

					// Choose the room with the least visits, avoiding going back down the previous path
					Room * nextr = Filter::LeastVisited(currentRoom->get_children(previousRoom));
					
					if (!actualPath->Contains(nextr->Location().x, nextr->Location().y))
					{
						// change back to regular advancements
						backtracking = false;
					}
					
					// Start down path
					Turn(nextr);
					MoveForward();
				}
				break;
			}

			maze->printClean();
			maze->printMaze(true);
			maze->printClean();
		}

	}