1

I'm reading through these prolog tutorials and I feel like i'm getting a decent grasp on some of the concepts they use but i'm having an issue trying to implement a grid like system.

I know I could set this up with a list, but so far i'm drawing blanks on how to implement it, is there a resource or some type of source code I look at to guide me through how to do a grid system in prolog?

The grid system I want to make from scratch would be a 4x4 and it should print out to be like this

(4,1) (4,2) (4,3) (4,4)

(3,1) (3,2) (3,3) (3,4)

(2,1) (2,2) (2,3) (2,4)

(1,1) (1,2) (1,3) (1,4)

For the comments

The reason I need this in a grid is because i'm starting to build a maze like structure for a wumpus world i'm creating, I think this is how I should approach this but i'm having an issue creating a type of list to satisfy this type of structure I want.

This is to where I can assign a square(piece of the grid) such as (3,2) to be a pit or wumpus or gold in any of the squares I want for my agent to traverse this grid.

If this is the wrong way to approach this I would appreciate why it isn't and hopefully get some feedback on what I need to be concentrating on.

If this wrong I would appreciate any feedback regardless.

false
  • 10,264
  • 13
  • 101
  • 209
Frontier
  • 139
  • 1
  • 4
  • 12
  • 3
    What form should that "grid" have? Do you want a data-structure that *represents* a grid or would you rather want to output a grid via side-effects? – repeat Apr 10 '15 at 05:41
  • 3
    The question by @repeat is very reasonable: what are you going to do with the grid? Why do you need to print it out like this? Do you really need to print it like this, or you you just need a data structure with a similar layout? –  Apr 10 '15 at 09:44
  • This is for the wumpus world example that I found online, i've never done logic programming like this so i'm trying to set this up in a way so I that I can assign each square(coordinate) to either a pit, wumpus, or gold, giving those coordinates facts. I then need my agent to traverse though these lists/squares/coordinates to kill the wumpus if need be, and to retrieve the gold then go back to 1,1 (where he always starts). – Frontier Apr 10 '15 at 18:57
  • 1
    The only thing you're showing is a generic display of the standard x, y grid coordinates for a 4x4 grid with origin in the lower left corner. I'm not sure what the *approach* is that you're referring to. I don't see any Prolog code, and I don't see how you are currently thinking you're determining whether a given location has a pit, wumpus, or gold. Perhaps clarify a little? Have you looked up Prolog list structures? It's the primary structure in Prolog for doing things. – lurker Apr 10 '15 at 20:39
  • The previous comments asked for context of what this grid was going to be used for, as given a scope for the problem I have, i've been trying to implement it like a list but so far have come up with errors and I really don't understand the syntax of the operations I need to be using to create such a grid, that's why i'm asking. I have no intention of asking for help with including additive things (like wumpus location and where pits are located) that will come later, I just want to set up a grid so I can start manipulating it, I basically need to create a structure to mess around with. – Frontier Apr 10 '15 at 21:43

1 Answers1

2

You can use a list of lists to represent your grid
[[4,1,I41], [4,2,I42], ... [0,4,I04]]
where each sublist has the coordinates and information on what is in each cell.

This list could then be rewritten into another similar list as a result of applying some operator to it (for instance, moving the content of a cell to another one). The rewriting will be done by appropriate predicates and this is the usual Logic Programming recipe in contrast to what happens in imperative languages where the content of the data structure would be modified by assignments to the cells.

There is a more elaborate approach if the grid is large, using a cyclic-term (rational tree) for representing the grid and "moving" in it, with a separate term for the grid contents that is rewritten as above.

migfilg
  • 542
  • 2
  • 9