我是下一个董事会:
board :- ([[-,-,-,-,-,-,-],[-,-,-,-,-,-,-],[-,-,-,-,-,-,-],[-,-,-,-,-,-,-],[-,-,-,-,-,-,-],[-,-,-,-,-,-,-]]).
其中每列代表一个子列表。
我的编解码器是:
printBoard(T) :- write(' A B C D E F G'), nl, printLine(T,6).
printLine(_, 0).
printLine([P1,P2,P3,P4,P5,P6,P7], N) :- write(N), ith(N,P1,C), imp(C), write(' '),
ith(N,P2,C), imp(C), write(' '),
ith(N,P3,C), imp(C), write(' '),
ith(N,P4,C), imp(C), write(' '),
ith(N,P5,C), imp(C), write(' '),
ith(N,P6,C), imp(C), write(' '),
ith(N,P7,C), imp(C), write(' '),
nl, J is N -1, printLine([P1,P2,P3,P4,P5,P6,P7],J),!.
哪里
imp(o):- write(o).
imp(x):- write(x).
imp(-):- write(-).
% ith(I,L,Z) := Z is the Ith element of list L
% := on L = emptylist returns a space
ith(_,[],' ').
ith(1,[Y|_],Z) :- Y=Z.
ith(I,[_|W],Z) :- J is I-1, ith(J,W,Z).
但没有找到,prolog说不,只画'A B C D E F G'。因为? 哪个错误?感谢的
这是我的意见:
printBoard([[a,-,-,-,-,-,-],[b,-,-,-,-,-,-],[c,-,-,-,-,-,-],[d,-,-,-,-,-,-],[e,-,-,-,-,-,-],[f,-,-,-,-,-,-]]).
但我想要你出去:
A B C D E F G
a b c d e f g
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
最后我这样做了
printBoard(T) :- write(' A B C D E F G'), nl, printLine(T).
printLine([[],[],[],[],[],[],[]]).
rintLine([[P1|P1X],[P2|P2X],[P3|P3X],[P4|P4X],[P5|P5X],[P6|P6X],[P7|P7X]]) :-
imp(P1), write(' '),
imp(P2), write(' '),
imp(P3), write(' '),
imp(P4), write(' '),
imp(P5), write(' '),
imp(P6), write(' '),
imp(P7), write(' '), nl, J is N -1, printLine([P1X,P2X,P3X,P4X,P5X,P6X,P7X],J),!.