旧月 发表于 2010-8-27 19:28:25

判断AI军力优势/劣势的代码

RT
从AI里找到的
可以用这个确定出的兵的类型 是否进攻等等

用GOAL也可以做,但是用一个废弃的策略值来更好。因为策略值可以用来比较大小。例如,如果我的军力优势达到某个程度,就进攻。否则就防守。

策略值215(原来忘记是什么了,反正没太大用处),这里用来判断军力优劣势.

      -2 = 敌方军力比我方多20个以上
      -1 = 敌方军力比我方多10个以上
         0 = 敌方军力与我方相近(十个以内)
         1 = 敌方军力比我方少10个以上
         2 = 敌方军力比我方少20个以上

(defrule;初始化
   (true)
   =>
   (set-strategic-number 215 0)
)

(defrule
   (or(military-population > 195)
      (or(and(military-population > 190)
             (players-military-population every-enemy < 180))
          (or(and(military-population > 180)
               (players-military-population every-enemy < 170))
             (and(military-population > 170)
               (players-military-population every-enemy < 160)))))
   =>
   (set-strategic-number 215 1)
)

(defrule
   (or(and(military-population > 160)
          (players-military-population every-enemy < 150))
      (or(and(military-population > 150)
             (players-military-population every-enemy < 140))
          (or(and(military-population > 140)
               (players-military-population every-enemy < 130))
             (and(military-population > 130)
               (players-military-population every-enemy < 120)))))
   =>
   (set-strategic-number 215 1)
)

(defrule
   (or(and(military-population > 120)
          (players-military-population every-enemy < 110))
      (or(and(military-population > 110)
             (players-military-population every-enemy < 100))
          (or(and(military-population > 100)
               (players-military-population every-enemy < 90))
             (and(military-population > 90)
               (players-military-population every-enemy < 80)))))
   =>
   (set-strategic-number 215 1)
)

(defrule
   (or(and(military-population > 80)
          (players-military-population every-enemy < 70))
      (or(and(military-population > 70)
             (players-military-population every-enemy < 60))
          (or(and(military-population > 60)
               (players-military-population every-enemy < 50))
             (and(military-population > 50)
               (players-military-population every-enemy < 40)))))
   =>
   (set-strategic-number 215 1)
)

(defrule
   (or(and(military-population > 40)
          (players-military-population every-enemy < 30))
      (or(and(military-population > 30)
             (players-military-population every-enemy < 20))
          (or(and(military-population > 20)
               (players-military-population every-enemy < 10))
             (and(military-population > 10)
               (players-military-population every-enemy == 0)))))
   =>
   (set-strategic-number 215 1)
)

(defrule
   (or(military-population > 200)
      (or(and(military-population > 190)
             (players-military-population every-enemy < 170))
          (or(and(military-population > 180)
               (players-military-population every-enemy < 160))
             (and(military-population > 170)
               (players-military-population every-enemy < 150)))))
   =>
   (set-strategic-number 215 2)
)

(defrule
   (or(and(military-population > 160)
          (players-military-population every-enemy < 140))
      (or(and(military-population > 150)
             (players-military-population every-enemy < 130))
          (or(and(military-population > 140)
               (players-military-population every-enemy < 120))
             (and(military-population > 130)
               (players-military-population every-enemy < 110)))))
   =>
   (set-strategic-number 215 2)
)

(defrule
   (or(and(military-population > 120)
          (players-military-population every-enemy < 100))
      (or(and(military-population > 110)
             (players-military-population every-enemy < 90))
          (or(and(military-population > 100)
               (players-military-population every-enemy < 80))
             (and(military-population > 90)
               (players-military-population every-enemy < 70)))))
   =>
   (set-strategic-number 215 2)
)

(defrule
   (or(and(military-population > 80)
          (players-military-population every-enemy < 60))
      (or(and(military-population > 70)
             (players-military-population every-enemy < 50))
          (or(and(military-population > 60)
               (players-military-population every-enemy < 40))
             (and(military-population > 50)
               (players-military-population every-enemy < 30)))))
   =>
   (set-strategic-number 215 2)
)

(defrule
   (or(and(military-population > 40)
          (players-military-population every-enemy < 20))
      (or(and(military-population > 30)
             (players-military-population every-enemy < 10))
         (and(military-population > 20)
             (players-military-population every-enemy == 0))))
   =>
   (set-strategic-number 215 2)
)

(defrule
   (or(and(military-population == 0)
          (players-military-population any-enemy > 10))
      (or(and(military-population < 10)
             (players-military-population any-enemy > 20))
          (or(and(military-population < 20)
               (players-military-population any-enemy > 30))
             (and(military-population < 30)
               (players-military-population any-enemy > 40)))))
   =>
   (set-strategic-number 215 -1)
)

(defrule
   (or(and(military-population < 40)
          (players-military-population any-enemy > 50))
      (or(and(military-population < 50)
             (players-military-population any-enemy > 60))
          (or(and(military-population < 60)
               (players-military-population any-enemy > 70))
             (and(military-population < 70)
               (players-military-population any-enemy > 80)))))
   =>
   (set-strategic-number 215 -1)
)

