我对 prolog 谓词有疑问。
我有一个棋盘,我想检查一个玩家何时没有值在 1 到 10 之间的棋子,称为移动棋子。代码如上所示:
test_board([
[piece(' ',12,blk),piece('R2 ',2,red),piece('RB ',11,red),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk)],
[piece(' ',12,blk),piece('RB ',11,red),piece('RF ',0,red),piece('RB ',11,red),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece('RB ',11,red),piece(' ',12,blk),piece(' ',12,blk)],
[piece(' ',12,blk),piece(' ',12,blk),piece('RB ',11,red),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk)],
[piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk),piece(' ',12,blk)],
[piece(' ',12,blk),piece(' ',12,blk),piece('X ',13,for),piece('X ',13,for),piece(' ',12,blk),piece(' ',12,blk),piece('X ',13,for),piece('X ',13,for),piece(' ',12,blk),piece(' ',12,blk)],
[piece(' ',12,blk),piece(' ',12,blk),piece('X ',13,for),piece('X ',13,for),piece(' ',12,blk),piece(' ',12,blk),piece('X ',13,for),piece('X ',13,for),piece(' ',12,blk),piece(' ',12,blk)],
[piece('B6 ', 6,blue),piece('B4 ', 4,blue),piece('B5 ', 5,blue),piece('B10',10,blue),piece('B7 ', 7,blue),piece('B4 ', 4,blue),piece('B8 ', 8,blue),piece('B9 ', 9,blue),piece('B5 ', 5,blue),piece('B4 ', 4,blue)],
[piece('B7 ', 7,blue),piece('B2 ', 2,blue),piece('B5 ', 5,blue),piece('BB ',11,blue),piece('B3 ', 3,blue),piece('B6 ', 6,blue),piece('B3 ', 3,blue),piece('B1 ', 1,blue),piece('B2 ', 2,blue),piece('B3 ', 3,blue)],
[piece('B3 ', 3,blue),piece('B2 ', 2,blue),piece('BB ',11,blue),piece('B3 ', 3,blue),piece('BB ',11,blue),piece('B2 ', 2,blue),piece('BB ',11,blue),piece('B6 ', 6,blue),piece('B2 ', 2,blue),piece('B7 ', 7,blue)],
[piece('B2 ', 2,blue),piece('B6 ', 6,blue),piece('B5 ', 5,blue),piece('B4 ', 4,blue),piece('B2 ', 2,blue),piece('BB ',11,blue),piece('BF ',0,blue),piece('BB ',11,blue),piece('B8 ', 8,blue),piece('B2 ', 2,blue)]]
).
check_mobile_pieces([],_):-
fail.
check_mobile_pieces([BoardHead|BoardTail],Opponent):-
check_mobile_pieces_line(BoardHead,Opponent);
check_mobile_pieces(BoardTail,Opponent).
check_mobile_pieces_line([],_):-
fail.
check_mobile_pieces_line([LineHead|LineTail],Opponent):-
piece(_,PieceValue,Opponent)=LineHead,
((PieceValue > 0, PieceValue<11) -> true
;check_mobile_pieces_line(LineTail,Opponent)).
在这个例子中,结果应该是“是”,但结果是“否”。为什么?任何人都可以得到代码中的错误?
问候