翔鹰帝国网|帝国时代论坛|帝国时代系列|神话时代
 找回密码
 注册翔鹰会员(昵称)
搜索
查看: 599|回复: 8

[交流] 单兵战术:残血收割

[复制链接]

21

主题

3

精华

1万

积分

征服者

耕战
3476
鹰币
2266
天龙币
0
回帖
221

第十三届火箭筒杯季军

附庸关系9
 楼主| 发表于 2021-3-1 12:35:41 | 显示全部楼层 |阅读模式
又来了~再次分享一段自己写的AI。

逻辑:例遍每个正在战斗的单位,如果这个单位射程范围内有残血的敌人(一刀就死那种),立刻就得打死~

另外安利下新战役萨阿德王朝,其中的AI就是加入了这组战术。

  1. ;[残血收割]

  2. (defconst gl-local-total 11)
  3. (defconst gl-local-last 12)
  4. (defconst gl-remote-total 13)
  5. (defconst gl-remote-last 14)
  6. (defconst answer 475)
  7. (defconst reapers 476)
  8. (defconst reaper-id 477)
  9. (defconst reaper-type 478)
  10. (defconst reaper-point 479)
  11. (defconst reaper-range 480)
  12. (defconst reaper-aggressivity 481)
  13. (defconst preys 482)
  14. (defconst prey-id 483)
  15. (defconst prey-type 484)
  16. (defconst prey-class 485)
  17. (defconst prey-HP 486)
  18. (defconst prey-armor 487)
  19. (defconst prey-shield 488)
  20. (defconst stop-attack-id 489)
  21. (defconst next-reaper 490)
  22. (defconst next-prey 491)

  23. (defrule;搜索战斗单位
  24.     (true)
  25. =>
  26.     (up-full-reset-search)
  27.     (up-filter-include -1 actionid-attack -1 -1)
  28.     (up-find-local c: castle c: 240)
  29.     (up-find-local c: tower-class c: 240)
  30.     (up-find-local c: siege-weapon-class c: 240)
  31.     (up-find-local c: archery-class c: 240)
  32.     (up-find-local c: cavalry-archer-class c: 240)
  33.     (up-find-local c: cavalry-class c: 240)
  34.     (up-find-local c: infantry-class c: 240)
  35.     (up-find-local c: 1126 c: 240)
  36.     (up-remove-objects search-local object-data-id g:== reaper-id)
  37.     (up-remove-objects search-local object-data-type == 1258)
  38.     (up-remove-objects search-local object-data-type == 422)
  39.     (up-remove-objects search-local object-data-type == 548)
  40.     (up-remove-objects search-local object-data-class == packed-trebuchet-class)
  41.     (up-remove-objects search-local object-data-class == unpacked-trebuchet-class)
  42.     (up-clean-search search-local object-data-action search-order-asc)
  43.     (up-get-search-state gl-local-total)
  44.     (up-modify-goal reapers g:= gl-local-total))
  45. (defrule;例遍收割者置零
  46.     (up-compare-goal reapers c:<= next-reaper)
  47. =>
  48.     (up-modify-goal next-reaper c:= 0))
  49. (defrule;找不到收割者
  50.     (up-compare-goal reapers c:<= 0)
  51. =>
  52.     (up-jump-rule 38)
  53.     (up-modify-goal reaper-id c:= -1)
  54.     (up-modify-goal next-reaper c:+ 1)
  55.     (up-modify-goal next-prey c:= 0))
  56. (defrule;挑选收割者
  57.     (true)
  58. =>
  59.     (up-set-target-object search-local g: next-reaper)
  60.     (up-get-object-data object-data-id reaper-id)
  61.     (up-get-object-data object-data-type reaper-type)
  62.     (up-get-object-data object-data-base-attack reaper-aggressivity)
  63.     (up-get-object-data object-data-range reaper-range)
  64.     (up-get-point position-object reaper-point-x))
  65. (defrule;射程为0补偿为1
  66.     (up-compare-goal reaper-range c:< 1)
  67. =>
  68.     (up-modify-goal reaper-range c:= 1))
  69. (defrule;以收割者为中心,以其射程为半径搜索
  70.     (true)
  71. =>
  72.     (up-set-target-point reaper-point-x)
  73.     (up-filter-distance c: -1 g: reaper-range))
  74. (defrule;35
  75.     (stance-toward 1 enemy)
  76. =>
  77.     (set-strategic-number sn-focus-player-number 1)
  78.     (up-find-remote c: -1 c: 40))
  79. (defrule;34
  80.     (stance-toward 3 enemy)
  81. =>
  82.     (set-strategic-number sn-focus-player-number 3)
  83.     (up-find-remote c: -1 c: 40))
  84. (defrule;33
  85.     (stance-toward 4 enemy)
  86. =>
  87.     (set-strategic-number sn-focus-player-number 4)
  88.     (up-find-remote c: -1 c: 40))
  89. (defrule;32
  90.     (stance-toward 6 enemy)
  91. =>
  92.     (set-strategic-number sn-focus-player-number 6)
  93.     (up-find-remote c: -1 c: 40))
  94. (defrule;31
  95.     (stance-toward 5 enemy)
  96. =>
  97.     (set-strategic-number sn-focus-player-number 5)
  98.     (up-find-remote c: -1 c: 40))
  99. (defrule;30
  100.     (stance-toward 7 enemy)
  101. =>
  102.     (set-strategic-number sn-focus-player-number 7)
  103.     (up-find-remote c: -1 c: 40))
  104. (defrule;29
  105.     (stance-toward 8 enemy)
  106. =>
  107.     (set-strategic-number sn-focus-player-number 8)
  108.     (up-find-remote c: -1 c: 40))
  109. (defrule;28;搜索残血者
  110.     (true)
  111. =>
  112.     (up-remove-objects search-remote object-data-id g:== stop-attack-id)
  113.     (up-get-search-state gl-local-total)
  114.     (up-modify-goal preys g:= gl-remote-total))
  115. (defrule;27;找不到残血者
  116.     (up-compare-goal preys c:<= 0)
  117. =>
  118.     (up-jump-rule 26)
  119.     (up-modify-goal reaper-id c:= -1)
  120.     (up-modify-goal next-reaper c:+ 1)
  121.     (up-modify-goal next-prey c:= 0))
  122. (defrule;26;找到残血者
  123.     (up-compare-goal preys c:> 0)
  124. =>
  125.     (up-clean-search search-remote object-data-hitpoints search-order-asc)
  126.     (up-set-target-object search-remote g: next-prey)
  127.     (up-get-object-data object-data-id prey-id)
  128.     (up-get-object-data object-data-type prey-type)
  129.     (up-get-object-data object-data-class prey-class)
  130.     (up-get-object-data object-data-hitpoints prey-HP)
  131.     (up-get-object-data object-data-strike-armor prey-armor)
  132.     (up-get-object-data object-data-pierce-armor prey-shield)
  133.     (up-modify-goal answer g:= reaper-aggressivity))
  134. (defrule;25;例遍残血者置零
  135.     (up-compare-goal preys c:<= next-prey)
  136. =>
  137.     (up-modify-goal next-reaper c:+ 1)
  138.     (up-modify-goal next-prey c:= 0))
  139. (defrule;24;收割者是近战单位
  140. (or (up-compare-goal reaper-type c:== 1126)
  141.     (up-compare-goal reaper-range c:<= 1))
  142. =>
  143.     (up-jump-rule 1)
  144.     (up-modify-goal answer g:- prey-armor))
  145. (defrule;23;收割者是远程单位
  146.     (up-compare-goal reaper-type c:!= 1126)
  147.     (up-compare-goal reaper-range c:> 1)
  148. =>
  149.     (up-modify-goal answer g:- prey-shield))
  150. (defrule;22;攻击力小于1视同为1
  151.     (up-compare-goal answer c:<= 1)
  152. =>
  153.     (up-modify-goal answer c:= 1))
  154. (defrule;21;收割者是长矛兵,残血者是骑兵
  155.     (up-compare-goal reaper-type c:== 93)
  156. (or (up-compare-goal prey-type c:== 38)
  157. (or (up-compare-goal prey-type c:== 283)
  158.     (up-compare-goal prey-class c:== scout-cavalry-class)))
  159. =>
  160.     (up-jump-rule 18)
  161.     (up-modify-goal answer c:+ 15))
  162. (defrule;20;收割者是长矛兵,残血者是战象;92
  163.     (up-compare-goal reaper-type c:== 93)
  164. (or (up-compare-goal prey-type c:== 1132)
  165. (or (up-compare-goal prey-type c:== 1134)
  166. (or (up-compare-goal prey-type c:== 873)
  167.     (up-compare-goal prey-type c:== 875))))
  168. =>
  169.     (up-jump-rule 17)
  170.     (up-modify-goal answer c:+ 30))
  171. (defrule;19;收割者是长矛兵,残血者是骆驼
  172.     (up-compare-goal reaper-type c:== 93)
  173. (or (up-compare-goal prey-type c:== 329)
  174.     (up-compare-goal prey-type c:== 330))
  175. =>
  176.     (up-jump-rule 16)
  177.     (up-modify-goal answer c:+ 12))
  178. (defrule;18;收割者是长矛兵,残血者是战船或渔船
  179.     (up-compare-goal reaper-type c:== 93)
  180. (or (up-compare-goal prey-class c:== warship-class)
  181.     (up-compare-goal prey-type c:== 13))
  182. =>
  183.     (up-jump-rule 15)
  184.     (up-modify-goal answer c:+ 9))
  185. (defrule;17;收割者是步弓手或掷矛手,残血者是枪兵
  186. (or (up-compare-goal reaper-type c:== 4)
  187. (or (up-compare-goal reaper-type c:== 24)
  188. (or (up-compare-goal reaper-type c:== 492)
  189. (or (up-compare-goal reaper-type c:== 7)
  190.     (up-compare-goal reaper-type c:== 6)))))
  191. (or (up-compare-goal prey-type c:== 93)
  192. (or (up-compare-goal prey-type c:== 358)
  193.     (up-compare-goal prey-type c:== 359)))
  194. =>
  195.     (up-modify-goal answer c:+ 3))
  196. (defrule;16;收割者是掷矛手,残血者是弓兵种属;
  197.     (up-compare-goal reaper-type c:== 7)
  198.     (up-compare-goal prey-class c:== archery-class)
  199. =>
  200.     (up-jump-rule 13)
  201.     (up-modify-goal answer c:+ 3))
  202. (defrule;15;收割者是精锐掷矛手,残血者是弓兵种属;87
  203.     (up-compare-goal reaper-type c:== 6)
  204.     (up-compare-goal prey-class c:== archery-class)
  205. =>
  206.     (up-modify-goal answer c:+ 4))
  207. (defrule;14;收割者是精锐掷矛手,残血者是骑射手;86
  208.     (up-compare-goal reaper-type c:== 6)
  209.     (up-compare-goal prey-class c:== cavalry-archer-class)
  210. =>
  211.     (up-jump-rule 11)
  212.     (up-modify-goal answer c:+ 6))
  213. (defrule;13;收割者是骑射手,残血者是枪兵;85
  214. (or (up-compare-goal reaper-type c:== 39)
  215.     (up-compare-goal reaper-type c:== 474))
  216. (or (up-compare-goal prey-type c:== 93)
  217. (or (up-compare-goal prey-type c:== 358)
  218.     (up-compare-goal prey-type c:== 359)))
  219. =>
  220.     (up-jump-rule 10)
  221.     (up-modify-goal answer c:+ 2))
  222. (defrule;12;收割者是斥候骑兵,残血者是僧侣;84
  223.     (up-compare-goal reaper-type c:== 448)
  224.     (up-compare-goal prey-class c:== monastery-class)
  225. =>
  226.     (up-jump-rule 9)
  227.     (up-modify-goal answer c:+ 6))
  228. (defrule;11;收割者是轻骑兵,残血者是僧侣;83
  229.     (up-compare-goal reaper-type c:== 546)
  230.     (up-compare-goal prey-class c:== monastery-class)
  231. =>
  232.     (up-jump-rule 8)
  233.     (up-modify-goal answer c:+ 10))
  234. (defrule;10;收割者是骆驼兵,残血者是骑兵;82
  235.     (up-compare-goal reaper-type c:== 546)
  236. (or (up-compare-goal prey-type c:== 38)
  237. (or (up-compare-goal prey-type c:== 283)
  238.     (up-compare-goal prey-class c:== scout-cavalry-class)))
  239. =>
  240.     (up-jump-rule 7)
  241.     (up-modify-goal answer c:+ 9))
  242. (defrule;9;收割者是骆驼兵,残血者是船只或者骆驼;81
  243.     (up-compare-goal reaper-type c:== 546)
  244. (or (up-compare-goal prey-type c:== 546)
  245. (or (up-compare-goal prey-type c:== 330)
  246. (or (up-compare-goal prey-type c:== 13)
  247.     (up-compare-goal prey-class c:== warship-class))))
  248. =>
  249.     (up-jump-rule 6)
  250.     (up-modify-goal answer c:+ 5))
  251. (defrule;8;收割者是重装骆驼兵,残血者是骑兵;80
  252.     (up-compare-goal reaper-type c:== 330)
  253. (or (up-compare-goal prey-type c:== 38)
  254. (or (up-compare-goal prey-type c:== 283)
  255.     (up-compare-goal prey-class c:== scout-cavalry-class)))
  256. =>
  257.     (up-jump-rule 5)
  258.     (up-modify-goal answer c:+ 18))
  259. (defrule;7;收割者是重装骆驼兵,残血者是船只或者骆驼;79
  260.     (up-compare-goal reaper-type c:== 330)
  261. (or (up-compare-goal prey-type c:== 546)
  262. (or (up-compare-goal prey-type c:== 330)
  263. (or (up-compare-goal prey-type c:== 13)
  264.     (up-compare-goal prey-class c:== warship-class))))
  265. =>
  266.     (up-jump-rule 4)
  267.     (up-modify-goal answer c:+ 9))
  268. (defrule;6;收割者是弩炮,残血者是战象系;78
  269.     (up-compare-goal reaper-type c:== 279)
  270. (or (up-compare-goal prey-type c:== 1132)
  271. (or (up-compare-goal prey-type c:== 1134)
  272. (or (up-compare-goal prey-type c:== 873)
  273.     (up-compare-goal prey-type c:== 875))))
  274. =>
  275.     (up-jump-rule 3)
  276.     (up-modify-goal answer c:+ 6))
  277. (defrule;5;收割者是重型弩炮,残血者是战象系;77
  278.     (up-compare-goal reaper-type c:== 279)
  279. (or (up-compare-goal prey-type c:== 1132)
  280. (or (up-compare-goal prey-type c:== 1134)
  281. (or (up-compare-goal prey-type c:== 873)
  282.     (up-compare-goal prey-type c:== 875))))
  283. =>
  284.     (up-jump-rule 2)
  285.     (up-modify-goal answer c:+ 8))
  286. (defrule;4;收割者是箭船,残血者是战船或渔船;76
  287.     (up-compare-goal reaper-type c:== 539)
  288. (or (up-compare-goal prey-class c:== warship-class)
  289.     (up-compare-goal prey-type c:== 13))
  290. =>
  291.     (up-jump-rule 1)
  292.     (up-modify-goal answer c:+ 8))
  293. (defrule;收割者是瞭望箭塔,残血者是战船或渔船;75
  294.     (up-compare-goal reaper-type c:== 79)
  295. (or (up-compare-goal prey-class c:== warship-class)
  296.     (up-compare-goal prey-type c:== 13))
  297. =>
  298.     (up-modify-goal answer c:+ 7))
  299. (defrule;可以致命;74
  300.     (up-compare-goal answer g:>= prey-HP)
  301. =>
  302.     ;(chat-to-player 1 "残血收割")
  303.     (up-jump-rule 1)
  304.     (up-full-reset-search)
  305.     (up-add-object-by-id 1 g: reaper-id)
  306.     (up-add-object-by-id 2 g: prey-id)
  307.     (up-target-objects 0 action-default -1 -1)
  308.     (up-modify-goal stop-attack-id c:= 0))
  309. (defrule;不可以致命;73
  310.     (up-compare-goal answer g:< prey-HP)
  311. =>
  312.     (up-modify-goal reaper-id c:= -1)
  313.     (up-get-object-data object-data-id stop-attack-id))
