Prolog:在列表中查找第N个元素

Jul*_*lio 1 artificial-intelligence prolog

我试图在Prolog中找到List的第n个元素.这是我试图使用的代码:

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

...

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

基本上,我试图检查一个给定的单元格是否"正常"进入.我错过了什么吗?

Ahm*_*saf 5

有一个名为nth0的预定义谓词..

5 ?- nth0(1,[1,2,3],X).
X = 2.

6 ?- listing(nth0).
lists:nth0(A, B, C) :-
        integer(A), !,
        A>=0,
        nth0_det(A, B, C).
lists:nth0(A, B, C) :-
        var(A), !,
        nth_gen(B, C, 0, A).

true.
Run Code Online (Sandbox Code Playgroud)

索引列表从0开始希望这有助于..