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

[求助] AI中如何判断下列情况?

 关闭 [复制链接]

23

主题

0

精华

8785

积分

国王

耕战
1422
鹰币
36
天龙币
0
回帖
293
附庸关系0
发表于 2010-8-26 14:15:56 | 显示全部楼层 |阅读模式
1.如何判断有几个人类同盟
2.如何判断有几个电脑同盟
3.如何判断有几个同盟
4.如何判断有几个人类敌人
5.如何判断有几个电脑敌人
6.如何判断有几个敌人

有点啰嗦,哪位老师知道?
回复

使用道具 举报

2

主题

0

精华

160

积分

男爵

耕战
4
鹰币
150
天龙币
0
回帖
72
附庸关系0
发表于 2010-9-1 14:42:19 | 显示全部楼层
我有个笨办法,对第1-8家挨个判断
以下是判断本队中有多少个电脑的代码(注自己也算一家电脑),其他请照葫芦画瓢
;--------------------
;--     goal ID    --
;--------------------
;如果与其他goal ID定义冲突,请修改
(defconst g-team                                          1)
(defconst g-team-tmp                                      2)
(defconst timer-team-judge-triggered                      3);


;--------------------
;--    定时器ID    --
;--------------------
;如果与其他定时器ID定义冲突,请修改
;注意,定时器最多只能有10个,其值不能大于10
(defconst TIMER-TEAM-JUDGE         10)


;--------------------
;-     常量    --
;宏的值不存在冲突问题,不需要修改
;--------------------

(defconst FALSE                    0)
(defconst TRUE                     1)

;g-team,g-team-tmp可能的值,
(defconst TEAM-0MEMBER             0);0人组队
(defconst TEAM-1MEMBER             1);1人组队
(defconst TEAM-2MEMBER             2);2人组队
(defconst TEAM-3MEMBER             3);3人组队
(defconst TEAM-4MEMBER             4);4人组队
(defconst TEAM-5MEMBER             5);5人或5人以上组队



;初始化
(defrule
    (true)
=>
    (set-goal g-team                      TEAM-1MEMBER)
    (set-goal g-team-tmp                  TEAM-1MEMBER)
    (set-goal timer-team-judge-triggered         FALSE)
    (enable-timer TIMER-TEAM-JUDGE 60)
    (disable-self)
)


;循环判断
;判断在游戏里的本组电脑数量(注:自己也算一个)

(defrule
    (timer-triggered TIMER-TEAM-JUDGE)
=>
    (set-goal timer-team-judge-triggered TRUE)
    (set-goal g-team-tmp          TEAM-1MEMBER)
)

;判断1p

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 1))
        (player-in-game 1)
        (player-computer 1)
        (stance-toward 1 ally)
        (goal g-team-tmp TEAM-1MEMBER)
=>
        (set-goal g-team-tmp TEAM-2MEMBER)
)

;判断2p
(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 2))
        (player-in-game 2)
        (player-computer 2)
        (stance-toward 2 ally)
        (goal g-team-tmp TEAM-2MEMBER)
=>
        (set-goal g-team-tmp TEAM-3MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 2))
        (player-in-game 2)
        (player-computer 2)
        (stance-toward 2 ally)
        (goal g-team-tmp TEAM-1MEMBER)
=>
        (set-goal g-team-tmp TEAM-2MEMBER)
)


;判断3p
(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 3))
        (player-in-game 3)
        (player-computer 3)
        (stance-toward 3 ally)
        (goal g-team-tmp TEAM-3MEMBER)
=>
        (set-goal g-team-tmp TEAM-4MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 3))
        (player-in-game 3)
        (player-computer 3)
        (stance-toward 3 ally)
        (goal g-team-tmp TEAM-2MEMBER)
=>
        (set-goal g-team-tmp TEAM-3MEMBER)
)
(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 3))
        (player-in-game 3)
        (player-computer 3)
        (stance-toward 3 ally)
        (goal g-team-tmp TEAM-1MEMBER)
