1

so i assert the gamemap/3 with value 'O' gamemap(X,Y,'O') with X and Y from 1 to 10 and i get this error at this code V2=:= "O"if one of the V values is not 'O',can anyone help ? everything is instantiated but i saw in debugger that if the value is different from 'O' it does a rollback to the gamemap(X,Y,V) and probably deletes the value or something, what can i do to stop this, i want so that if the value is not 'O' to check the other comparisons not to do the rollback.

 Z=:=3 ->
          (
          random_between(3,8,X),
          random_between(3,8,Y),
          gamemap(X,Y,V),
          V=:="O" ->
          (
          X1 is X-1,
                  X2 is X+1,
              Y1 is Y-1,
          Y2 is Y+1,
          Y3 is Y+2,
          Y5 is Y-2,
          X3 is X+2,
          X5 is X-2,

          gamemap(X1,Y,V1),
          gamemap(X,Y2,V2),
          gamemap(X2,Y,V3),
          gamemap(X,Y1,V4),
      gamemap(X,Y3,V5),
      gamemap(X3,Y,V7),
      gamemap(X,Y5,V9),
      gamemap(X5,Y,V11),

          V2=:= "O", V5 =:="O" ->
         (
             change_map(X,Y2,"O","X"),
                 change_map(X,Y3,"O","X")
         );
         V3=:="O", V7=:="O" ->
         (
                     change_map(X2,Y,"O","X"),
                 change_map(X3,Y,"O","X")
         );
         V4=:="O", V9 =:="O" ->
         (
                     change_map(X,Y1,"O","X"),
                 change_map(X,Y5,"O","X")
         );
         V1=:="O", V11=:="O" ->
         (
                     change_map(X1,Y,"O","X"),
                 change_map(X5,Y,"O","X")

         );
         placeship(3)
         );
      placeship(3)
      )
4

1 回答 1

0

不确定它会纠正您的问题,但您的程序缩进与括号使用不匹配。我会按照 SWI-Prolog IDE 提出的样式缩进来写

(   (V2=:= "O", V5 =:="O")
->  change_map(X,Y2,"O","X"),
    change_map(X,Y3,"O","X")
;   (V3=:="O", V7=:="O")
->  change_map(X2,Y,"O","X")
...
于 2013-05-28T06:17:49.317 回答