(defrule
   (or(and(military-population < 80)
          (players-military-population any-enemy > 90))
      (or(and(military-population < 90)
             (players-military-population any-enemy > 100))
          (or(and(military-population < 100)
               (players-military-population any-enemy > 110))
             (and(military-population < 110)
               (players-military-population any-enemy > 120)))))
   =>
   (set-strategic-number 215 -1)
)

(defrule
   (or(and(military-population < 120)
          (players-military-population any-enemy > 130))
      (or(and(military-population < 130)
             (players-military-population any-enemy > 140))
          (or(and(military-population < 140)
               (players-military-population any-enemy > 150))
             (and(military-population < 150)
               (players-military-population any-enemy > 160)))))
   =>
   (set-strategic-number 215 -1)
)

(defrule
   (or(and(military-population < 160)
          (players-military-population any-enemy > 170))
      (or(and(military-population < 170)
             (players-military-population any-enemy > 180))
          (or(and(military-population < 180)
               (players-military-population any-enemy > 190))
             (and(military-population < 190)
               (players-military-population any-enemy > 200)))))
   =>
   (set-strategic-number 215 -1)
)

(defrule
   (or(and(military-population == 0)
          (players-military-population any-enemy > 20))
      (or(and(military-population < 10)
             (players-military-population any-enemy > 30))
          (or(and(military-population < 20)
               (players-military-population any-enemy > 40))
             (and(military-population < 30)
               (players-military-population any-enemy > 50)))))
   =>
   (set-strategic-number 215 -2)
)

(defrule
   (or(and(military-population < 40)
          (players-military-population any-enemy > 60))
      (or(and(military-population < 50)
             (players-military-population any-enemy > 70))
          (or(and(military-population < 60)
               (players-military-population any-enemy > 80))
             (and(military-population < 70)
               (players-military-population any-enemy > 90)))))
   =>
   (set-strategic-number 215 -2)
)

(defrule
   (or(and(military-population < 80)
          (players-military-population any-enemy > 100))
      (or(and(military-population < 90)
             (players-military-population any-enemy > 110))
          (or(and(military-population < 100)
               (players-military-population any-enemy > 120))
             (and(military-population < 110)
               (players-military-population any-enemy > 130)))))
   =>
   (set-strategic-number 215 -2)
)

(defrule
   (or(and(military-population < 120)
          (players-military-population any-enemy > 140))
      (or(and(military-population < 130)
             (players-military-population any-enemy > 150))
          (or(and(military-population < 140)
               (players-military-population any-enemy > 160))
             (and(military-population < 150)
               (players-military-population any-enemy > 170)))))
   =>
   (set-strategic-number 215 -2)
)

(defrule
   (or(and(military-population < 160)
          (players-military-population any-enemy > 180))
      (or(and(military-population < 170)
             (players-military-population any-enemy > 190))
          (or(and(military-population < 180)
               (players-military-population any-enemy > 200))
             (and(military-population < 190)
               (players-military-population any-enemy > 210)))))
   =>
   (set-strategic-number 215 -2)
)

旧月 发表于 2010-8-27 23:06:26

只是个范本而已。。说明大概原理而已。。

lws735 发表于 2010-8-28 07:27:41

原帖由 787918944 于 2010-8-27 22:51 发表 https://www.hawkaoe.net/bbs/images/common/back.gif
我就缺军事判断这方面的知识,给老胡补上了,谢谢啊。

我就缺军事判断这方面的知识,给老胡补上了,谢谢啊。

老胡==旧月?

旧月 发表于 2010-8-28 08:29:35

旧不就是古吗。。。。。。。。。。。。。古月。。。。。。

bingbing 发表于 2010-9-1 14:09:48

Kosmos是利用了废弃的策略值sn-attack-diplomacy-impact
(defconst war-situation sn-attack-diplomacy-impact)
判断语句基本类似。如果自己编写的AI想用,直接复制过去就行了。

旧月 发表于 2010-9-1 22:51:34

感谢楼上指出。话说哪里有策略值和ID的对应表?
另外我觉得还可以用别的没用的策略值,例如零指令

bingbing 发表于 2010-9-6 12:47:23

策略值和ID的对应表,官方没有给出吧?
我找了一个Kosmos网页的链接,是日文的,只有部分ID值:
https://members.at.infoseek.co.jp/aocai/tutorial/ref_sn01.html

在Kosmos里,以下重定义了这三个策略值:
sn-minimum-boar-hunt-group-size(最小打野猪人数,原来根本没用,大家都知道电脑是不打野猪的)
sn-attack-diplomacy-impact(攻击对友好度影响,在锁定组队的情况下是没用的,没有锁定组队的情况下,我不清楚是否有用)
sn-required-forest-tiles(建造伐木场所需树林方格,用这个要慎重,它的值不能太小)

旧月 发表于 2010-9-6 22:55:53

谢谢楼上指出了,最近在研究策略值。

bingbing 发表于 2010-9-19 10:29:21

我周末玩帝国发现这种判断方式的一个缺点:
只判断了数量,没有判断质量。
两个AI对打(KOSMOS vs the Horde),KOMOS在出叉叉+毛毛,the Horde出骑士+骑射手,双方都暴了很多兵,KOSMOS判断自己的兵比对方多了一点,处于优势,因此进攻,结果可想而知--大败。
结论是最好在条件上加上自己的兵种策略,如果是便宜的兵,要比对方多不少时才断定为优势。
页: [1]
查看完整版本: 判断AI军力优势/劣势的代码