xkx mushclient 全自动walk lua实现

加入了xkx地图数据,通过寻路算法,找到两点间的通路,然后再走。
地图数据来自xkx论坛gps定位的sqlite数据库,转换成lua格式输出处理。修改其中的一些错误的,"符号

  1. room={
  2.     [1]={
  3.         ["id"]=1,
  4.         ["name"]="中心广场",
  5.         ["desc"]="这是泉州的中心地带,树荫浓郁,整齐划一。人山人海,摩肩接踵,来来",
  6.         ["ways"]="east|north|south|west",
  7.         ["link"]={["w"]=2,["w"]=11,["e"]=10,["s"]=9},
  8.         ["zone"]="福建泉州",
  9.         ["npc"]="",
  10.         ["cmd"]=""
  11.     },
  12.     [2]={
  13.         ["id"]=2,
  14.         ["name"]="刺桐西路",
  15.         ["desc"]="这是泉州的主要干道,笔直宽广,车水马龙,热闹非凡。西边便是著名的",
  16.         ["ways"]="east|north|west",
  17.         ["link"]={["w"]=3,["w"]=19,["s"]=17},
  18.         ["zone"]="福建泉州",
  19.         ["npc"]="",
  20.         ["cmd"]=""
  21.     },
  22.          .
  23.          .
  24.          .
  25. }

通过触发器获取place,ways,desc表示当前看到的地点,出路,地点描述。