复制代码




评分

参与人数 1耕战 +300 鹰币 +500 收起 理由
troytroytroy + 300 + 500 耕战之功

查看全部评分

![/url]
回复

使用道具 举报

17

主题

0

精华

4万

积分

宗主教

耕战
8230
鹰币
21670
天龙币
0
回帖
540
附庸关系1
发表于 2021-4-8 02:08:37 | 显示全部楼层
今天才看到你的文章~~
回复

使用道具 举报

2

主题

0

精华

71

积分

骑士

耕战
0
鹰币
12468
天龙币
0
回帖
13
附庸关系0
发表于 2021-4-8 08:23:23 | 显示全部楼层
应该是遍历而不是例遍。
回复

使用道具 举报

14

主题

0

精华

1165

积分

伯爵

耕战
100
鹰币
320
天龙币
0
回帖
30
附庸关系0
发表于 2021-4-10 14:07:13 | 显示全部楼层
用筛选血量 升序就能找到最少血单位了
回复

使用道具 举报

21

主题

3

精华

1万

积分

征服者

耕战
3476
鹰币
2266
天龙币
0
回帖
221

第十三届火箭筒杯季军

附庸关系9
 楼主| 发表于 2021-4-10 14:28:03 | 显示全部楼层
wangzhen 发表于 2021-4-10 14:07
用筛选血量 升序就能找到最少血单位了

