Jess itself doesn't have a data structure like that. You could use a Java list-of-lists, but it would be awkward to manipulate from Jess. Fortunately, a game board is usually a sparse matrix, meaning that most positions are empty, and you therefore only need to represent the ones that are not. You can either put coordinates directly into your game object template -- i.e., x
and y
here:
(deftemplate game-object (slot name) (slot type) (slot x) (slot y) ...)
Or you can use a separate "position" template and match it with game objects using an id, like
(deftemplate game-object (slot name) (slot type) (slot id) ...)
(deftemplate location (slot id) (slot x) (slot y))
One important insight is that pattern matching makes loops over all objects unnecessary. For example, say you want to check if there are no other characters in the same row as your "hero" character. You can just write something like this, no looping required:
(defrule no-character-in-same-row-as-hero
(game-object (name hero) (y ?y))
(not (game-object (name ~hero) (y ?y)))
=>
// Do whatever you want, knowing that no other characters are in the same row
)