我真的需要幫助。我正在嘗試創建一個機器人,以發現它走出迷宮的方式。我已經使用一系列角色創建了迷宮,但我實際上不知道如何解決這個問題。我真的很喜歡一些幫助。
我需要實現3個函數: •createMaze(char maze [] [columns],int columns,int rows) - 初始化您的迷宮•showMaze(char迷宮[] [列],int列,int行) - 顯示迷宮機器人 •機器人(焦迷宮[] [列],INT lastColumn,詮釋LASTROW,INT & nextColumn,詮釋 & nextRow) - 機器人做隨機移動我該如何製作一個機器人(用字符'X'表示),通過使用隨機數生成的迷宮方式找到它
這裏是我到目前爲止的代碼:
#include <iostream>
#include <ctime>
#include <iomanip>
using namespace std;
int main()
{
char maze [10][10] =
{ {'*','*','*','*','*','*','*','*','*','*',},
{'*', ' ', ' ', ' ',' ', ' ',' ', ' ',' ', ' ',},
{'*','*',' ','*','*','*','*',' ','*','*',},
{'*','*',' ','*',' ','*','*',' ','*','*',},
{'*','*',' ',' ','*','*','*',' ','*','*',},
{'*','*',' ','*','*','*','*','*',' ','*',},
{'*','*',' ',' ',' ','*',' ','*','*',' ',},
{'*','*','*','*',' ','*','*','*','*','*',},
{'*','*','*','*',' ','*','*','*','*',' ',},
{'*','*','*','*',' ','*',' ',' ','*','*',}
};
for (int row = 0; row < 10; row++)
{
for (int col = 0; col < 10; col++)
{
cout << maze[row][col];
}
cout << endl;
}
return 0;
}
cout << ================================= << endl;
/*
********** // robot enters from here
*
** **** **
** * ** **
** *** **
** ***** *
** * **
**** *****
**** ****
**** * **
// robot exits here
Program ended with exit code: 0
*/
你能提供一些更多的參數給你的問題嗎?是否有確定的入口/出口點?還是機器人需要找到?機器人能夠立即看到整個迷宮嗎?或者只有它可以在任何給定步驟中移動的4個可能方向?如果機器人使用進入迷宮的相同入口退出迷宮,那麼可以嗎? – MikeMayer67
在「夜間狗的好奇事件」中有詳細的算法。請參閱https://en.wikipedia.org/wiki/The_Curious_Incident_of_the_Dog_in_the_Night-Time – Bathsheba