| 赞 | 0 |
| VIP | |
| 好人卡 | |
| 积分 | 1 |
| 经验 | |
| 最后登录 | 2017-8-1 |
| 在线时间 | 193 小时 |
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 193 小时
- 注册时间
- 2013-3-24
- 回帖
- 427
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
最近想寫個尋路演算法的時候,查了一下,找不到RGSS裡面有Priority queue(heap)....
沒有Heap怎麼弄A*阿...
所以就很無聊的把C++裡面STL的Priority queue包成個DLL檔,這樣就有Heap可以用了
p.s.這是最大堆
用法:
[pre lang="ruby" line="1"]
$Heap_is_empty = Win32API.new('heap.dll', 'is_empty', 'v', 'i') #檢查是否為空
$Heap_clear = Win32API.new('heap.dll', 'clear', 'v', 'v') #清空
$Heap_push = Win32API.new('heap.dll', 'push', 'ii', 'v') #放入,第一個為優先度,第二個為儲存之數值
$Heap_top = Win32API.new('heap.dll', 'top', 'v', 'i') #取頂部,回傳第二個數值
$Heap_pop = Win32API.new('heap.dll', 'pop', 'v', 'v') #推出
$Heap_clear.call()
$Heap_push.call(1,2)
$Heap_push.call(3,4)
$Heap_push.call(-1,9)
if $Heap_is_empty.call() == 0
p $Heap_top.call() #4
$Heap_pop.call()
p $Heap_top.call() #2
$Heap_pop.call()
p $Heap_top.call() #9
$Heap_pop.call()
end
[/pre]
話說我存xy座標是把一個int拿來當兩個short用(座標不會超過30K嘛 |
|