=>
        (set-goal g-team-tmp TEAM-2MEMBER)
)

;判断4p

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 4))
        (player-in-game 4)
        (player-computer 4)
        (stance-toward 4 ally)
        (goal g-team-tmp TEAM-4MEMBER)
=>
        (set-goal g-team-tmp TEAM-5MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 4))
        (player-in-game 4)
        (player-computer 4)
        (stance-toward 4 ally)
        (goal g-team-tmp TEAM-3MEMBER)
=>
        (set-goal g-team-tmp TEAM-4MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 4))
        (player-in-game 4)
        (player-computer 4)
        (stance-toward 4 ally)
        (goal g-team-tmp TEAM-2MEMBER)
=>
        (set-goal g-team-tmp TEAM-3MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 4))
        (player-in-game 4)
        (player-computer 4)
        (stance-toward 4 ally)
        (goal g-team-tmp TEAM-1MEMBER)
=>
        (set-goal g-team-tmp TEAM-2MEMBER)
)


;判断5p
(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 5))
        (player-in-game 5)
        (player-computer 5)
        (stance-toward 5 ally)
        (goal g-team-tmp TEAM-4MEMBER)
=>
        (set-goal g-team-tmp TEAM-5MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 5))
        (player-in-game 5)
        (player-computer 5)
        (stance-toward 5 ally)
        (goal g-team-tmp TEAM-3MEMBER)
=>
        (set-goal g-team-tmp TEAM-4MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 5))
        (player-in-game 5)
        (player-computer 5)
        (stance-toward 5 ally)
        (goal g-team-tmp TEAM-2MEMBER)
=>
        (set-goal g-team-tmp TEAM-3MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 5))
        (player-in-game 5)
        (player-computer 5)
        (stance-toward 5 ally)
        (goal g-team-tmp TEAM-1MEMBER)
=>
        (set-goal g-team-tmp TEAM-2MEMBER)
)

;判断6p
(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 6))
        (player-in-game 6)
        (player-computer 6)
        (stance-toward 6 ally)
        (goal g-team-tmp TEAM-4MEMBER)
=>
        (set-goal g-team-tmp TEAM-5MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 6))
        (player-in-game 6)
        (player-computer 6)
        (stance-toward 6 ally)
        (goal g-team-tmp TEAM-3MEMBER)
=>
        (set-goal g-team-tmp TEAM-4MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 6))
        (player-in-game 6)
        (player-computer 6)
        (stance-toward 6 ally)
        (goal g-team-tmp TEAM-2MEMBER)
=>
        (set-goal g-team-tmp TEAM-3MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 6))
        (player-in-game 6)
        (player-computer 6)
        (stance-toward 6 ally)
        (goal g-team-tmp TEAM-1MEMBER)
=>
        (set-goal g-team-tmp TEAM-2MEMBER)
)


;判断7p
(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 7))
        (player-in-game 7)
        (player-computer 7)
        (stance-toward 7 ally)
        (goal g-team-tmp TEAM-4MEMBER)
=>
        (set-goal g-team-tmp TEAM-5MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 7))
        (player-in-game 7)
        (player-computer 7)
        (stance-toward 7 ally)
        (goal g-team-tmp TEAM-3MEMBER)
=>
        (set-goal g-team-tmp TEAM-4MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 7))
        (player-in-game 7)
        (player-computer 7)
        (stance-toward 7 ally)
        (goal g-team-tmp TEAM-2MEMBER)
=>
        (set-goal g-team-tmp TEAM-3MEMBER)
)
(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 7))
        (player-in-game 7)
        (player-computer 7)
        (stance-toward 7 ally)
        (goal g-team-tmp TEAM-1MEMBER)
=>
        (set-goal g-team-tmp TEAM-2MEMBER)
)

