Question

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)
      )
Was it helpful?

Solution

not sure it will correct your problem, but your program indentation doesn't match your parenthesis use. I would write, following the style indentation proposed by 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")
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top