[英]How can I stablish a relation between two LHS in clips?
I'm trying to make a clips program in order to solve any Sokoban level but I have a huge problem: 我正在尝试制作一个剪辑程序以解决任何推箱子问题,但我遇到了一个大问题:
In this example, I only have the initial state of the field and a rule which tries to move the player to the right if there is not a box or an obstacle (in the full program I also have rules which move the boxes). 在此示例中,我仅具有该字段的初始状态,以及一条规则,如果没有框或障碍物,该规则将尝试将玩家向右移动(在完整程序中,我也具有移动框的规则)。 The problem comes when I have a state which matches with the LHS
?ff <- (R ?Ir ?Xr ?Yr $?a B ?Ib ?Xb ?Yb $?b S ?Is ?Xs ?Ys ?Es $?c W ?w D ?d L ?l F ?)
and another one, created due to the movement of the boxes, which does not allow the rule (not (R $? B ? =(+ ?Xr 1) ?Yr $?) )
to be true even if the first estate makes it true. 当我的状态与LHS
?ff <- (R ?Ir ?Xr ?Yr $?a B ?Ib ?Xb ?Yb $?b S ?Is ?Xs ?Ys ?Es $?c W ?w D ?d L ?l F ?)
和另一个由于框的运动而产生的,不允许规则(not (R $? B ? =(+ ?Xr 1) ?Yr $?) )
即使第一个遗产为真,也要为真。
(deffacts InitialState
;------static---------
(MAX_DEPTH 5)
;field
; X Y
(FIELD 8 5)
;obstacle
; X Y
(O 4 1)
(O 1 3)
(O 8 3)
(O 4 3)
(O 5 3)
(O 4 4)
(O 4 5)
;-----dynamic-----
(
;robot
; I X Y
R 1 2 4
;box
; I X Y
B 1 2 2
B 2 3 4
B 3 6 2
;storehouse
; I X Y E
S 1 7 1 0
S 2 5 4 0
S 3 5 5 0
;win
W 0 ;Posibilidad de cambiar la R por W asi paramos la ejec
; depth
D 0
;last move
;0:nothing 1:up 2:right 3:down 4:left
L 0
;father id
F 0
)
)
(defrule move_right_no_box
(MAX_DEPTH ?MD)
(FIELD ?Xf ?Yf)
?ff <- (R ?Ir ?Xr ?Yr $?a B ?Ib ?Xb ?Yb $?b S ?Is ?Xs ?Ys ?Es $?c W ?w D ?d L ?l F ?)
;comprueba que a la derecha no hay un obstacle
(not (O =(+ ?Xr 1) ?Yr) )
;comprueba que a la derecha no hay un box
(not (R $? B ? =(+ ?Xr 1) ?Yr $?) )
=>
(assert (R ?Ir (+ ?Xr 1) ?Yr $?a B ?Ib ?Xb ?Yb $?b S ?Is ?Xs ?Ys ?Es $?c W ?w D (+ ?d 1) L 2 F ?ff))
)
For example, I have a state which do not have a box or an obstacle in the right, but I have another state which does. 例如,我的状态右边没有盒子或障碍物,但是我有另一种状态。 I need a way to establish a relation between the rules:
?ff <- (R ?Ir ?Xr ?Yr $?a B ?Ib ?Xb ?Yb $?b S ?Is ?Xs ?Ys ?Es $?c W ?w D ?d L ?l F ?)
and (not (R $? B ? =(+ ?Xr 1) ?Yr $?) )
in order to make sure that they are referring to the same state (and a different state, which is different from the one that I'm evaluating, is not interfering). 我需要一种建立规则之间关系的方法:
?ff <- (R ?Ir ?Xr ?Yr $?a B ?Ib ?Xb ?Yb $?b S ?Is ?Xs ?Ys ?Es $?c W ?w D ?d L ?l F ?)
和(not (R $? B ? =(+ ?Xr 1) ?Yr $?) )
,以确保它们指的是相同状态(和不同状态)。状态(与我正在评估的状态不同)没有干扰)。
I other words, what I need is a way to make sure that both LHS are evaluating the same state. 换句话说,我需要的是一种确保两个LHS都评估相同状态的方法。 Thanks!
谢谢!
PD1: I can't use something like an ID because it makes the execution of the program too slow. PD1:我不能使用ID之类的东西,因为它会使程序的执行速度太慢。
声明一个事实,其中包含有关两个规则匹配的状态的信息。
Okay, at the end I could not found a way to make sure that two LHS are evaluating the same state, so I solved the problem using the 'member' function: https://www.csie.ntu.edu.tw/~sylee/courses/clips/bpg/node12.2.3.html 好的,最后我找不到确保两个LHS正在评估同一状态的方法,因此我使用“成员”功能解决了该问题: https : //www.csie.ntu.edu.tw/~ sylee /场/短片/ BPG / node12.2.3.html
I can create a LHS rule which always returns True and is composed of multifield variables and then using the member function check if part of the rule satisfies my condition. 我可以创建一个LHS规则,该规则始终返回True,并且由多字段变量组成,然后使用成员函数检查规则的一部分是否满足我的条件。
Another option (even if I'm not sure this works due to I have not tested it) is to evaluate all the conditions in one LHS using this: https://www.csie.ntu.edu.tw/~sylee/courses/clips/bpg/node5.4.1.4.html 另一种选择(即使由于我尚未测试而无法确定是否可行),也可以使用以下方法评估一个LHS中的所有条件: https : //www.csie.ntu.edu.tw/~sylee/courses /clips/bpg/node5.4.1.4.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.