trywalk.lua含半自动行走实现

  1. --[[
  2. 1、修改wait.regexp使得匹配后该行保持有效,触发器仍旧为临时触发(一劳永逸。)
  3. 2、需要全局变量 place 获取房间名建立1个触发器
  4. 3、需要全局变量ways获取出路建立18个出发器
  5. 4、使用举例
  6.    可以建立mush alias walk/((.*),(.*)/)
  7.    发送到脚本
  8.    local target="%1"
  9.    local allow="%2"
  10.    function walk()
  11.      rectilineal_walk(target,allow)
  12.    end
  13.    require "wait"
  14.    wait.make(walk)
  15.    从武当三清殿走到玄岳门可以在命令行walk(玄岳,n.nd.nu)
  16.    再从玄岳门走到三不管walk(三不管,e.eu.ed.nw.n)
  17. ]]--
  18. require "wait"
  19. require "tprint"
  20. place=nil
  21. desc=nil
  22. ways=nil
  23. --脚本建立出发器的方法
  24. function way_t()
  25.     local l,w
  26.     local find=string.find
  27.     while 1 do
  28.         l,w=wait.regexp("这里没有任何明显的出路|这里唯一的出口是 ([a-z]+)。|这里明显的出口是 ([a-z]+) 和 ([a-z]+)|这里明显的出口是 ([a-z]+)、([a-z]+) 和 ([a-z]+)|这里明显的出口是 ([a-z]+)、([a-z]+)、([a-z]+) 和 ([a-z]+)|这里明显的出口是 ([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+) 和 ([a-z]+)|这里明显的出口是 ([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+) 和 ([a-z]+)|这里明显的出口是 ([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+) 和 ([a-z]+)|这里明显的出口是 ([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+) 和 ([a-z]+)|(> )*(.*) /- $|(> )*(.*) /- ([a-z]+)$|(> )*(.*) /- ([a-z]+)、([a-z]+)$|(> )*(.*) /- ([a-z]+)、([a-z]+)、([a-z]+)$|(> )*(.*) /- ([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)$|(> )*(.*) /- ([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)$|(> )*(.*) /- ([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)$|(> )*(.*) /- ([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)$|(> )*(.*) /- ([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)、([a-z]+)$")
  29.           ways=nil
  30.           ways={}
  31.           local id=1
  32.           if find(l,"-") then
  33.            for i,v in ipairs(w) do
  34.             if v~=nil and v~=false and (not find(v,">")) and v~="" and i>2 then
  35.              --Note(v)
  36.              ways[id]=v
  37.              id=id+1
  38.             end
  39.            end
  40.           else
  41.            for i,v in ipairs(w) do
  42.             if v~=nil and v~=false and v~="" then
  43.              --Note(v)
  44.              ways[id]=v
  45.              id=id+1
  46.             end
  47.            end
  48.           end
  49.           --tprint(ways)
  50.     end
  51. end
  52. function place_t()
  53.     local l,w
  54.     local find=string.find
  55.     local ways_str
  56.     while 1 do
  57.         l,w=wait.regexp("(> )*(.*) /- ([a-z、]*)")
  58.         place=w[2]
  59.         desc=nil
  60.         ways=nil
  61.         npc=""
  62.         --Note("地点:"..place)
  63.     end
  64. end
  65. function desc_t()
  66.     local l,w
  67.     local find=string.find
  68.     while 1 do
  69.         l,w=wait.regexp("    (.*)")
  70.         if desc==nil then
  71.             desc=w[1]
  72.             --Note(desc)
  73.         end
  74.     end
  75. end
  76. function init()
  77.     wait.make(way_t)
  78.     wait.make(desc_t)
  79.     wait.make(place_t)
  80. end
  81. init()
  82. --上面这一段可以自己不用脚本,通过操作mush的触发器设置实现(我实现好了,用脚本方便点)
  83. function rectilineal_walk(target,allows)
  84.     local find=string.find
  85.     local l,w,t
  86.     local walkmap_s,walkmap_l,walkmap
  87. local bad=false
  88.     --映射
  89.     walkmap_s="e;w;s;n;eu;ed;wu;wd;su;sd;nu;nd;se;sw;ne;nw;d;u"
  90.     walkmap_l="east;west;south;north;eastup;eastdown;westup;westdown;southup;southdown;northup;northdown;southeast;southwest;northeast;northwest;down;up"
  91.     
  92.     local ws=utils.split(walkmap_s,";")
  93.     local wl=utils.split(walkmap_l,";")
  94.     local path=""
  95.     walkmap={}
  96.     for i,v in ipairs(ws) do
  97.         walkmap[v]=wl[i]
  98.     end
  99.     for i,v in ipairs(wl) do
  100.         walkmap[v]=ws[i]
  101.     end
  102.     --获取允许方位
  103.     if allows~=nil then
  104.        if allows~="" then  t=utils.split(allows,".") end
  105.     end
  106.     --t中有可行方位,有优先级
  107. Execute("look")
  108.     task="walking"
  109.     while task=="walking" do
  110.         l,w=wait.regexp("这里明显的出口是|这里唯一的出口是|这里没有任何明显的出路|(> )*(.*) /- ([a-z、]+)",10)
  111.         if l==nil then
  112.         else
  113.             if find(place,target) then
  114.                 Note("到达"..target)
  115.                 break
  116.             end
  117.             if ways~=nil then
  118.                 --通过出口,尝试走
  119.                 local walked=false
  120.                 for i,v in ipairs(t) do
  121.                     for ii,vv in ipairs(ways) do
  122.                         if vv=="" or vv==false or vv==nil then else
  123.                         if vv==v or walkmap[vv]==v then
  124.                             Execute("h;"..v) --发送一个halt再行走
  125.        --Execute(v)         --网速好时可以快速行走
  126.                             path=path..v..";"
  127.                             walked=true
  128.                             break
  129.                         end
  130.                         end
  131.                     end
  132.                     if walked==true then break end
  133.                 end
  134.                 --不能再走了
  135.                 if walked==false then
  136.                     Note("能力有限,走到这里,不只如何走了")
  137.                     bad=true
  138.                     break
  139.                 end
  140.             else
  141.                 Note("这里没有出路,机器人解决不了")
  142.                 bad=true
  143.                 break
  144.             end
  145.         end
  146.     end
  147.     Note("我走的路径:"..path)
  148.     if bad==false then
  149.       return path
  150.     else
  151.       return nil
  152.     end
  153. end

全自动寻路行走实现

