Prolog: Finding the Nth Element in a List

Posted by Thomas on Stack Overflow See other posts from Stack Overflow or by Thomas
Published on 2010-04-06T04:09:12Z Indexed on 2010/04/06 4:13 UTC
Read the original article Hit count: 210

I am attempting to locate the nth element of a List in Prolog. Here is the code I am attempting to use:

Cells = [OK, _, _, _, _, _] .

...

next_safe(_) :-
facing(CurrentDirection),
delta(CurrentDirection, Delta), 
in_cell(OldLoc), 
NewLoc is OldLoc + Delta,
nth1(NewLoc, Cells, SafetyIdentifier),
SafetyIdentifier = OK .

Basically, I am trying to check to see if a given cell is "OK" to move into. Am I missing something?

© Stack Overflow or respective owner

Related posts about prolog

Related posts about artificial-intelligence