Prolog If Then Else以成员谓词失败

时间:2012-01-19 13:52:15

标签: if-statement prolog

大家好,我正在开发一个prolog游戏,我需要编写一段代码:

  1. 从用户那里拿一个号码(ArmyNo)。
  2. 采用X坐标
  3. 取Y坐标。
  4. 然后我有一个名为TempBoard的列表,它看起来像这样:

    ([
        (1,1,-,-),(1,2,-,-),(1,3,-,-),(1,4,-,-),
        (2,1,-,-),(2,2,-,-),(2,3,-,-),(2,4,-,-),
        (3,1,-,-),(3,2,-,-),(3,3,-,-),(3,4,-,-),
        (4,1,-,-),(4,2,-,-),(4,3,-,-),(4,4,-,-)
    ]).
    

    在我将此(X,Y,w,ArmyNO)添加到列表之前,我首先要检查它是否已经存在。

    我尝试使用此代码执行此操作,但似乎无法正常运行:

    %#######Got the number####
            repeat,
        %Get Cordinates X & Y.
        writelist( [TempBoard,'select coordinates for the horizontal axis 1 to 4 to place          your soldier Mr. Human',nl]),
        read(X),
        writelist(['select coordinates for the vertical axis 1 to 4 to place your soldier Mr. Human',nl]),
        read(Y),
        %Check if they are in the list.
              (
                  member( (X,Y,w,ArmyNo),TempBoard )  ->
                           (  replace((X,Y,w,ArmyNo),TempBoard,NewBoard) ) ;
                     (
                 writelist(['selected positions are not available in the table Mr.Human',nl]) , fail
                 )
              ).
    
              %%
    

1 个答案:

答案 0 :(得分:1)

(X, Y, w, ArmyNo)

无法与示例列表的任何成员统一,因为w未与-统一。你的意思可能是W