質問

I am making a tetris game in Jess language and I have made this algorithm to rotate the T piece.

(defrule rotateTPiece
?g<-(piece (id 4) (x1 ?x1) (y1 ?y1)
                  (x2 ?x2) (y2 ?y2)
                  (x3 ?x3) (y3 ?y3)
                  (x4 ?x4) (y4 ?y4))
=>
(bind ?lowerx (min ?x1 ?x2 ?x3 ?x4))
(bind ?lowery (min ?y1 ?y2 ?y3 ?y4))

(modify ?g  
(x1 (- ?x1 ?lowerx)) (y1 (- ?y1 ?lowery)) 
(x2 (- ?x2 ?lowerx)) (y2 (- ?y2 ?lowery)) 
(x3 (- ?x3 ?lowerx)) (y3 (- ?y3 ?lowery))
(x4 (- ?x4 ?lowerx)) (y4 (- ?y4 ?lowery)))  

(modify ?g  
(x1 ?y1) (y1 (- 1 (- ?x1 1))) 
(x2 ?y2) (y2 (- 1 (- ?x2 1)))
(x3 ?y3) (y3 (- 1 (- ?x3 1)))
(x4 ?y4) (y4 (- 1 (- ?x4 1))))

(modify ?g
    (x1 (+ ?x1 ?lowerx)) (y1 (+ ?y1 ?lowery))
    (x2 (+ ?x2 ?lowerx)) (y2 (+ ?y2 ?lowery))
    (x3 (+ ?x3 ?lowerx)) (y3 (+ ?y3 ?lowery))
    (x4 (+ ?x4 ?lowerx)) (y4 (+ ?y4 ?lowery)))

(focus VISUAL))

In first modify I translate the piece to the origin, then I modify it to make a rotation and then I translate it to the inicial position. I don't know why but this is not working.

役に立ちましたか?

解決

Slot bindings are by value, so ?x1 refers to the value in slot x1 at the time the right hand side is entered. Replace the first and second modify, using the pattern

(bind ?tx1 (- ?x1 ?lowerx))

and

(bind ?ux1 ?tx1)   

and the last modify becomes

(modify ?g
(x1 (+ ?ux1 ?lowerx)) ... )
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top