;判断8p
(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 8))
        (player-in-game 8)
        (player-computer 8)
        (stance-toward 8 ally)
        (goal g-team-tmp TEAM-4MEMBER)
=>
        (set-goal g-team-tmp TEAM-5MEMBER)
)
(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 8))
        (player-in-game 8)
        (player-computer 8)
        (stance-toward 8 ally)
        (goal g-team-tmp TEAM-3MEMBER)
=>
        (set-goal g-team-tmp TEAM-4MEMBER)
)
(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 8))
        (player-in-game 8)
        (player-computer 8)
        (stance-toward 8 ally)
        (goal g-team-tmp TEAM-2MEMBER)
=>
        (set-goal g-team-tmp TEAM-3MEMBER)
)
(defrule
    (goal timer-team-judge-triggered TRUE)
        (not(player-number 8))
        (player-in-game 8)
        (player-computer 8)
        (stance-toward 8 ally)
        (goal g-team-tmp TEAM-1MEMBER)
=>
        (set-goal g-team-tmp TEAM-2MEMBER)
)

(defrule
    (goal timer-team-judge-triggered TRUE)
    (goal g-team-tmp          TEAM-1MEMBER)
=>
    (set-goal g-team          TEAM-1MEMBER)
    (chat-local "一人组队")
)

(defrule
    (goal timer-team-judge-triggered TRUE)
    (goal g-team-tmp          TEAM-2MEMBER)
=>
    (set-goal g-team          TEAM-2MEMBER)
    (chat-local "两人组队")
)

(defrule
    (goal timer-team-judge-triggered TRUE)
    (goal g-team-tmp          TEAM-3MEMBER)
=>
    (set-goal g-team          TEAM-3MEMBER)
    (chat-local "三人组队")
)

(defrule
    (goal timer-team-judge-triggered TRUE)
    (goal g-team-tmp          TEAM-4MEMBER)
=>
    (set-goal g-team          TEAM-4MEMBER)
    (chat-local "四人组队")
)

(defrule
    (goal timer-team-judge-triggered TRUE)
    (goal g-team-tmp          TEAM-5MEMBER)
=>
    (set-goal g-team          TEAM-5MEMBER)
    (chat-local "五人或五人以上组队")
)

;一轮判断完毕后,重新启动定时器
(defrule
    (goal timer-team-judge-triggered TRUE)
=>
    (set-goal timer-team-judge-triggered FALSE)
    (enable-timer TIMER-TEAM-JUDGE 60)
)
回复

使用道具 举报

2

主题

0

精华

160

积分

男爵

耕战
4
鹰币
150
天龙币
0
回帖
72
附庸关系0
发表于 2010-9-1 14:55:17 | 显示全部楼层
我认为对1-8家依次判断是唯一可行的办法。
反例是Kosmos中的代码:
(defrule
    (players-tribute any-ally food < 2000)                  
    (player-in-game every-ally)                             
    (food-amount >= 3000)                                   
=>
    (tribute-to-player this-any-ally food 1000)
)

这段代码本意是实现资源共享的,
但是却有两个问题:
1 只有序号最小的同盟才会收到贡品
例如我创建了游戏,我是1p,序号最小,跟我结盟的kosmos老是进贡给我,而其他同盟则收不到
2 任何一家同盟退出都会造成该机制停摆
如果有一家退出,(player-in-game every-ally) 就成了false
回复

使用道具 举报

23

主题

0

精华

8785

积分

国王

耕战
1422
鹰币
36
天龙币
0
回帖
293
附庸关系0
 楼主| 发表于 2010-9-1 17:25:30 | 显示全部楼层
收下仔细研究,谢了
收下仔细研究,谢了
回复

使用道具 举报

本版积分规则

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

GMT+8, 2024-11-23 05:14 , Processed in 0.155322 second(s), 57 queries , File On.

Powered by Hawk Studio  QS Security Corp.® Licensed

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

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