其實這個議題對於每次遇到要寫類似迷宮程式的時候都是一個頭痛需要思考的問題。
在此我就提供其中一個方法,也許方法很多我的不代表就是最佳但是一個參考方向。
當你要寫迷宮程式的時候也許你會有以下的作法:
1.亂數隨意產生牆壁的作法,長度不要過長的方式來達到,但有會走不到終點的情況,因為有死路產生。
2.乾脆將地圖寫死,多做幾個在程式中亂數選擇之一,還算可以的作法好處是不會有死路產生但變化不多。
3.取一的作法加入更多的限制條件,但是還是會有死路產生的狀況無法解決。
條件:在下點的情況下需檢查周圍狀況之類.....
我這提供的作法其實很簡單,就是把路先長出來然後填牆......說來簡單就幾句話而已,難道我當大家是白癡喔!!
大家都知道阿....問題就在作法上的處理了。
我以31x31的地圖大小來做說明,記住地圖一定要是積數絕不要用偶數,如果使用我的方法的話。
範例使用C語言設計,請不要問我其他語言請自行修改設計。
目前分類:C/C++討論 (8)
- May 01 Fri 2009 14:36
[C/C++].產生一個不死迷宮
- Mar 26 Thu 2009 23:30
C++ multi-thread簡易範例
C++ multi-thread簡易範例
- Mar 24 Tue 2009 00:17
sort algorithm(STL)
利用sort algorithm寫一個排序範例.....
- Mar 24 Tue 2009 00:12
How fast is STL?
You would think on the face of it, that STL - with all of its abstraction and templates - would be slower than doing things the "old fashioned way". However my tests do not bear that out. For a simple test, I wrote a small program that generated 10,000,000 (10 million) random numbers and sorted them using the inbuilt STL sort. Here it is ...
- Jan 28 Wed 2009 22:00
C語言如何連接MySQL
- Nov 16 Sun 2008 10:00
如何寫出3*3的行列式值
- Nov 11 Tue 2008 07:49
[STL] sort algorithm
利用sort algorithm寫一個排序範例.....
- Nov 08 Sat 2008 23:16
Windows 是否有 2000 個執行緒的上限?
Does Windows have a limit of 2000 threads per process?
Often I see people asking why they can't create more than around 2000 threads in a process. The reason is not that there is any particular limit inherent in Windows. Rather, the programmer failed to take into account the amount of address space each thread uses.
A thread consists of some memory in kernel mode (kernel stacks and object management), some memory in user mode (the thread environment block, thread-local storage, that sort of thing), plus its stack. (Or stacks if you're on an Itanium system.)