1

適切な座標でオブジェクト (文字 # オブジェクト I) をボードに印刷するにはどうすればよいですか?

(deftemplate cenario
(slot min-line)
(slot max-line)
(slot min-column)
(slot max-column))

(deftemplate line
(slot index))

(deftemplate column
(slot index))

(deftemplate coordinate
(slot line)
(slot column))

(deftemplate object
(multislot coordinate))

(deffacts cenario
(cenario
(min-line 1)
(max-line 24)
(min-column 1)
(max-column 12)))

(deffacts line
(line (index 1))
(line (index 2))
(line (index 3))
(line (index 4))
(line (index 5))
(line (index 6))
(line (index 7))
(line (index 8))
(line (index 9))
(line (index 10))
(line (index 11))
(line (index 12))
(line (index 13))
(line (index 14))
(line (index 15))
(line (index 16))
(line (index 17))
(line (index 18))
(line (index 19))
(line (index 20))
(line (index 21))
(line (index 22))
(line (index 23))
(line (index 24)))

(deffacts column
(column (index 1))
(column (index 2))
(column (index 3))
(column (index 4))
(column (index 5))
(column (index 6))
(column (index 7))
(column (index 8))
(column (index 9))
(column (index 10))
(column (index 11))
(column (index 12)))

(deffacts I
(object (coordinate 5 24) (coordinate 6 24) (coordinate 7 24) (coordinate 8 24))))

(defrule startcolumn
(not(columnCurrent))
(cenario (min-column ?x))
=>
(assert(columnCurrent ?x)))

(defrule startline
(not(lineCurrent))
(cenario (max-line ?x))
=>
(assert(lineCurrent ?x)))

(defrule print-board
(cenario (max-column ?maxcol))
?f <- (line (index ?i))
?g <- (columnCurrent ?ca&:(<= ?ca ?maxcol))
(not (object (coordinate ?i ?ca)))
(lineCurrent ?i)
=>
(retract ?g)
(assert (columnCurrent (+ ?ca 1)))
(printout t "?"))

(defrule print-object
(lineCurrent ?i)
(columnCurrent ?ca)
(object (coordinate ?i ?ca ))
=>
(printout t ?i " " ?ca ))

(defrule change-line
(cenario (max-column ?maxcol))
?f <- (line (index ?i))
?g <- (columnCurrent 13)
(lineCurrent ?i)
=>
(retract ?f)
(assert (columnCurrent 1))
(assert (lineCurrent (- ?i 1)))
(printout t crlf))

この最終結果が欲しい:

????####????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????

????????????
4

2 に答える 2

0

マルチスロットにはオブジェクトが含まれていますが、リスト項目内のオブジェクトを一致させることはできません。これは機能しません:

(object $? (coordinate ?i ?ca ) $?)

座標ペアを文字列 (または折り畳まれた整数) として格納できるはずです。

(deffacts I
(object (coordinate "5.23"  "6.23" "7.2" "8.2")))

そして、次のようにパターンを書き直します

(object (coordinate $? ?x&=(str-cat ?i "." ?ca) $?)))

(行のループはうまく機能しませんが、この完全に非宣言的なルール コードで時間を無駄にしたくありません。申し訳ありません。)

于 2014-03-19T12:41:11.753 に答える