不仅仅是找到血少的单位,还要知道能不能一击杀死。看127行,已经在用筛选血量了。
![/url]
回复

使用道具 举报

4

主题

0

精华

295

积分

男爵

耕战
50
鹰币
70
天龙币
0
回帖
23
附庸关系0
发表于 2021-4-17 16:56:18 | 显示全部楼层
本帖最后由 xiaogaoyagn 于 2021-4-17 17:06 编辑

感谢感谢,我一直觉得我的敌人太弱了,正好可以体验一下。我复制到记事本,然后修改后缀为AI,不能用啊,是不是常数什么没定义,老大,你应该考虑下我这种文盲伸手党啊,怎么不成品打包一起发个
回复

使用道具 举报

21

主题

3

精华

1万

积分

征服者

耕战
3476
鹰币
2266
天龙币
0
回帖
221

第十三届火箭筒杯季军

附庸关系9
 楼主| 发表于 2021-4-17 20:24:57 | 显示全部楼层
xiaogaoyagn 发表于 2021-4-17 16:56
感谢感谢,我一直觉得我的敌人太弱了,正好可以体验一下。我复制到记事本,然后修改后缀为AI,不能用啊,是 ...

这不是一个完整的AI,只是给供其他AI作者做歌参考而已。单位在战斗时有选择性的攻击某些目标。相当成对战靶子还是洗洗睡吧。后缀得是per
![/url]
回复