autowalk.lua

  1. require "xkx_room"
  2. require "tprint"
  3. require "trywalk"
  4. local wait=wait
  5. local  find=string.find
  6. local ways_ok=function (ways1,ways2)
  7.     local w1=utils.split(ways1,"|")
  8.     --local w1=ways1
  9.     local w2=utils.split(ways2,"|")
  10.     local i,v,ii,vv
  11.     if  table.getn(w1)==table.getn(w2) then
  12.         for i,v in ipairs(w1) do
  13.             local ok=false
  14.             for ii,vv in ipairs(w2) do
  15.                 if vv==v then
  16.                     ok=true
  17.                     break
  18.                 end
  19.             end
  20.             if  ok==false then return false end
  21.         end
  22.         --all ok
  23.         return true
  24.     else
  25.         return false
  26.     end
  27. end
  28. --地址描述用触发得到是完整的,find找数据中匹配项,不可以反,因为数据中有不完整的。
  29. function findroom(name,desc,ways)
  30.     Note("开始寻找"..name)
  31.     local ret={}
  32.     local id=1
  33.     local i,v
  34.     for i,v in ipairs(room) do
  35.         if v["name"]==name then
  36.             if (desc~=nil and desc~="") or ( ways~=nil and ways~="")  then
  37.                 if (desc~=nil and desc~="") and ( ways~=nil and ways~="") then
  38.                 --两个都有
  39.                     if  find(desc,v["desc"]) and ways_ok(ways,v["ways"]) then
  40.                         ret[id]=v["id"]
  41.                         id=id+1
  42.                     end
  43.                 else
  44.                     if ( ways~=nil and ways~="") then
  45.                     --ways有desc无
  46.                         if ways_ok(ways,v["ways"]) then
  47.                             ret[id]=v["id"]
  48.                             id=id+1
  49.                         end
  50.                     else
  51.                     --desc有ways无
  52.                         if find(desc,v["desc"]) then
  53.                             ret[id]=v["id"]
  54.                             id=id+1
  55.                         end
  56.                     end
  57.                 end
  58.             else
  59.             --两个空
  60.                 ret[id]=v["id"]
  61.                 id=id+1
  62.             end
  63.         end
  64.     end
  65.     Note("寻找"..name.."结束")
  66.     tprint(ret)
  67.     return ret
  68. end
  69. function showroom(roomid)
  70.     tprint(room[roomid])
  71. end
  72. function pathbyid(startroomid,endroomid)
  73.     local ret=""
  74.     local tree={}
  75.     local tree_grow_at=function (id)
  76.         local k,v
  77.         local ret=false
  78.         if id~=nil then
  79.             local links={}
  80.             if  (room[id])["link"]~=nil  and (room[id])["link"]~={} then
  81.                 for k,v in pairs( (room[id])["link"] ) do
  82.                     if tree[v]~=nil or v==0 then
  83.                         --已经处理了,是正常顺序
  84.                     else
  85.                         tree[v]={}
  86.                         tree[v]={
  87.                             ["uplink"]=id,
  88.                             ["path"]=k,
  89.                             ["link"]={}
  90.                         }
  91.                         table.insert(links,v)
  92.                         if v == endroomid then
  93.                             ret=true
  94.                             break
  95.                         end
  96.                     end
  97.                 end
  98.                 (tree[id])["link"]=links
  99.                 if ret==true then return true else return links end
  100.             else
  101.                 return nil
  102.             end
  103.             return links
  104.         else
  105.             tree[startroomid]={
  106.                 ["uplink"]=nil,
  107.                 ["path"]=nil,
  108.                 ["link"]={[1]=startroomid}
  109.             }
  110.             if startroomid==endroomid then
  111.                 return true
  112.             end
  113.             return (tree[startroomid])["link"]
  114.         end
  115.     end
  116.     --
  117.     local tree_grow=function()
  118.         local root,links,leaf
  119.         local i,v,ii,vv,iii,vvv
  120.         local trycount=0
  121.         local ret=false
  122.         local closed={}
  123.         root=tree_grow_at(nil)
  124.         if root==true then
  125.             --找到
  126.             return true
  127.         else
  128.             while root~=nil and root~={} and table.getn(tree)<table.getn(room) and trycount<table.getn(room) do
  129.                 leaf={}
  130.                 for i,v in ipairs(root) do
  131.                     table.insert(closed,v)
  132.                     links=tree_grow_at(v)
  133.                     if links==true then
  134.                         --找到
  135.                         return true
  136.                     else
  137.                         if links~=nil then
  138.                             for ii,vv in ipairs(links) do
  139.                                 local new=true
  140.                                 for iii,vvv in ipairs(closed) do
  141.                                     if vvv==vv then
  142.                                         new=false
  143.                                         break
  144.                                     end
  145.                                 end
  146.                                 if new==true then
  147.                                     table.insert(leaf,vv)
  148.                                 else
  149.                                     --print("but old place")
  150.                                 end
  151.                             end
  152.                         end
  153.                     end
  154.                 end
  155.                 root=leaf
  156.                 trycount=trycount+1
  157.             end
  158.         end
  159.         --从这里出,失败
  160.         return false
  161.     end
  162.     --
  163.     if tree_grow()==true then
  164.         Note("找到了!")
  165.         local id=endroomid
  166.         while id~=startroomid do
  167.             ret=(tree[id])["path"]..";"..ret
  168.             id=(tree[id])["uplink"]
  169.         end
  170.         Note(ret)
  171.     else
  172.         Note("抱歉没找到通路,请修改地图room.lua数据,确保连通")
  173.     end
  174.     return ret
  175. end
  176. function where()
  177.     local roomidt={}
  178.     while  table.getn(roomidt)~=1 do
  179.         place=nil
  180.         ways=nil
  181.         desc=nil
  182.         Execute("look")
  183.         while 1 do
  184.             if place~=nil and ways~=nil and desc~=nil then
  185.                 break
  186.             end
  187.             wait.time(2)
  188.         end
  189.         local wlen=table.getn(ways)
  190.         local ran=math.random(wlen)
  191.         local ranway=ways[ran]
  192.         roomidt=findroom(place,desc,table.concat(ways,'|'))
  193.         if table.getn(roomidt)~=1 then
  194.             Note("此处不好定位,换个地方。走:"..ranway)
  195.             Execute("h;"..ranway)
  196.         end
  197.     end
  198.     Note("当前房间:"..roomidt[1])
  199.     return roomidt[1]
  200. end
  201. function walk(toname,tozone)
  202.     local rooms=findroom(toname)
  203.     local startid=where()
  204.     local i,v,ii,vv
  205.     local path
  206.     local find=string.find
  207.     if rooms~=nil and rooms~={} then
  208.         if  tozone~=nil then
  209.             for ii,vv in ipairs(rooms) do
  210.                 if find((room[vv])["zone"],tozone) then
  211.                 else
  212.                     Note("区域:"..(room[vv])["zone"].."不合要求"..tozone)
  213.                     rooms[ii]=0
  214.                 end
  215.             end
  216.         end
  217.         --只处理到第一个位置
  218.         for i,v in ipairs(rooms) do
  219.             if v~=nil and v~=0 then
  220.                 path=pathbyid(startid,v)
  221.                 if path~=nil and path~="" then break end
  222.             end
  223.         end
  224.         if path~=nil and path~="" then
  225.             --找到了通路,执行咯!
  226.             local patht=utils.split(path,";")
  227.             for i,v in ipairs(patht) do
  228.                 wait.time(1)
  229.                 Execute("h;"..v)
  230.             end
  231.         else
  232.             Note("奇怪,没有通路")
  233.         end
  234.     else
  235.         Note("无法定位目标房间号")
  236.     end
  237. end
  238. function to_npc(tonpc)
  239.      --无数据,有数据很好实现,把目标找到和上面就一样了。    
  240. end

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CCSDebug配置是指在CCS(Code Composer Studio)中进行调试的配置。根据引用\[1\],CCS对于CC3200的支持相对较弱,只能进行程序仿真,无法直接将程序下载到CC3200的Flash中。因此,如果想将程序下载到CC3200的Flash中,需要使用CCS UniFlash来完成。 在CCS中进行调试配置时,可以使用不同的调试API和方法。根据引用\[2\],可以将输出字符串放置在可以通过ROV(Real-time Object Viewer)查看的内部缓冲区中。可以通过修改release.cfg文件来使用SysMin,也可以创建新的内核项目或移动到调试内核项目来实现。 此外,根据引用\[3\],在IDE控制台和UART显示时,可以使用不同的调试API,如printf、Display_printf、System_printf和UART_PRINT。这些API可以用于输出调试信息,并且在添加调试调用时会有额外的内存影响。 因此,CCSDebug配置涉及到选择合适的调试API和方法,以及根据需求进行相应的配置和调试操作。 #### 引用[.reference_title] - *1* [CC3200 Debug时报错:Unable to launch CCS debug-session based on current selection....](https://blog.csdn.net/CSDN_X_W/article/details/86676351)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [CCS printf调试](https://blog.csdn.net/Chase_xkx/article/details/127182238)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值