|
楼主 |
发表于 2014-1-6 13:40:02
|
显示全部楼层
其实cjgwalkunbusydo()就做了两件事:
第一,判断是否走到了第一个地图的出口处,如果到了,将当前状态设置为:cjgstate = "map1out"
用"set cjg gooutmap1"命令做一下过渡,简化处理过程。
第二,观察:观察周边有没有巡逻僧兵。为选择行动方向准备信息。
function cjgwalkunbusydo()
checkbusyend()--终止checkbusy机制
if cjgcurrentx == cjgoutweizhi and cjgcurrenty == 1 then
AMNote("已经到达第一个地图出口")
cjgstate = "map1out"
Execute("set cjg gooutmap1")
return
end
if cjgcurrenty <= 0 or cjgcurrenty > cjgmapwidth+1 or cjgcurrentx <=0 or cjgcurrentx > cjgmaplength then
Note("当前位置发生错误"..cjgcurrentx.." "..cjgcurrenty)
return
elseif cjgcurrenty == cjgmapwidth+1 and cjgcurrentx ~= cjgenterweizhi then
Note("当前入口位置发生错误"..cjgcurrentx.." "..cjgcurrenty)
return
elseif cjgcurrenty == cjgmapwidth+1 and cjgcurrentx == cjgenterweizhi then
Note("当前位置在入口,唯一的行走方向enter,检查里面有没有巡逻僧兵")
cjgxunluosengbingflag = {east = "no",south = "no",west = "no",north = "no",}
cjglooktimes = 1
Execute("look enter;set cjg cjglooknorth")
return
elseif cjgcurrenty == cjgmapwidth and cjgcurrentx == 1 then
Note("当前位置在地图西南角,检查东面和北面有无阻挡")
cjgxunluosengbingflag = {east = "no",south = "no",west = "no",north = "no",}
cjglooktimes = 2
Execute("look east;set cjg cjglookeast;look north;set cjg cjglooknorth")
return
elseif cjgcurrenty == cjgmapwidth and cjgcurrentx == cjgmaplength then
Note("当前位置在地图东南角,检查西面和北面有无阻挡")
cjgxunluosengbingflag = {east = "no",south = "no",west = "no",north = "no",}
cjglooktimes = 2
Execute("look west;set cjg cjglookwest;look north;set cjg cjglooknorth")
return
elseif cjgcurrenty == cjgmapwidth and cjgcurrentx < cjgmaplength and cjgcurrentx > 1 then
Note("当前位置在最南面,且不在角落,检查东、西、北面有无阻挡")
cjgxunluosengbingflag = {east = "no",south = "no",west = "no",north = "no",}
cjglooktimes = 3
Execute("look east;set cjg cjglookeast;look west;set cjg cjglookwest;look north;set cjg cjglooknorth")
return
elseif cjgcurrenty == 1 and cjgcurrentx == 1 then
Note("当前位置在地图西北角,检查东面和南面有无阻挡")
cjgxunluosengbingflag = {east = "no",south = "no",west = "no",north = "no",}
cjglooktimes = 2
Execute("look east;set cjg cjglookeast;look south;set cjg cjglooksouth")
return
elseif cjgcurrenty == 1 and cjgcurrentx == cjgmaplength then
Note("当前位置在地图东北角,检查西面和南面有无阻挡")
cjgxunluosengbingflag = {east = "no",south = "no",west = "no",north = "no",}
cjglooktimes = 2
Execute("look south;set cjg cjglooksouth;look west;set cjg cjglookwest")
return
elseif cjgcurrenty > 1 and cjgcurrentx == cjgmaplength then
Note("当前位置在地图东边,检查西面和南面和北面有无阻挡")
cjgxunluosengbingflag = {east = "no",south = "no",west = "no",north = "no",}
cjglooktimes = 3
Execute("look south;set cjg cjglooksouth;look west;set cjg cjglookwest;look north;set cjg cjglooknorth")
return
elseif cjgcurrenty > 1 and cjgcurrentx == 1 then
Note("当前位置在地图西边,检查东面和南面和北面有无阻挡")
cjgxunluosengbingflag = {east = "no",south = "no",west = "no",north = "no",}
cjglooktimes = 3
Execute("look east;set cjg cjglookeast;look south;set cjg cjglooksouth;look north;set cjg cjglooknorth")
return
elseif cjgcurrenty == 1 and cjgcurrentx < cjgmaplength and cjgcurrentx > 1 then
Note("当前位置在最北面,且不在角落,检查东、西、南面有无阻挡")
cjgxunluosengbingflag = {east = "no",south = "no",west = "no",north = "no",}
cjglooktimes = 3
Execute("look east;set cjg cjglookeast;look south;set cjg cjglooksouth;look west;set cjg cjglookwest")
return
elseif cjgcurrenty > 1 and cjgcurrenty < cjgmapwidth and cjgcurrentx < cjgmaplength and cjgcurrentx > 1 then
Note("当前位置在地图中央,检查四面阻挡情况")
cjgxunluosengbingflag = {east = "no",south = "no",west = "no",north = "no",}
cjglooktimes = 4
Execute("look east;set cjg cjglookeast;look south;set cjg cjglooksouth;look west;set cjg cjglookwest;look north;set cjg cjglooknorth")
return
else
Note(cjgcurrentx..","..cjgcurrenty)
end
end |
|