使用道具 举报

4

主题

0

精华

295

积分

男爵

耕战
50
鹰币
70
天龙币
0
回帖
23
附庸关系0
发表于 2021-4-17 21:06:30 | 显示全部楼层
本帖最后由 xiaogaoyagn 于 2021-4-17 22:15 编辑
HudsonLee 发表于 2021-4-17 20:24
这不是一个完整的AI,只是给供其他AI作者做歌参考而已。单位在战斗时有选择性的攻击某些目标。相当成对战 ...

这什么情况

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册翔鹰会员(昵称)

x
回复

使用道具 举报

183

主题

9

精华

2万

积分

教皇

耕战
3329
鹰币
16766
天龙币
0
回帖
1200

翔鹰建站十周年纪念章

附庸关系3
发表于 2021-5-24 11:56:42 本帖来自手机 | 显示全部楼层
我的思路是:①远程搜索任何敌方正在进行攻击动作的军事单位,②剔除血量超过15点的敌人,③按血量从低到高排序,④逐一遍历残血敌人,以他为中心搜索8格范围内的己方正在战斗的军事单位,记录其剩余血量为变量<敌人剩余血量>,『次级遍历:逐一遍历范围内己方士兵,若射程<与该敌人的距离 且 <敌人剩余血量>大于0 且 其地图ID未被标记为“已派遣去收割”,则任命士兵去收割敌人,并登记其地图ID(通过指针&列表存取技术)以标记为“已派遣去收割”并附带被收割敌人的地图ID,并将<敌人剩余血量>减去<士兵攻击力>』,⑤遍历<收割者列表>中的各个“收割者”地图ID,如果其当前目标单位已不是之前“被收割者”的地图ID,则取消其“收割者”的标记及其附带的“被收割者”地图ID。
回复

使用道具 举报

本版积分规则

排行榜|小黑屋|翔鹰帝国

GMT+8, 2024-11-23 16:10 , Processed in 0.151609 second(s), 110 queries , File On.

Powered by Hawk Studio  QS Security Corp.® Licensed

Copyright © 2001-2023, Hawkaoe.net All Rights Reserved

快速回复 返回顶部 返回列表