需要帮助使用opengl在c ++中构建迷宫(Need help in building maze in c++ using opengl)

   IT问题网   2020-06-29 00:00:00

问 题

这是我的解决方案路径代码,我使用随机fn,但每次产生相同的结果。显示2,3条路径,但正确的迷宫包含一条解决方案和许多错误路径,我该怎么做?亲切地告诉我

 void solutionpath()
{
int x = 0,y = 0,tempx,tempy,currentx,currenty,legsize = 3,方向= right;
while(xlt; mazeheight)gt;
{
while(legsize--amp;amp; xlt; mazeheight)gt;
{
currentx = x;
currenty = y;
开关(方向)
{
案例left:
mazearray [x] [y- ] = solution_path;
休息;
case right:
mazearray [x] [y ++] = solution_path;
休息;
case top:
mazearray [x- ] [y] = solution_path;
休息;
case bottom:
mazearray [x ++] [y] = solution_path;
休息;
}
if(x <0 || ylt; 0 || ygt; mazewidth)
{
x = currentx;
y = currenty;
休息;
}

}
tempx = x;
tempy = y;
int flag = 0;
do
{
flag ++;
legsize =(rand()%5)+1;
direction =(rand()%3)+1;
开关(方向)
{
案例左:
tempy- = legsize;
休息;
case right:
tempy + = legsize;
休息;
case top:
tempx- = legsize;
休息;
case bottom:
tempx + = legsize;
休息;
}

}
while((tempxlt; 0 || tempylt; 0 || tempygt; = mazewidth || tempxgt; = mazeheight)amp;amp; flaglt; 3) ;
if(flaggt; = 3)
direction =(rand()%3)+1;
}
}

解决方案

在最终<$ c $之前查看变量的值c>在你的代码中执行循环。您将不断添加到 tempx ,但很可能是中的其他变量while()表达式阻止循环终止。使用调试器逐步解决此类问题总是很有用,可以尝试查看您的某个值或测试可能不一致的地方。



第二个想法,您可能需要也可以在你的第一个循环中执行此操作。

hi sweety,



我猜您的随机数生成有问题。可能是你的程序无法生成随机数。



  #include   "  stdafx.h" 
#include lt; iostream gt;
#include lt; cstdlib gt;
#include lt; time.h gt;
使用 命名空间标准;

int main()
{
int 我,r;

srand(time( 0 ));

for (i = 0 ; ilt; = 2000 ; i ++)
{
r = rand();
coutlt;lt; " 数字是"lt;lt; rlt;lt; " 。它是在试号"lt;lt; ilt;lt; " 。\ n";
}

return 0 ;
}




请查看上面的示例代码以获取随机数...希望它可以帮助您..

标签:需要帮助匡助使用构建迷宫



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

使用文本框将一个选项卡值添加到另一个选项卡。(one tab value to another tab both using text box.)

problem how to assign one tab value to another tab if bot ...

使用WSAsy-Model的Win32套接字(Win32 Socket using WSAsy-Model)

problem hi !i want to use the wsaasyncselect ...

一次单击添加空白记录(one click add blank record)

problem dear sir, when was clicking edit link button ther ...

关于sql'列表的问题(the problem which is about listing of sql&#39;)

problem i want to get 3 datas which has been added lastly ...

DataGridView绑定源datacontext.ExecuteQuery allowusertoaddrows已禁用(DataGridView Binding Source datacontext.ExecuteQuery allowusertoaddrows disabled)

problem using the following code: iqueryable data = db.e ...

我想在每个页面上显示用户名(I want to display username on every page)

problem can i use loginview control without login control ...

解释如何重载.ToString()方法......(Explain how to overload .ToString() method...)

problem help me friends... :) thanks in advance... soluti ...

UserControl编辑对象(UserControl to edit an object)

problem hello, i have a usercontrol that has some fields ...

使用任何网络服务获取英国的邮政编码和地址(get postal code and address of UK using any web service)

problem hi, i have 2 text box. 1 for u.k. p ...

Windows 7的应用程序(application for windows 7)

problem do i need to install anything to program an app u ...

将控件添加到datagridview(add control to datagridview)

problem hi, there is a control called nbtext (which forma ...

多列和网格下拉列表(无自动完成)(dropdown with multicolumn and grid(no autocomplete))

problem i need a dropdown with multicolumn like the follo ...

如何创建oracle数据库DSN?(how to create oracle database DSN)

problem respected sir/mam i have a oracle database in my ...

获取dataTable中字符串的长度(get length of a string in dataTable)

problem hiii all i make a for loop on datatab ...

使用大型数据库(working with large databases)

problem hi, we use sql server 2008 database ...

数据列表中的CountDown计时器(CountDown timers in a datalist)

problem im developing a auction website where students fr ...

插入记录器的问题(problem in inserting recorod)

problem cmd = new sqlcommand("insert into login1 values" ...

显示行到列(Display Row to Column)

problem how row to column value display in crystal report ...

Gridview中的复选框(Check box in Gridview)

problem if i check checkbox in gridview after that if i c ...

更新DatagridView记录(Updating DatagridView Records)

problem what am i doing wrong i can seem to u ...